// ChatModel is LangChain4j's provider-agnostic interface
ChatModel model = AnthropicChatModel.builder()
.apiKey(System.getenv("ANTHROPIC_API_KEY"))
.modelName("claude-sonnet-4-6")
.maxTokens(1024)
.build();
var transport = new StdioAcpAgentTransport();
AcpSyncAgent agent = AcpAgent.sync(transport)
// Identical to the echo agent (Module 12)
.initializeHandler(req -> InitializeResponse.ok())
.newSessionHandler(req ->
new NewSessionResponse(UUID.randomUUID().toString(), null, null))
// The only change from echo: ask the model
.promptHandler((req, context) -> {
String answer = model.chat(req.text());
context.sendMessage(answer);
return PromptResponse.endTurn();
})
.build();
agent.run();