Overview
TheAgent abstract class defines the core interface that agents must implement to handle requests from clients in the ACP protocol. Agents are responsible for processing user prompts, managing sessions, handling authentication, and coordinating with AI models and tools.
Class Definition
- Protocol initialization and capability negotiation
- Session lifecycle management (creation, loading, forking)
- User prompt processing and AI model coordination
- Authentication flows
- Mode and configuration management
Methods
initialize
Establishes the connection with a client and negotiates protocol capabilities.- Negotiate the protocol version to use
- Exchange capability information between client and agent
- Determine available authentication methods
The initialization request containing protocol version and client capabilities
Contains the agent’s protocol version, capabilities, and available authentication methods
newSession
Creates a new conversation session with the agent.- Create a new session context
- Connect to any specified MCP servers
- Return a unique session ID for future requests
auth_required error if the agent requires authentication.
Request parameters for creating a new session
Contains the unique session ID and session configuration
loadSession
Loads an existing session to resume a previous conversation.loadSession capability. The agent should:
- Restore the session context and conversation history
- Connect to the specified MCP servers
- Stream the entire conversation history back to the client via notifications
Request parameters containing the session ID to load
Returns
null if not supported, otherwise contains loaded session informationprompt
Processes a user prompt within a session.- Receives user messages with optional context (files, images, etc.)
- Processes the prompt using language models
- Reports language model content and tool calls to the clients
- Requests permission to run tools
- Executes any requested tool calls
- Returns when the turn is complete with a stop reason
The prompt request containing session ID, messages, and context
Contains the final stop reason and any result data
setSessionMode
Sets the operational mode for a session.availableModes during session creation or loading. Agents may also change modes autonomously and notify the client via current_mode_update notifications.
This method can be called at any time during a session, whether the Agent is idle or actively generating a turn.
Request containing the session ID and desired mode
Returns
null if not supported, otherwise confirms the mode changesetSessionConfigOption
Sets the current value for a session configuration option.Request containing the session ID, option key, and new value
Returns
null if not supported, otherwise contains the updated configurationauthenticate
Authenticates the client using the specified authentication method.newSession without receiving an auth_required error.
Request containing the authentication method and credentials
Returns
null if not supported, otherwise confirms authentication successcancel
Cancels ongoing operations for a session.- Stop all language model requests as soon as possible
- Abort all tool call invocations in progress
- Send any pending
session/updatenotifications - Respond to the original
session/promptrequest withStopReason::Cancelled
Notification containing the session ID to cancel
Unstable Methods
The following methods are not yet part of the official ACP specification and may be changed or removed:unstableListSessions
Lists existing sessions from the agent.unstableForkSession
Forks an existing session to create a new independent session.unstableResumeSession
Resumes an existing session without replaying previous messages.setSessionModel
Selects the model for a given session.Extension Methods
extMethod
Allows the Client to send an arbitrary request that is not part of the ACP spec._ prefix, so callers should include the leading underscore explicitly when needed.
The extension method name (should start with
_ for ACP-reserved extensions)Arbitrary parameters for the extension method
Returns
null if not supported, otherwise the extension method responseextNotification
Allows the Client to send an arbitrary notification that is not part of the ACP spec.The extension notification name
Arbitrary parameters for the extension notification
Usage Example
See Also
- Client - The client interface that agents communicate with
- AgentSideConnection - Implementation of agent-side connections
- Connection - Base connection class for JSON-RPC communication