Skip to main content

Module 13: Agent Handlers

Implement all handler types that an ACP agent can provide.

What You’ll Learn

  • All five handler types: initialize, newSession, loadSession, prompt, cancel
  • Session tracking with ConcurrentHashMap
  • Logging to stderr (stdout is reserved for the protocol)

The Code

An ACP agent has five handler types. Three are required (initialize, newSession, prompt) and two are optional (loadSession, cancel). This example shows all five wired up with the sync builder API. Note that stdout is reserved for the JSON-RPC protocol — agent logging goes to stderr:

Handler Reference

The cancelHandler receives a CancelNotification, not a request — it has no response. This is the JSON-RPC notification pattern: the client sends it and does not expect a reply.

Source Code

View on GitHub

Running the Example

Next Module

Module 14: Sending Updates — send all types of session updates to clients.