diff --git a/agent-client-protocol-schema/Cargo.toml b/agent-client-protocol-schema/Cargo.toml index 78be2eae5..8411c1199 100644 --- a/agent-client-protocol-schema/Cargo.toml +++ b/agent-client-protocol-schema/Cargo.toml @@ -31,6 +31,7 @@ unstable = [ "unstable_auth_status", "unstable_llm_providers", "unstable_mcp_over_acp", + "unstable_prompt_delivery", "unstable_prompt_suggestions", "unstable_proxy_chains", "unstable_session_archive", @@ -50,6 +51,7 @@ unstable_agent_skills = [] unstable_auth_status = [] unstable_llm_providers = [] unstable_mcp_over_acp = [] +unstable_prompt_delivery = [] unstable_prompt_suggestions = [] unstable_proxy_chains = [] unstable_session_archive = [] diff --git a/agent-client-protocol-schema/src/v2/agent.rs b/agent-client-protocol-schema/src/v2/agent.rs index 325a7a23c..b47cb6349 100644 --- a/agent-client-protocol-schema/src/v2/agent.rs +++ b/agent-client-protocol-schema/src/v2/agent.rs @@ -5250,6 +5250,11 @@ pub struct PromptRequest { /// inserting it. #[cfg_attr(feature = "schemars", schemars(length(min = 1)))] pub prompt: Vec, + /// How to insert the prompt while foreground work is active. + /// Omitted and `null` are equivalent and select the ordinary prompt behavior. + /// Clients MUST NOT send a mode that the Agent did not advertise. + #[cfg(feature = "unstable_prompt_delivery")] + pub delivery: Option, /// Identifies one prompt submission within this session. /// /// Optional. Omitted and `null` are equivalent and mean no key. The Agent then handles @@ -5292,6 +5297,8 @@ impl PromptRequest { Self { session_id: session_id.into(), prompt, + #[cfg(feature = "unstable_prompt_delivery")] + delivery: None, idempotency_key: None, meta: None, } @@ -5306,6 +5313,14 @@ impl PromptRequest { self } + /// Selects the delivery mode for this prompt. + #[cfg(feature = "unstable_prompt_delivery")] + #[must_use] + pub fn delivery(mut self, delivery: impl IntoOption) -> Self { + self.delivery = delivery.into_option(); + self + } + /// The _meta property is reserved by ACP to allow clients and agents to attach additional /// metadata to their interactions. Implementations MUST NOT assign meaning to keys they /// do not recognize. @@ -5318,6 +5333,19 @@ impl PromptRequest { } } +/// How to insert a prompt received during foreground work. +#[cfg(feature = "unstable_prompt_delivery")] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +#[serde(rename_all = "camelCase")] +#[non_exhaustive] +pub enum PromptDelivery { + /// Insert at the next safe point in the current turn, or start the next turn if it ends first. + Steer, + /// Wait until the current turn ends, then start a new turn with the prompt. + Queue, +} + /// Response acknowledging that a user prompt was inserted into the ACP conversation. /// /// This response does not indicate that the prompt was merely received or held, nor that the @@ -7156,6 +7184,13 @@ pub struct PromptCapabilities { #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))] #[serde(default)] pub skill: Option, + /// Delivery modes supported by the Agent for `session/prompt`. + /// Omitted and `null` are equivalent and mean neither mode is supported. + #[cfg(feature = "unstable_prompt_delivery")] + #[serde_as(deserialize_as = "DefaultOnError")] + #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))] + #[serde(default)] + pub delivery: Option, /// The _meta property is reserved by ACP to allow clients and agents to attach additional /// metadata to their interactions. Omitted and `null` are equivalent and mean no metadata. /// Implementations MUST NOT assign meaning to keys they do not recognize. @@ -7226,6 +7261,14 @@ impl PromptCapabilities { self } + /// Sets the delivery modes supported by the Agent. + #[cfg(feature = "unstable_prompt_delivery")] + #[must_use] + pub fn delivery(mut self, delivery: impl IntoOption) -> Self { + self.delivery = delivery.into_option(); + self + } + /// The _meta property is reserved by ACP to allow clients and agents to attach additional /// metadata to their interactions. Implementations MUST NOT assign meaning to keys they /// do not recognize. @@ -7238,6 +7281,45 @@ impl PromptCapabilities { } } +/// Delivery modes supported by the Agent for `session/prompt`. +#[cfg(feature = "unstable_prompt_delivery")] +#[serde_as] +#[skip_serializing_none] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[non_exhaustive] +pub struct PromptDeliveryCapabilities { + /// Supplying `{}` advertises `steer`. Omitted and `null` mean unsupported. + #[serde_as(deserialize_as = "DefaultOnError")] + #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))] + #[serde(default)] + pub steer: Option, + /// Supplying `{}` advertises `queue`. Omitted and `null` mean unsupported. + #[serde_as(deserialize_as = "DefaultOnError")] + #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))] + #[serde(default)] + pub queue: Option, +} + +#[cfg(feature = "unstable_prompt_delivery")] +impl PromptDeliveryCapabilities { + /// Builds the advertisement for the given modes. + #[must_use] + pub fn new(steer: bool, queue: bool) -> Self { + Self { + steer: steer.then(PromptDeliveryModeCapabilities::default), + queue: queue.then(PromptDeliveryModeCapabilities::default), + } + } +} + +/// An advertised prompt delivery mode. An empty object indicates support. +#[cfg(feature = "unstable_prompt_delivery")] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[non_exhaustive] +pub struct PromptDeliveryModeCapabilities {} + /// Capabilities for image content in prompt requests. /// /// Supplying `{}` means the agent supports image content in prompts. @@ -7704,6 +7786,10 @@ impl McpAcpCapabilities { /// Cancels the named session's active foreground work and earlier prompts not yet inserted. /// It does not cancel later submissions or work in the session's latest `background` list. +#[cfg_attr( + feature = "unstable_prompt_delivery", + doc = "Explicit steers and queued prompts are not covered by this cancellation." +)] /// /// See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/v2/prompt-lifecycle#cancellation) #[serde_as] @@ -8321,6 +8407,68 @@ mod test_serialization { use super::*; use serde_json::json; + #[cfg(feature = "unstable_prompt_delivery")] + #[test] + fn prompt_delivery_request_is_optional_and_strict() { + let mut params = json!({"sessionId": "session", "prompt": []}); + let request = serde_json::from_value::(params.clone()).unwrap(); + assert_eq!(request.delivery, None); + params["delivery"] = serde_json::Value::Null; + assert_eq!( + serde_json::from_value::(params.clone()).unwrap(), + request + ); + assert!( + serde_json::to_value(&request) + .unwrap() + .get("delivery") + .is_none() + ); + for (value, mode) in [ + ("steer", PromptDelivery::Steer), + ("queue", PromptDelivery::Queue), + ] { + params["delivery"] = json!(value); + let request = request.clone().delivery(mode); + assert_eq!( + serde_json::from_value::(params.clone()).unwrap(), + request + ); + assert_eq!(serde_json::to_value(request).unwrap(), params); + } + for invalid in [json!("interrupt"), json!({}), json!(true)] { + params["delivery"] = invalid; + assert!(serde_json::from_value::(params.clone()).is_err()); + } + } + + #[cfg(feature = "unstable_prompt_delivery")] + #[test] + fn prompt_delivery_capabilities_advertise_only_supported_modes() { + let steer = + PromptCapabilities::new().delivery(PromptDeliveryCapabilities::new(true, false)); + let both = PromptCapabilities::new().delivery(PromptDeliveryCapabilities::new(true, true)); + assert_eq!( + serde_json::to_value(&steer).unwrap(), + json!({"delivery": {"steer": {}}}) + ); + assert_eq!( + serde_json::to_value(both).unwrap(), + json!({"delivery": {"steer": {}, "queue": {}}}) + ); + assert_eq!( + serde_json::from_value::( + json!({"delivery": {"steer": {}, "queue": null}}) + ) + .unwrap(), + steer + ); + assert_eq!( + serde_json::from_value::(json!({"delivery": null})).unwrap(), + PromptCapabilities::new() + ); + } + fn test_meta() -> Meta { json!({ "source": "test" }).as_object().unwrap().clone() } diff --git a/docs/protocol/v2/draft/prompt-lifecycle.mdx b/docs/protocol/v2/draft/prompt-lifecycle.mdx index f9b0c8ed4..b614bebfa 100644 --- a/docs/protocol/v2/draft/prompt-lifecycle.mdx +++ b/docs/protocol/v2/draft/prompt-lifecycle.mdx @@ -416,16 +416,18 @@ The same insertion boundary applies when [closing the session](/protocol/v2/draf #### Prompts during active work -Clients **MAY** send `session/prompt` in any state, including while foreground work is `running` or `requires_action`. The Agent either inserts the prompt right away or holds it and inserts it later. Held prompts are inserted in the order they were received. What inserting during active work means, such as steering the current turn or starting the next one, is up to the Agent. Agents **MUST NOT** reject a prompt only because foreground work is active. +Clients **MAY** send `session/prompt` in any state, including while foreground work is `running` or `requires_action`. The Agent either inserts the prompt right away or holds it and inserts it later. Ordinary held prompts are inserted in the order they were received. The Agent decides when to insert a prompt whose `delivery` is omitted or `null`. Agents **MUST NOT** reject a prompt only because foreground work is active. -A held prompt's response stays pending until the prompt is inserted. Until then, the Client can drop it in two ways: +A held prompt's response stays pending until the prompt is inserted. Until then, these cancellation rules apply: -- [`session/cancel`](#cancellation) and `session/close` drop prompts the Agent has already received but not inserted. The Agent answers each of them with `-32800`. Both also stop the foreground work. +- [`session/cancel`](#cancellation) stops foreground work and drops ordinary prompts the Agent has not inserted. `session/close` also drops any uninserted explicit steers and queued prompts. The Agent answers each dropped prompt with `-32800`. - [`$/cancel_request`](/protocol/v2/draft/cancellation) for the prompt's request is best effort, because request cancellation is optional for the receiver. An Agent that honors it answers with `-32800` and does not insert the message. Otherwise the prompt is inserted as usual, and the response carries its `messageId`. Once a prompt is inserted, the Client cannot withdraw it. It stops the work the prompt started with `session/cancel`. -A guaranteed way to remove one held prompt is left to future capabilities, which may also let Agents advertise steering or queueing behavior. +Agents that advertise experimental [prompt delivery](https://github.com/agentclientprotocol/agent-client-protocol/pull/1261) support one or both explicit modes under `capabilities.session.prompt.delivery`. A Client **MUST NOT** send a mode the Agent did not advertise. The Agent **MUST** reject an unsupported or unrecognized mode with `-32602` before insertion. `steer` inserts at the next safe point in the current turn or starts the next turn if the current turn ends first. If the turn ends first, waiting steers enter the next turn together in receipt order. `queue` waits until the current turn ends. Queued prompts follow any waiting steers in receipt order, each in its own turn. The response still acknowledges insertion, and it can arrive before or after the `user_message` update. + +`session/cancel` stops the current turn but does not drop explicit steers or queued prompts. To withdraw one before insertion, the Client sends `$/cancel_request` for that request. #### Prompts that are never inserted @@ -1484,7 +1486,7 @@ Clients **MAY** cancel the session's foreground work at any time by sending a `s } ``` -`session/cancel` covers foreground work and prompts received before it that the Agent has not yet inserted. The Agent **MUST** answer the covered prompts with `-32800`, as described in [request cancellation](/protocol/v2/draft/cancellation). A `session/prompt` received after `session/cancel` is not cancelled by it. Once a message is inserted, its prompt request still succeeds with its `messageId`. Cancellation does not undo that insertion. Work in the latest [`background`](#background-work) list is not covered and keeps running. The Agent **MAY** stop background activity it does not list. To stop a listed tool call or terminal, the Client sends [`tool_call/cancel`](/protocol/v2/draft/tool-calls#cancelling-tool-calls) or [`terminal/cancel`](/protocol/v2/draft/tool-calls#cancelling-terminals) while that item advertises `capabilities.cancel`. +`session/cancel` covers foreground work and ordinary prompts received before it that the Agent has not yet inserted. It does not cover [pending explicit steers or queued prompts](#prompts-during-active-work). The Agent **MUST** answer the covered prompts with `-32800`, as described in [request cancellation](/protocol/v2/draft/cancellation). A `session/prompt` received after `session/cancel` is not cancelled by it. Once a message is inserted, its prompt request still succeeds with its `messageId`. Cancellation does not undo that insertion. Work in the latest [`background`](#background-work) list is not covered and keeps running. The Agent **MAY** stop background activity it does not list. To stop a listed tool call or terminal, the Client sends [`tool_call/cancel`](/protocol/v2/draft/tool-calls#cancelling-tool-calls) or [`terminal/cancel`](/protocol/v2/draft/tool-calls#cancelling-terminals) while that item advertises `capabilities.cancel`. For a [child session](/protocol/v2/draft/subagents#cancellation), the Client sends `session/cancel` only while the child advertises `capabilities.cancel`. Cancelling a session also cancels the child work that the cancelled work is waiting on. diff --git a/docs/protocol/v2/draft/schema.mdx b/docs/protocol/v2/draft/schema.mdx index d4deb7598..13987a6bd 100644 --- a/docs/protocol/v2/draft/schema.mdx +++ b/docs/protocol/v2/draft/schema.mdx @@ -623,6 +623,7 @@ See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/v2/dr Cancels the named session's active foreground work and earlier prompts not yet inserted. It does not cancel later submissions or work in the session's latest `background` list. +Explicit steers and queued prompts are not covered by this cancellation. See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/v2/draft/prompt-lifecycle#cancellation) @@ -1251,6 +1252,11 @@ Implementations MUST NOT assign meaning to keys they do not recognize. See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/v2/draft/extensibility) + +PromptDelivery | null} > + How to insert the prompt while foreground work is active. +Omitted and `null` are equivalent and select the ordinary prompt behavior. +Clients MUST NOT send a mode that the Agent did not advertise. IdempotencyKey | null} > Identifies one prompt submission within this session. @@ -7862,6 +7868,10 @@ See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/v2/d Optional. Omitted and `null` are equivalent and mean the agent does not advertise support. Supplying `\{\}` means the agent supports audio content in prompts. + +PromptDeliveryCapabilities | null} > + Delivery modes supported by the Agent for `session/prompt`. +Omitted and `null` are equivalent and mean neither mode is supported. PromptEmbeddedContextCapabilities | null} > Agent supports embedded context in `session/prompt` requests. @@ -7893,6 +7903,42 @@ An agent that sends `skill` entries in `availableCommands` MUST advertise this c +## PromptDelivery + +How to insert a prompt received during foreground work. + +**Type:** Union + + + Insert at the next safe point in the current turn, or start the next turn if + it ends first. + + + + Wait until the current turn ends, then start a new turn with the prompt. + + +## PromptDeliveryCapabilities + +Delivery modes supported by the Agent for `session/prompt`. + +**Type:** Object + +**Properties:** + +PromptDeliveryModeCapabilities | null} > + Supplying `\{\}` advertises `queue`. Omitted and `null` mean unsupported. + +PromptDeliveryModeCapabilities | null} > + Supplying `\{\}` advertises `steer`. Omitted and `null` mean unsupported. + + +## PromptDeliveryModeCapabilities + +An advertised prompt delivery mode. An empty object indicates support. + +**Type:** `object` + ## PromptEmbeddedContextCapabilities Capabilities for embedded context in prompt requests. diff --git a/schema/v2/schema.unstable.json b/schema/v2/schema.unstable.json index ff4668fd9..536962d69 100644 --- a/schema/v2/schema.unstable.json +++ b/schema/v2/schema.unstable.json @@ -3411,6 +3411,18 @@ ], "x-deserialize-default-on-error": true }, + "delivery": { + "description": "Delivery modes supported by the Agent for `session/prompt`.\nOmitted and `null` are equivalent and mean neither mode is supported.", + "anyOf": [ + { + "$ref": "#/$defs/PromptDeliveryCapabilities" + }, + { + "type": "null" + } + ], + "x-deserialize-default-on-error": true + }, "_meta": { "description": "The _meta property is reserved by ACP to allow clients and agents to attach additional\nmetadata to their interactions. Omitted and `null` are equivalent and mean no metadata.\nImplementations MUST NOT assign meaning to keys they do not recognize.\n\nSee protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/v2/draft/extensibility)", "type": ["object", "null"], @@ -3491,6 +3503,40 @@ } } }, + "PromptDeliveryCapabilities": { + "description": "Delivery modes supported by the Agent for `session/prompt`.", + "type": "object", + "properties": { + "steer": { + "description": "Supplying `{}` advertises `steer`. Omitted and `null` mean unsupported.", + "anyOf": [ + { + "$ref": "#/$defs/PromptDeliveryModeCapabilities" + }, + { + "type": "null" + } + ], + "x-deserialize-default-on-error": true + }, + "queue": { + "description": "Supplying `{}` advertises `queue`. Omitted and `null` mean unsupported.", + "anyOf": [ + { + "$ref": "#/$defs/PromptDeliveryModeCapabilities" + }, + { + "type": "null" + } + ], + "x-deserialize-default-on-error": true + } + } + }, + "PromptDeliveryModeCapabilities": { + "description": "An advertised prompt delivery mode. An empty object indicates support.", + "type": "object" + }, "McpCapabilities": { "description": "MCP capabilities supported by the agent for session lifecycle requests.", "type": "object", @@ -10528,6 +10574,17 @@ }, "minItems": 1 }, + "delivery": { + "description": "How to insert the prompt while foreground work is active.\nOmitted and `null` are equivalent and select the ordinary prompt behavior.\nClients MUST NOT send a mode that the Agent did not advertise.", + "anyOf": [ + { + "$ref": "#/$defs/PromptDelivery" + }, + { + "type": "null" + } + ] + }, "idempotencyKey": { "description": "Identifies one prompt submission within this session.\n\nOptional. Omitted and `null` are equivalent and mean no key. The Agent then handles\nthe prompt without duplicate detection.\n\nThe Client generates the key and sends the same key on every attempt for the same\nsubmission. Agents that advertise `capabilities.session` MUST support the key.\nA retry of a recorded insertion returns the original `messageId` without inserting\nanother message.\n\nThe Agent MUST recognize the key for as long as it retains the message, including\nacross connections and Agent restarts. For a live-only message, it MUST recognize\nthe key while the session stays active on a connection. A retry with a forgotten\nkey is a new submission, even immediately after reconnecting. If a duplicate\nwould matter and the Client cannot rule it out, it SHOULD NOT retry automatically.\n\nWhen present, the value is an opaque, case-sensitive string of 1 to 255 characters.\nAgents MUST reject any other value with `-32602` (Invalid params) and MUST NOT treat\nit as omitted.\n\nSee protocol docs: [Retrying a prompt](https://agentclientprotocol.com/protocol/v2/draft/prompt-lifecycle#retrying-a-prompt)", "anyOf": [ @@ -10550,6 +10607,21 @@ "x-side": "agent", "x-method": "session/prompt" }, + "PromptDelivery": { + "description": "How to insert a prompt received during foreground work.", + "oneOf": [ + { + "description": "Insert at the next safe point in the current turn, or start the next turn if it ends first.", + "type": "string", + "const": "steer" + }, + { + "description": "Wait until the current turn ends, then start a new turn with the prompt.", + "type": "string", + "const": "queue" + } + ] + }, "IdempotencyKey": { "description": "A key the Client generates to identify one `session/prompt` submission across attempts.\n\nThe key is an opaque, case-sensitive string of 1 to 255 characters. It is scoped to the\nsession named by the request's `sessionId`.\n\nSee protocol docs: [Retrying a prompt](https://agentclientprotocol.com/protocol/v2/draft/prompt-lifecycle#retrying-a-prompt)", "type": "string", @@ -11056,7 +11128,7 @@ "x-docs-ignore": true }, "CancelSessionNotification": { - "description": "Cancels the named session's active foreground work and earlier prompts not yet inserted.\nIt does not cancel later submissions or work in the session's latest `background` list.\n\nSee protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/v2/draft/prompt-lifecycle#cancellation)", + "description": "Cancels the named session's active foreground work and earlier prompts not yet inserted.\nIt does not cancel later submissions or work in the session's latest `background` list.\nExplicit steers and queued prompts are not covered by this cancellation.\n\nSee protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/v2/draft/prompt-lifecycle#cancellation)", "type": "object", "properties": { "sessionId": {