Skip to main content

Module 11: Error Handling

Handle protocol errors from agents on the client side.

What You’ll Learn

  • Catching AcpError (com.agentclientprotocol.sdk.spec.AcpError)
  • Standard error codes in AcpErrorCodes
  • Throwing AcpProtocolException from agent handlers
  • Error recovery — continuing after errors

The Code

ACP uses structured errors based on JSON-RPC error codes. On the client side, protocol errors arrive as AcpError exceptions. AcpError is one type on both sides (com.agentclientprotocol.sdk.spec.AcpError), replacing the older AcpClientSession.AcpError and AcpAgentSession.AcpError. You can inspect the error code to determine what went wrong:
On the agent side, throw AcpProtocolException with a standard error code. The SDK converts it to a JSON-RPC error response:

Error Codes

AcpErrorCodes keeps only the codes the ACP v1 schema defines: See the 0.80.0 migration guide if you’re carrying forward code that used SESSION_NOT_FOUND, PERMISSION_DENIED, CAPABILITY_NOT_SUPPORTED, NOT_INITIALIZED, or CONCURRENT_PROMPT: those names and codes changed or were removed. Agents throw AcpProtocolException with one of these codes. The SDK converts it to a JSON-RPC error response. Clients catch it as AcpError.

Error Recovery

Errors do not terminate the connection. After catching an error, the client can continue sending requests on the same session:

Source Code

View on GitHub

Running the Example

Next Module

Module 12: Echo Agent — build your first agent.