11package io.agentclientprotocol.agent
22
33import io.agentclientprotocol.model.AuthenticateRequest
4+ import io.agentclientprotocol.model.AuthenticateResponse
45import io.agentclientprotocol.model.CancelNotification
56import io.agentclientprotocol.model.InitializeRequest
67import io.agentclientprotocol.model.InitializeResponse
78import io.agentclientprotocol.model.LoadSessionRequest
9+ import io.agentclientprotocol.model.LoadSessionResponse
810import io.agentclientprotocol.model.NewSessionRequest
911import io.agentclientprotocol.model.NewSessionResponse
1012import io.agentclientprotocol.model.PromptRequest
1113import io.agentclientprotocol.model.PromptResponse
14+ import io.agentclientprotocol.model.SetSessionModeRequest
15+ import io.agentclientprotocol.model.SetSessionModeResponse
1216
1317/* *
1418 * Interface that agents must implement to handle client requests.
@@ -33,54 +37,98 @@ public interface Agent {
3337 /* *
3438 * Authenticate using the specified authentication method.
3539 *
36- * Called when the client wants to authenticate with a specific method
37- * that was advertised in the initialize response.
40+ * Called when the agent requires authentication before allowing session creation.
41+ * The client provides the authentication method ID that was advertised during initialization.
42+ * After successful authentication, the client can proceed to create sessions without
43+ * receiving an `auth_required` error.
44+ *
45+ * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
3846 *
3947 * @param request The authentication request containing the method ID
40- * @return null (authentication is just a handshake)
48+ * @return Authentication response
4149 */
42- public suspend fun authenticate (request : AuthenticateRequest )
50+ public suspend fun authenticate (request : AuthenticateRequest ): AuthenticateResponse
4351
4452 /* *
4553 * Create a new conversation session.
4654 *
47- * Sessions maintain their own context and allow multiple independent
48- * conversations with the same agent.
55+ * Sessions represent independent conversation contexts with their own history and state.
56+ * The agent should create a new session context, connect to any specified MCP servers,
57+ * and return a unique session ID for future requests.
58+ *
59+ * May return an `auth_required` error if the agent requires authentication.
4960 *
5061 * See protocol docs: [Creating a Session](https://agentclientprotocol.com/protocol/session-setup#creating-a-session)
62+ *
63+ * @param request The session creation request with working directory and MCP servers
64+ * @return The session ID and optional mode/model state
5165 */
52- public suspend fun newSession (request : NewSessionRequest ): NewSessionResponse
66+ public suspend fun sessionNew (request : NewSessionRequest ): NewSessionResponse
5367
5468 /* *
55- * Load an existing conversation session.
69+ * Load an existing conversation session to resume a previous conversation .
5670 *
5771 * Only called if the agent advertises the `loadSession` capability.
58- * Allows resuming previous conversations.
72+ * The agent should restore the session context and conversation history, connect to
73+ * the specified MCP servers, and stream the entire conversation history back to the
74+ * client via notifications.
5975 *
6076 * See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
77+ *
78+ * @param request The session load request with session ID, working directory, and MCP servers
79+ * @return Optional mode/model state for the loaded session
80+ */
81+ public suspend fun sessionLoad (request : LoadSessionRequest ): LoadSessionResponse
82+
83+ /* *
84+ * Sets the operational mode for a session.
85+ *
86+ * Allows switching between different agent modes (e.g., "ask", "architect", "code")
87+ * that affect system prompts, tool availability, and permission behaviors. The mode
88+ * must be one of the modes advertised in `availableModes` during session creation or loading.
89+ *
90+ * This method can be called at any time during a session, whether the agent is idle or
91+ * actively generating a turn. Agents may also change modes autonomously and notify the
92+ * client via `current_mode_update` notifications.
93+ *
94+ * See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
95+ *
96+ * @param request The set mode request with session ID and mode ID
97+ * @return Set session mode response
6198 */
62- public suspend fun loadSession (request : LoadSessionRequest )
99+ public suspend fun sessionSetMode (request : SetSessionModeRequest ): SetSessionModeResponse
63100
64101 /* *
65102 * Process a user prompt within a session.
66103 *
67- * This is the main method for handling user interactions. The agent should:
68- * 1. Process the prompt content
69- * 2. Send session updates via the client connection
70- * 3. Execute any necessary tool calls (with permission if needed)
71- * 4. Return a final response with the stop reason
104+ * This method handles the full lifecycle of a prompt turn:
105+ * 1. Receives user messages with optional context (files, images, etc.)
106+ * 2. Processes the prompt using language models
107+ * 3. Reports language model content and tool calls to the client via [sessionUpdate]
108+ * 4. Requests permission to run tools via client's [sessionRequestPermission]
109+ * 5. Executes approved tool calls
110+ * 6. Returns when the turn is complete with a stop reason
111+ *
112+ * See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
72113 *
73- * See protocol docs: [User Message](https://agentclientprotocol.com/protocol/prompt-turn#1-user-message)
114+ * @param request The prompt request with session ID and content blocks
115+ * @return The stop reason (end_turn, max_tokens, max_turn_requests, refusal, or cancelled)
74116 */
75- public suspend fun prompt (request : PromptRequest ): PromptResponse
117+ public suspend fun sessionPrompt (request : PromptRequest ): PromptResponse
76118
77119 /* *
78120 * Cancel ongoing operations for a session.
79121 *
80- * The client sends this notification to request cancellation of the current
81- * prompt turn. The agent should stop processing and return a cancelled response.
122+ * This is a notification sent by the client to cancel an ongoing prompt turn.
123+ * Upon receiving this notification, the agent should:
124+ * - Stop all language model requests as soon as possible
125+ * - Abort all tool call invocations in progress
126+ * - Send any pending session update notifications
127+ * - Respond to the original [sessionPrompt] request with `StopReason.CANCELLED`
82128 *
83129 * See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
130+ *
131+ * @param notification The cancellation notification with session ID
84132 */
85- public suspend fun cancel (notification : CancelNotification )
133+ public suspend fun sessionCancel (notification : CancelNotification )
86134}
0 commit comments