agentflow4j icon indicating copy to clipboard operation
agentflow4j copied to clipboard

Add Anthropic Claude sample to agentflow4j-samples

Open ahmed-sekka opened this issue 5 months ago • 2 comments

Problem

agentflow4j-samples ships demos against Mistral and Ollama. There is no sample showing AgentFlow4J wired to Anthropic Claude — one of the most widely used providers.

Task

Add ClaudeResearchDemo.java to agentflow4j-samples:

  • Two-agent graph: a researcher (ExecutorAgent) + a writer (ExecutorAgent)
  • CoordinatorAgent with RoutingStrategy.llmDriven(chatClient)
  • BudgetPolicy capping the run at $0.10
  • Falls back to stubs when ANTHROPIC_API_KEY is not set (same pattern as existing demos)

Spring AI dependency to add

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-model-anthropic</artifactId>
</dependency>

Acceptance criteria

  • Demo runs with ANTHROPIC_API_KEY set
  • Demo runs in stub mode without any API key
  • Follows the existing demo structure (see MistralIntegrationDemo.java)
  • Listed in the samples table in docs/samples.md

Notes

Good first issue — the pattern is established in MistralIntegrationDemo.java, this is a straight adaptation.

ahmed-sekka avatar Jun 08 '26 07:06 ahmed-sekka

I'd love to take this on! I have hands-on experience building RAG pipelines with LangChain and Spring AI, including Anthropic Claude integrations at work.

Here's my proposed implementation for ClaudeResearchDemo.java:

@SpringBootApplicationpublic class ClaudeResearchDemo {

    public static void main(String[] args) {
        SpringApplication.run(ClaudeResearchDemo.class, args);
    }

    @Bean    public ApplicationRunner runner(
            AgentGraphBuilder builder,
            ChatClient.Builder chatClientBuilder) {
        return args -> {
            String apiKey = System.getenv("ANTHROPIC_API_KEY");
            ChatClient chatClient = apiKey != null
                ? chatClientBuilder.build()
                : StubChatClient.create(); // falls back to stub

            AgentGraph graph = builder
                .addAgent("researcher", ExecutorAgent.builder()
                    .chatClient(chatClient)
                    .systemPrompt("You are a thorough research analyst. Gather facts and cite sources.")
                    .build())
                .addAgent("writer", ExecutorAgent.builder()
                    .chatClient(chatClient)
                    .systemPrompt("You are a concise technical writer. Synthesize research into clear summaries.")
                    .build())
                .coordinator(CoordinatorAgent.builder()
                    .routingStrategy(RoutingStrategy.llmDriven(chatClient))
                    .build())
                .policy(BudgetPolicy.maxCost(0.10))
                .build();

            graph.run("Research and summarize the key benefits of event-driven microservices");
        };
    }
}

application.properties (stub fallback):

spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY:stub-key}
spring.ai.anthropic.chat.options.model=claude-3-5-sonnet-20241022
spring.ai.anthropic.chat.options.max-tokens=1024

I'll also add the entry to docs/samples.md as requested. Should I go ahead and open a PR?

koteshyelamati avatar Jun 08 '26 21:06 koteshyelamati

Hi @koteshyelamati, thanks for jumping on this!

A few corrections before you open the PR — the proposed implementation uses an API that doesn't match AgentFlow4J's actual builder:

  • There is no AgentGraphBuilder bean or StubChatClient — use AgentGraph.builder() directly (see MistralIntegrationDemo.java)
  • The method is addNode("name", agent), not addAgent()
  • BudgetPolicy.maxCost() doesn't exist — it's BudgetPolicy.perRun(0.10, tokenEstimator, meter)
  • CoordinatorAgent takes an executors map, not a standalone builder on the graph
  • The existing demos use a plain main(String[] args) pattern, not @SpringBootApplication

Please use MistralIntegrationDemo.java as your direct reference — the Claude adaptation should follow the same structure, just swapping the Spring AI provider dependency and the chat client initialization.

Once the implementation matches the existing pattern, happy to review the PR.

ahmed-sekka avatar Jun 14 '26 09:06 ahmed-sekka