Add Anthropic Claude sample to agentflow4j-samples
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) CoordinatorAgentwithRoutingStrategy.llmDriven(chatClient)BudgetPolicycapping the run at $0.10- Falls back to stubs when
ANTHROPIC_API_KEYis 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_KEYset - 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.
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?
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
AgentGraphBuilderbean orStubChatClient— useAgentGraph.builder()directly (seeMistralIntegrationDemo.java) - The method is
addNode("name", agent), notaddAgent() BudgetPolicy.maxCost()doesn't exist — it'sBudgetPolicy.perRun(0.10, tokenEstimator, meter)CoordinatorAgenttakes anexecutorsmap, 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.