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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tokio = { version = "1.48", features = ["full"] }
tokio-util = { version = "0.7", features = ["compat"] }

# Protocol
agent-client-protocol-schema = { version = "=0.10.4" }
agent-client-protocol-schema = { version = "=0.10.5" }

# Serialization
serde = { version = "1.0", features = ["derive", "rc"] }
Expand Down
19 changes: 19 additions & 0 deletions examples/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ impl acp::Agent for ExampleAgent {
Ok(acp::SetSessionModelResponse::default())
}

#[cfg(feature = "unstable_session_config_options")]
async fn set_session_config_option(
&self,
args: acp::SetSessionConfigOptionRequest,
) -> Result<acp::SetSessionConfigOptionResponse, acp::Error> {
log::info!("Received set session config option request {args:?}");
Ok(acp::SetSessionConfigOptionResponse::new(vec![
acp::SessionConfigOption::select(
args.config_id,
"Example Option",
args.value,
vec![
acp::SessionConfigSelectOption::new("option1", "Option 1"),
acp::SessionConfigSelectOption::new("option2", "Option 2"),
]),
),
]))
}

async fn ext_method(&self, args: acp::ExtRequest) -> Result<acp::ExtResponse, acp::Error> {
log::info!(
"Received extension method call: method={}, params={:?}",
Expand Down
35 changes: 35 additions & 0 deletions src/agent-client-protocol/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use agent_client_protocol_schema::{ForkSessionRequest, ForkSessionResponse};
use agent_client_protocol_schema::{ListSessionsRequest, ListSessionsResponse};
#[cfg(feature = "unstable_session_resume")]
use agent_client_protocol_schema::{ResumeSessionRequest, ResumeSessionResponse};
#[cfg(feature = "unstable_session_config_options")]
use agent_client_protocol_schema::{SetSessionConfigOptionRequest, SetSessionConfigOptionResponse};
#[cfg(feature = "unstable_session_model")]
use agent_client_protocol_schema::{SetSessionModelRequest, SetSessionModelResponse};
use serde_json::value::RawValue;
Expand Down Expand Up @@ -132,6 +134,25 @@ 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.
///
/// Sets the current value for a session configuration option.
///
/// Configuration options allow agents to expose arbitrary selectors (like model choice,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is super cool. thanks for putting it in!

/// reasoning level, etc.) that clients can display and modify.
///
/// The response returns the full list of configuration options with their current values,
/// as changing one option may affect others.
#[cfg(feature = "unstable_session_config_options")]
async fn set_session_config_option(
&self,
_args: SetSessionConfigOptionRequest,
) -> Result<SetSessionConfigOptionResponse> {
Err(Error::method_not_found())
}

/// **UNSTABLE**
///
/// This capability is not part of the spec yet, and may be removed or changed at any point.
Expand Down Expand Up @@ -225,6 +246,13 @@ impl<T: Agent> Agent for Rc<T> {
) -> Result<SetSessionModelResponse> {
self.as_ref().set_session_model(args).await
}
#[cfg(feature = "unstable_session_config_options")]
async fn set_session_config_option(
&self,
args: SetSessionConfigOptionRequest,
) -> Result<SetSessionConfigOptionResponse> {
self.as_ref().set_session_config_option(args).await
}
#[cfg(feature = "unstable_session_list")]
async fn list_sessions(&self, args: ListSessionsRequest) -> Result<ListSessionsResponse> {
self.as_ref().list_sessions(args).await
Expand Down Expand Up @@ -278,6 +306,13 @@ impl<T: Agent> Agent for Arc<T> {
) -> Result<SetSessionModelResponse> {
self.as_ref().set_session_model(args).await
}
#[cfg(feature = "unstable_session_config_options")]
async fn set_session_config_option(
&self,
args: SetSessionConfigOptionRequest,
) -> Result<SetSessionConfigOptionResponse> {
self.as_ref().set_session_config_option(args).await
}
#[cfg(feature = "unstable_session_list")]
async fn list_sessions(&self, args: ListSessionsRequest) -> Result<ListSessionsResponse> {
self.as_ref().list_sessions(args).await
Expand Down
24 changes: 24 additions & 0 deletions src/agent-client-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ impl Agent for ClientSideConnection {
.await
}

#[cfg(feature = "unstable_session_config_options")]
async fn set_session_config_option(
&self,
args: SetSessionConfigOptionRequest,
) -> Result<SetSessionConfigOptionResponse> {
self.conn
.request(
AGENT_METHOD_NAMES.session_set_config_option,
Some(ClientRequest::SetSessionConfigOptionRequest(args)),
)
.await
}

async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse> {
self.conn
.request(
Expand Down Expand Up @@ -560,6 +573,12 @@ impl Side for AgentSide {
m if m == AGENT_METHOD_NAMES.session_resume => serde_json::from_str(params.get())
.map(ClientRequest::ResumeSessionRequest)
.map_err(Into::into),
#[cfg(feature = "unstable_session_config_options")]
m if m == AGENT_METHOD_NAMES.session_set_config_option => {
serde_json::from_str(params.get())
.map(ClientRequest::SetSessionConfigOptionRequest)
.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 @@ -644,6 +663,11 @@ impl<T: Agent> MessageHandler<AgentSide> for T {
let response = self.resume_session(args).await?;
Ok(AgentResponse::ResumeSessionResponse(response))
}
#[cfg(feature = "unstable_session_config_options")]
ClientRequest::SetSessionConfigOptionRequest(args) => {
let response = self.set_session_config_option(args).await?;
Ok(AgentResponse::SetSessionConfigOptionResponse(response))
}
ClientRequest::ExtMethodRequest(args) => {
let response = self.ext_method(args).await?;
Ok(AgentResponse::ExtMethodResponse(response))
Expand Down
57 changes: 57 additions & 0 deletions src/agent-client-protocol/src/rpc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,30 @@ impl Agent for TestAgent {
Ok(agent_client_protocol_schema::ResumeSessionResponse::new())
}

#[cfg(feature = "unstable_session_config_options")]
async fn set_session_config_option(
&self,
args: agent_client_protocol_schema::SetSessionConfigOptionRequest,
) -> Result<agent_client_protocol_schema::SetSessionConfigOptionResponse> {
Ok(
agent_client_protocol_schema::SetSessionConfigOptionResponse::new(vec![
agent_client_protocol_schema::SessionConfigOption::select(
args.config_id,
"Test Option",
args.value,
vec![
agent_client_protocol_schema::SessionConfigSelectOption::new(
"value1", "Value 1",
),
agent_client_protocol_schema::SessionConfigSelectOption::new(
"value2", "Value 2",
),
],
),
]),
)
}

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

#[cfg(feature = "unstable_session_config_options")]
#[tokio::test]
async fn test_set_session_config_option() {
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);

// Set a config option
let response = agent_conn
.set_session_config_option(
agent_client_protocol_schema::SetSessionConfigOptionRequest::new(
"test-session",
"mode",
"value2",
),
)
.await
.expect("set_session_config_option failed");

// Verify we got config options back
assert_eq!(response.config_options.len(), 1);
assert_eq!(
response.config_options[0].id,
agent_client_protocol_schema::SessionConfigId::new("mode")
);
})
.await;
}