Skip to main content

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: 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 includes EchoAgentDemo.java, which launches the echo agent as a subprocess and exercises it:

Source Code

View on GitHub

Running 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() — combines start() and awaitTermination()
  • context.sendMessage() — convenience for sending AgentMessageChunk updates

Next Module

Module 13: Agent Handlers — implement all handler types including load session and cancel.