Skip to main content

Module 27: LangChain4j Chatbot

The Module 25 chatbot built with LangChain4j. Same ACP agent, a different way to reach the model.

Prerequisites

What You’ll Learn

  • Calling the model through LangChain4j’s provider-neutral ChatModel
  • Switching providers by swapping a dependency and a model builder
  • Why the ACP handlers never change when the model does

Dependencies

The Code

The ACP skeleton is the fluent builder from the echo agent. Only the prompt handler changes:
To use another provider, build a different ChatModel (for example an OpenAI or Ollama model) and change the dependency. The ACP handler is untouched.

Conversation Memory

This module keeps to a single turn for clarity: each prompt is answered on its own. LangChain4j adds memory through MessageWindowChatMemory, or through an AiServices interface with @MemoryId. Keying that memory on the ACP session ID gives each editor chat its own history, as Module 26 does with Spring AI.

Three Flavors, One Agent

Source Code

View on GitHub

Running the Example

Next Module

Module 28: Zed Integration — run your agent inside the Zed editor.