Module 12: Echo Agent
Build a minimal ACP agent in ~25 lines. No API key required.What You’ll Learn
- Building an agent with
AcpAgent.sync() - Implementing the three required handlers: initialize, newSession, prompt
- Sending messages back to the client
- Running a self-contained agent + client demo
The Agent
How It Works
An ACP agent needs three handlers:| Handler | Purpose |
|---|---|
initializeHandler | Protocol handshake — return capabilities |
newSessionHandler | Create a session — return a unique session ID |
promptHandler | Process prompts — send updates and return a stop reason |
agent.run() starts the agent and blocks. The agent reads JSON-RPC requests from stdin and writes responses to stdout. This is the stdio transport — the same mechanism Zed and JetBrains use to talk to agents.
The context parameter in the prompt handler gives access to sendMessage(), sendThought(), and other convenience methods for sending updates back to the client.
The Demo Client
The module also includesEchoAgentDemo.java, which launches the echo agent as a subprocess and exercises it:
Source Code
View on GitHubRunning the Example
Key Points
- No API key — the agent runs entirely locally
- Stdio transport — same protocol mechanism used by Zed, JetBrains, VS Code
agent.run()— combinesstart()andawaitTermination()context.sendMessage()— convenience for sendingAgentMessageChunkupdates