@@ -9,7 +9,7 @@ use anyhow::Result;
99use schemars:: JsonSchema ;
1010use serde:: { Deserialize , Serialize } ;
1111
12- use crate :: { ClientCapabilities , ContentBlock , Error , ProtocolVersion , SessionId } ;
12+ use crate :: { ClientCapabilities , ContentBlock , Error , PromptId , ProtocolVersion , SessionId } ;
1313
1414/// The Agent trait defines the interface that all ACP-compliant agents must implement.
1515///
@@ -91,6 +91,11 @@ pub trait Agent {
9191 arguments : PromptRequest ,
9292 ) -> impl Future < Output = Result < PromptResponse , Error > > ;
9393
94+ /// Rewinds a session.
95+ ///
96+ /// See: <https://agentclientprotocol.com/protocol/prompt-turn>
97+ fn rewind ( & self , arguments : RewindRequest ) -> impl Future < Output = Result < ( ) , Error > > ;
98+
9499 /// Cancels ongoing operations for a session.
95100 ///
96101 /// This is a notification sent by the client to cancel an ongoing prompt turn.
@@ -218,6 +223,26 @@ pub struct LoadSessionRequest {
218223 pub session_id : SessionId ,
219224}
220225
226+ // Rewind session
227+
228+ /// Request parameters for rewinding a session.
229+ ///
230+ /// Only available if the agent supports the `rewindSession` capability.
231+ ///
232+ /// The conversation is rewound to the moment just before the given prompt was
233+ /// submitted. This allows the user to submit a new version of that prompt through
234+ /// the UI to attempt to get better results.
235+ ///
236+ /// See: <https://agentclientprotocol.com/protocol/session-setup#truncating-sessions>
237+ #[ derive( Debug , Clone , Serialize , Deserialize , JsonSchema ) ]
238+ #[ serde( rename_all = "camelCase" ) ]
239+ pub struct RewindRequest {
240+ /// The prompt ID to rewind to. This prompt, and all subsequent user and agent
241+ /// messages should be discarded.
242+ pub prompt_id : PromptId ,
243+ pub session_id : SessionId ,
244+ }
245+
221246// MCP
222247
223248/// Configuration for connecting to an MCP (Model Context Protocol) server.
@@ -261,6 +286,9 @@ pub struct EnvVariable {
261286pub struct PromptRequest {
262287 /// The ID of the session to send this user message to
263288 pub session_id : SessionId ,
289+ /// The ID of the prompt. Required if both the client and
290+ /// the server support rewinding.
291+ pub prompt_id : Option < PromptId > ,
264292 /// The blocks of content that compose the user's message.
265293 ///
266294 /// As a baseline, the Agent MUST support [`ContentBlock::Text`] and [`ContentBlock::ResourceLink`],
@@ -329,6 +357,9 @@ pub struct AgentCapabilities {
329357 /// Whether the agent supports `session/load`.
330358 #[ serde( default ) ]
331359 pub load_session : bool ,
360+ /// Whether the agent supports `session/rewind`.
361+ #[ serde( default ) ]
362+ pub rewind_session : bool ,
332363 /// Prompt capabilities supported by the agent.
333364 #[ serde( default ) ]
334365 pub prompt_capabilities : PromptCapabilities ,
@@ -378,6 +409,8 @@ pub struct AgentMethodNames {
378409 pub session_new : & ' static str ,
379410 /// Method for loading an existing session.
380411 pub session_load : & ' static str ,
412+ /// Method for rewinding the current session.
413+ pub session_rewind : & ' static str ,
381414 /// Method for sending a prompt to the agent.
382415 pub session_prompt : & ' static str ,
383416 /// Notification for cancelling operations.
@@ -390,6 +423,7 @@ pub const AGENT_METHOD_NAMES: AgentMethodNames = AgentMethodNames {
390423 authenticate : AUTHENTICATE_METHOD_NAME ,
391424 session_new : SESSION_NEW_METHOD_NAME ,
392425 session_load : SESSION_LOAD_METHOD_NAME ,
426+ session_rewind : SESSION_REWIND_METHOD_NAME ,
393427 session_prompt : SESSION_PROMPT_METHOD_NAME ,
394428 session_cancel : SESSION_CANCEL_METHOD_NAME ,
395429} ;
@@ -402,6 +436,8 @@ pub(crate) const AUTHENTICATE_METHOD_NAME: &str = "authenticate";
402436pub ( crate ) const SESSION_NEW_METHOD_NAME : & str = "session/new" ;
403437/// Method name for loading an existing session.
404438pub ( crate ) const SESSION_LOAD_METHOD_NAME : & str = "session/load" ;
439+ /// Method name for truncating the current session.
440+ pub ( crate ) const SESSION_REWIND_METHOD_NAME : & str = "session/rewind" ;
405441/// Method name for sending a prompt.
406442pub ( crate ) const SESSION_PROMPT_METHOD_NAME : & str = "session/prompt" ;
407443/// Method name for the cancel notification.
@@ -420,6 +456,7 @@ pub enum ClientRequest {
420456 AuthenticateRequest ( AuthenticateRequest ) ,
421457 NewSessionRequest ( NewSessionRequest ) ,
422458 LoadSessionRequest ( LoadSessionRequest ) ,
459+ RewindRequest ( RewindRequest ) ,
423460 PromptRequest ( PromptRequest ) ,
424461}
425462
@@ -436,6 +473,7 @@ pub enum AgentResponse {
436473 AuthenticateResponse ,
437474 NewSessionResponse ( NewSessionResponse ) ,
438475 LoadSessionResponse ,
476+ RewindResponse ,
439477 PromptResponse ( PromptResponse ) ,
440478}
441479
0 commit comments