pub trait Agent {
// Required methods
fn initialize(
&self,
arguments: InitializeRequest,
) -> impl Future<Output = Result<InitializeResponse, Error>>;
fn authenticate(
&self,
arguments: AuthenticateRequest,
) -> impl Future<Output = Result<(), Error>>;
fn new_session(
&self,
arguments: NewSessionRequest,
) -> impl Future<Output = Result<NewSessionResponse, Error>>;
fn load_session(
&self,
arguments: LoadSessionRequest,
) -> impl Future<Output = Result<(), Error>>;
fn prompt(
&self,
arguments: PromptRequest,
) -> impl Future<Output = Result<PromptResponse, Error>>;
fn cancel(
&self,
args: CancelNotification,
) -> impl Future<Output = Result<(), Error>>;
}
Expand description
Defines the interface that all ACP-compliant agents must implement.
Agents are programs that use generative AI to autonomously modify code. They handle requests from clients and execute tasks using language models and tools.
Required Methods§
Sourcefn initialize(
&self,
arguments: InitializeRequest,
) -> impl Future<Output = Result<InitializeResponse, Error>>
fn initialize( &self, arguments: InitializeRequest, ) -> impl Future<Output = Result<InitializeResponse, Error>>
Establishes the connection with a client and negotiates protocol capabilities.
This method is called once at the beginning of the connection to:
- Negotiate the protocol version to use
- Exchange capability information between client and agent
- Determine available authentication methods
The agent should respond with its supported protocol version and capabilities.
See protocol docs: Initialization
Sourcefn authenticate(
&self,
arguments: AuthenticateRequest,
) -> impl Future<Output = Result<(), Error>>
fn authenticate( &self, arguments: AuthenticateRequest, ) -> impl Future<Output = Result<(), Error>>
Authenticates the client using the specified authentication method.
Called when the agent requires authentication before allowing session creation. The client provides the authentication method ID that was advertised during initialization.
After successful authentication, the client can proceed to create sessions with
new_session
without receiving an auth_required
error.
See protocol docs: Initialization
Sourcefn new_session(
&self,
arguments: NewSessionRequest,
) -> impl Future<Output = Result<NewSessionResponse, Error>>
fn new_session( &self, arguments: NewSessionRequest, ) -> impl Future<Output = Result<NewSessionResponse, Error>>
Creates a new conversation session with the agent.
Sessions represent independent conversation contexts with their own history and state.
The agent should:
- Create a new session context
- Connect to any specified MCP servers
- Return a unique session ID for future requests
May return an auth_required
error if the agent requires authentication.
See protocol docs: Session Setup
Sourcefn load_session(
&self,
arguments: LoadSessionRequest,
) -> impl Future<Output = Result<(), Error>>
fn load_session( &self, arguments: LoadSessionRequest, ) -> impl Future<Output = Result<(), Error>>
Loads an existing session to resume a previous conversation.
This method is only available if the agent advertises the 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
See protocol docs: Loading Sessions
Sourcefn prompt(
&self,
arguments: PromptRequest,
) -> impl Future<Output = Result<PromptResponse, Error>>
fn prompt( &self, arguments: PromptRequest, ) -> impl Future<Output = Result<PromptResponse, Error>>
Processes a user prompt within a session.
This method handles the whole lifecycle of a prompt:
- 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
See protocol docs: Prompt Turn
Sourcefn cancel(
&self,
args: CancelNotification,
) -> impl Future<Output = Result<(), Error>>
fn cancel( &self, args: CancelNotification, ) -> impl Future<Output = Result<(), Error>>
Cancels ongoing operations for a session.
This is a notification sent by the client to cancel an ongoing prompt turn.
Upon receiving this notification, the Agent SHOULD:
- Stop all language model requests as soon as possible
- Abort all tool call invocations in progress
- Send any pending
session/update
notifications - Respond to the original
session/prompt
request withStopReason::Cancelled
See protocol docs: Cancellation
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.