Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/agent-client-protocol/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use agent_client_protocol_schema::{
use agent_client_protocol_schema::{ForkSessionRequest, ForkSessionResponse};
#[cfg(feature = "unstable_session_list")]
use agent_client_protocol_schema::{ListSessionsRequest, ListSessionsResponse};
#[cfg(feature = "unstable_session_resume")]
use agent_client_protocol_schema::{ResumeSessionRequest, ResumeSessionResponse};
#[cfg(feature = "unstable_session_model")]
use agent_client_protocol_schema::{SetSessionModelRequest, SetSessionModelResponse};
use serde_json::value::RawValue;
Expand Down Expand Up @@ -154,6 +156,21 @@ pub trait Agent {
Err(Error::method_not_found())
}

/// **UNSTABLE**
///
/// This capability is not part of the spec yet, and may be removed or changed at any point.
///
/// Resumes an existing session without replaying message history.
///
/// This is similar to `load_session`, except it does not return previous messages.
/// Useful for agents that support continuing conversations but don't store full history.
///
/// Only available if the Agent supports the `sessionCapabilities.resume` capability.
#[cfg(feature = "unstable_session_resume")]
async fn resume_session(&self, _args: ResumeSessionRequest) -> Result<ResumeSessionResponse> {
Err(Error::method_not_found())
}

/// Handles extension method requests from the client.
///
/// Extension methods provide a way to add custom functionality while maintaining
Expand Down Expand Up @@ -216,6 +233,10 @@ impl<T: Agent> Agent for Rc<T> {
async fn fork_session(&self, args: ForkSessionRequest) -> Result<ForkSessionResponse> {
self.as_ref().fork_session(args).await
}
#[cfg(feature = "unstable_session_resume")]
async fn resume_session(&self, args: ResumeSessionRequest) -> Result<ResumeSessionResponse> {
self.as_ref().resume_session(args).await
}
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
self.as_ref().ext_method(args).await
}
Expand Down Expand Up @@ -265,6 +286,10 @@ impl<T: Agent> Agent for Arc<T> {
async fn fork_session(&self, args: ForkSessionRequest) -> Result<ForkSessionResponse> {
self.as_ref().fork_session(args).await
}
#[cfg(feature = "unstable_session_resume")]
async fn resume_session(&self, args: ResumeSessionRequest) -> Result<ResumeSessionResponse> {
self.as_ref().resume_session(args).await
}
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
self.as_ref().ext_method(args).await
}
Expand Down
19 changes: 19 additions & 0 deletions src/agent-client-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ impl Agent for ClientSideConnection {
.await
}

#[cfg(feature = "unstable_session_resume")]
async fn resume_session(&self, args: ResumeSessionRequest) -> Result<ResumeSessionResponse> {
self.conn
.request(
AGENT_METHOD_NAMES.session_resume,
Some(ClientRequest::ResumeSessionRequest(args)),
)
.await
}

async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
self.conn
.request(
Expand Down Expand Up @@ -546,6 +556,10 @@ impl Side for AgentSide {
m if m == AGENT_METHOD_NAMES.session_fork => serde_json::from_str(params.get())
.map(ClientRequest::ForkSessionRequest)
.map_err(Into::into),
#[cfg(feature = "unstable_session_resume")]
m if m == AGENT_METHOD_NAMES.session_resume => serde_json::from_str(params.get())
.map(ClientRequest::ResumeSessionRequest)
.map_err(Into::into),
m if m == AGENT_METHOD_NAMES.session_prompt => serde_json::from_str(params.get())
.map(ClientRequest::PromptRequest)
.map_err(Into::into),
Expand Down Expand Up @@ -625,6 +639,11 @@ impl<T: Agent> MessageHandler<AgentSide> for T {
let response = self.fork_session(args).await?;
Ok(AgentResponse::ForkSessionResponse(response))
}
#[cfg(feature = "unstable_session_resume")]
ClientRequest::ResumeSessionRequest(args) => {
let response = self.resume_session(args).await?;
Ok(AgentResponse::ResumeSessionResponse(response))
}
ClientRequest::ExtMethodRequest(args) => {
let response = self.ext_method(args).await?;
Ok(AgentResponse::ExtMethodResponse(response))
Expand Down
46 changes: 46 additions & 0 deletions src/agent-client-protocol/src/rpc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ impl Agent for TestAgent {
))
}

#[cfg(feature = "unstable_session_resume")]
async fn resume_session(
&self,
args: agent_client_protocol_schema::ResumeSessionRequest,
) -> Result<agent_client_protocol_schema::ResumeSessionResponse> {
// Check if session exists
if !self.sessions.lock().unwrap().contains_key(&args.session_id) {
return Err(Error::invalid_params());
}
Ok(agent_client_protocol_schema::ResumeSessionResponse::new())
}

async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
dbg!();
match dbg!(args.method.as_ref()) {
Expand Down Expand Up @@ -773,3 +785,37 @@ async fn test_list_sessions() {
})
.await;
}

#[cfg(feature = "unstable_session_resume")]
#[tokio::test]
async fn test_resume_session() {
let local_set = tokio::task::LocalSet::new();
local_set
.run_until(async {
let client = TestClient::new();
let agent = TestAgent::new();

let (agent_conn, _client_conn) = create_connection_pair(&client, &agent);

// First create a session
let new_session_response = agent_conn
.new_session(NewSessionRequest::new("/test"))
.await
.expect("new_session failed");

let session_id = new_session_response.session_id;

// Resume the session
let resume_response = agent_conn
.resume_session(agent_client_protocol_schema::ResumeSessionRequest::new(
session_id.clone(),
"/test",
))
.await
.expect("resume_session failed");

// Verify we got a valid response (no modes by default in TestAgent)
assert!(resume_response.modes.is_none());
})
.await;
}