Skip to main content

Module 11: Error Handling

Handle protocol errors from agents on the client side.

What You’ll Learn

  • Catching AcpClientSession.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 AcpClientSession.AcpError exceptions. 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

Agents throw AcpProtocolException with one of these codes. The SDK converts it to a JSON-RPC error response. Clients catch it as AcpClientSession.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.