Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(agent): support model-aware effort in Cursor sessions (#7155)

Eric Hayesc45d58760ecb
diff --git a/crates/cursor_cloud_agents/src/domain/model_options.rs b/crates/cursor_cloud_agents/src/domain/model_options.rs
index d21f853992..86e34003b7 100644
--- a/crates/cursor_cloud_agents/src/domain/model_options.rs
+++ b/crates/cursor_cloud_agents/src/domain/model_options.rs
@@ -1,15 +1,21 @@
//! Shared projection of Cursor's model catalog into ACP session configuration.
-use super::model::{CursorModel, ModelFamily};
+use super::model::{CursorModel, ModelChoice, ModelFamily};
use agent_client_protocol::schema::v1::{
SessionConfigGroupId, SessionConfigId, SessionConfigKind, SessionConfigOption,
- SessionConfigSelect, SessionConfigSelectGroup, SessionConfigSelectOption,
- SessionConfigSelectOptions, SessionConfigValueId,
+ SessionConfigOptionCategory, SessionConfigSelect, SessionConfigSelectGroup,
+ SessionConfigSelectOption, SessionConfigSelectOptions, SessionConfigValueId,
};
/// ACP config id used for model selection.
pub const MODEL_CONFIG_ID: &str = "model";
+/// Portable ACP config id used for Cursor model reasoning variants.
+pub const REASONING_EFFORT_CONFIG_ID: &str = "reasoning_effort";
+
+/// Parameter ids Cursor currently uses for reasoning effort across models.
+pub const REASONING_PARAMETER_IDS: [&str; 2] = ["effort", "reasoning"];
+
/// Cursor's server-selected model entry.
pub const AUTO_MODEL_ID: &str = "default";
@@ -51,12 +57,106 @@ pub fn cursor_model_config_options(
} else {
SessionConfigSelectOptions::Ungrouped(models.iter().map(select_option).collect())
};
- vec![SessionConfigOption::new(
- SessionConfigId::new(MODEL_CONFIG_ID),
- "Model",
- SessionConfigKind::Select(SessionConfigSelect::new(
- SessionConfigValueId::new(current),
- options,
- )),
- )]
+ vec![
+ SessionConfigOption::new(
+ SessionConfigId::new(MODEL_CONFIG_ID),
+ "Model",
+ SessionConfigKind::Select(SessionConfigSelect::new(
+ SessionConfigValueId::new(current),
+ options,
+ )),
+ )
+ .category(SessionConfigOptionCategory::Model),
+ ]
}
+
+/// Build Cursor's model select and the selected model's reasoning-effort select.
+///
+/// Cursor enumerates valid model parameter combinations as variants. The
+/// effort control is therefore advertised only when the current concrete
+/// model has more than one accepted value.
+#[must_use]
+pub fn cursor_session_config_options(
+ models: &[CursorModel],
+ current: Option<&ModelChoice>,
+) -> Vec<SessionConfigOption> {
+ let mut options = cursor_model_config_options(models, current.map(|model| model.id.clone()));
+ let Some(current) = current else {
+ return options;
+ };
+ let Some(model) = models.iter().find(|model| model.id == current.id) else {
+ return options;
+ };
+ let Some(parameter) = current
+ .params
+ .iter()
+ .find(|param| REASONING_PARAMETER_IDS.contains(&param.id.as_str()))
+ else {
+ return options;
+ };
+ let mut values = Vec::new();
+ for variant in &model.variants {
+ if !model_params_match_except(&variant.params, &current.params, &parameter.id) {
+ continue;
+ }
+ let Some(value) = variant
+ .params
+ .iter()
+ .find(|param| param.id == parameter.id)
+ .map(|param| param.value.as_str())
+ else {
+ continue;
+ };
+ if !values.contains(&value) {
+ values.push(value);
+ }
+ }
+ if values.len() < 2 {
+ return options;
+ }
+ options.push(
+ SessionConfigOption::select(
+ REASONING_EFFORT_CONFIG_ID,
+ "Reasoning effort",
+ SessionConfigValueId::new(parameter.value.clone()),
+ values
+ .into_iter()
+ .map(|value| {
+ SessionConfigSelectOption::new(
+ SessionConfigValueId::new(value.to_owned()),
+ display_value(value),
+ )
+ })
+ .collect::<Vec<_>>(),
+ )
+ .category(SessionConfigOptionCategory::ThoughtLevel),
+ );
+ options
+}
+
+fn display_value(value: &str) -> String {
+ let mut chars = value.chars();
+ chars
+ .next()
+ .map(|first| first.to_uppercase().chain(chars).collect())
+ .unwrap_or_default()
+}
+
+pub(super) fn model_params_match_except(
+ left: &[crate::domain::model::ModelParam],
+ right: &[crate::domain::model::ModelParam],
+ excluded_id: &str,
+) -> bool {
+ let left = left
+ .iter()
+ .filter(|param| param.id != excluded_id)
+ .collect::<Vec<_>>();
+ let right = right
+ .iter()
+ .filter(|param| param.id != excluded_id)
+ .collect::<Vec<_>>();
+ left.len() == right.len() && left.iter().all(|param| right.contains(param))
+}
+
+#[cfg(test)]
+mod test;
diff --git a/crates/cursor_cloud_agents/src/domain/model_options/test.rs b/crates/cursor_cloud_agents/src/domain/model_options/test.rs
new file mode 100644
index 0000000000..366e7d98eb
--- /dev/null
+++ b/crates/cursor_cloud_agents/src/domain/model_options/test.rs
@@ -0,0 +1,62 @@
+use super::*;
+use crate::domain::model::{ModelParam, ModelVariant};
+
+fn variant(effort: &str, fast: &str) -> ModelVariant {
+ ModelVariant {
+ params: vec![
+ ModelParam {
+ id: "effort".into(),
+ value: effort.into(),
+ },
+ ModelParam {
+ id: "fast".into(),
+ value: fast.into(),
+ },
+ ],
+ is_default: effort == "low",
+ }
+}
+
+#[test]
+fn advertised_values_preserve_other_parameters_and_remain_opaque() {
+ let model = CursorModel {
+ id: "cursor-model".into(),
+ display_name: "Model".into(),
+ variants: vec![
+ variant("low", "false"),
+ variant("ultra", "false"),
+ variant("high", "true"),
+ ],
+ };
+ let current = model.default_choice();
+ let options = cursor_session_config_options(&[model], Some(&current));
+ let SessionConfigKind::Select(effort) = &options[1].kind else {
+ panic!("select");
+ };
+ let SessionConfigSelectOptions::Ungrouped(values) = &effort.options else {
+ panic!("values");
+ };
+ assert_eq!(
+ values
+ .iter()
+ .map(|option| option.value.to_string())
+ .collect::<Vec<_>>(),
+ ["low", "ultra"]
+ );
+ assert_eq!(effort.current_value.to_string(), "low");
+}
+
+#[test]
+fn no_effort_control_when_only_other_dimensions_can_change() {
+ let model = CursorModel {
+ id: "cursor-model".into(),
+ display_name: "Model".into(),
+ variants: vec![variant("low", "false"), variant("high", "true")],
+ };
+ let current = model.default_choice();
+ assert_eq!(
+ cursor_session_config_options(&[model], Some(&current)).len(),
+ 1
+ );
+ assert!(cursor_session_config_options(&[], None).is_empty());
+}
diff --git a/crates/cursor_cloud_agents/src/domain/service.rs b/crates/cursor_cloud_agents/src/domain/service.rs
index f647a676bb..2df9b6ca9e 100644
--- a/crates/cursor_cloud_agents/src/domain/service.rs
+++ b/crates/cursor_cloud_agents/src/domain/service.rs
@@ -666,10 +666,15 @@ where
&self,
session_id: &SessionId,
) -> Result<Option<String>, SessionError> {
- Ok(self
- .effective_model(session_id)
- .await?
- .map(|model| model.id))
+ Ok(self.session_model(session_id).await?.map(|model| model.id))
+ }
+
+ /// The concrete model variant the session's next run will use.
+ pub async fn session_model(
+ &self,
+ session_id: &SessionId,
+ ) -> Result<Option<ModelChoice>, SessionError> {
+ self.effective_model(session_id).await
}
/// Choose the model a session's next run will use.
@@ -702,6 +707,72 @@ where
Ok(())
}
+ /// Choose the reasoning effort for the session's next run.
+ ///
+ /// Cursor accepts only combinations returned by `GET /v1/models`, so the
+ /// selected effort is resolved to a variant that preserves every other
+ /// parameter of the current choice.
+ pub async fn set_reasoning_effort(
+ &self,
+ session_id: &SessionId,
+ effort: &str,
+ ) -> Result<(), SessionError> {
+ use crate::domain::model_options::REASONING_PARAMETER_IDS;
+
+ let session = self.session(session_id)?;
+ let current = self.effective_model(session_id).await?.ok_or_else(|| {
+ SessionError::Cursor(rootcause::report!(
+ "choose a concrete cursor model before setting reasoning effort"
+ ))
+ })?;
+ let models = self.models().await?;
+ let model = models
+ .iter()
+ .find(|model| model.id == current.id)
+ .ok_or_else(|| {
+ SessionError::Cursor(rootcause::report!(
+ "current cursor model is no longer offered"
+ ))
+ })?;
+ let parameter_id = current
+ .params
+ .iter()
+ .find(|param| REASONING_PARAMETER_IDS.contains(&param.id.as_str()))
+ .map(|param| param.id.as_str())
+ .ok_or_else(|| {
+ SessionError::Cursor(rootcause::report!(
+ "cursor model {} has no reasoning effort parameter",
+ current.id
+ ))
+ })?;
+ let choice = model
+ .variants
+ .iter()
+ .find(|variant| {
+ variant
+ .params
+ .iter()
+ .any(|param| param.id == parameter_id && param.value == effort)
+ && super::model_options::model_params_match_except(
+ &variant.params,
+ &current.params,
+ parameter_id,
+ )
+ })
+ .map(|variant| ModelChoice {
+ id: model.id.clone(),
+ params: variant.params.clone(),
+ })
+ .ok_or_else(|| {
+ SessionError::Cursor(rootcause::report!(
+ "cursor model {} has no compatible reasoning effort {effort}",
+ current.id
+ ))
+ })?;
+ session.state.lock().expect("session state poisoned").model = Some(choice);
+ Ok(())
+ }
+
/// The session's explicit choice, or the deployment's pinned default
/// resolved to a variant Cursor will accept.
///
diff --git a/crates/cursor_cloud_agents/src/inbound/acp.rs b/crates/cursor_cloud_agents/src/inbound/acp.rs
index ada91452fb..ae380f144c 100644
--- a/crates/cursor_cloud_agents/src/inbound/acp.rs
+++ b/crates/cursor_cloud_agents/src/inbound/acp.rs
@@ -30,7 +30,9 @@ mod test;
use crate::domain::error::SessionError;
use crate::domain::model::{McpHeader, McpServer, McpTransport};
-use crate::domain::model_options::{MODEL_CONFIG_ID, cursor_model_config_options};
+use crate::domain::model_options::{
+ MODEL_CONFIG_ID, REASONING_EFFORT_CONFIG_ID, cursor_session_config_options,
+};
use crate::domain::ports::{
ArtifactStore, CursorAgents, CursorArtifacts, RepositoryChooser, RunStream, SessionNotifier,
WorkingBranchReporter,
@@ -510,15 +512,19 @@ where
let service = Arc::clone(&service);
async move |request: SetSessionConfigOptionRequest, responder, _connection| {
let session = request.session_id;
- // Only the model is configurable, so anything else is the
- // client naming an option this agent never advertised.
- if request.config_id.to_string() != MODEL_CONFIG_ID {
- return responder.respond_with_error(AcpError::invalid_params());
- }
let Some(model) = request.value.as_value_id() else {
return responder.respond_with_error(AcpError::invalid_params());
};
- if let Err(error) = service.set_model(&session, &model.to_string()).await {
+ let result = match request.config_id.to_string().as_str() {
+ MODEL_CONFIG_ID => service.set_model(&session, &model.to_string()).await,
+ REASONING_EFFORT_CONFIG_ID => {
+ service
+ .set_reasoning_effort(&session, &model.to_string())
+ .await
+ }
+ _ => return responder.respond_with_error(AcpError::invalid_params()),
+ };
+ if let Err(error) = result {
// The id is the client's to get right, and the error
// names what this account may choose instead.
tracing::warn!(error = %error, "could not set the session model");
@@ -556,7 +562,7 @@ where
.await
}
-/// The session's config options: the model select, and nothing else yet.
+/// The session's config options: model and any effort values its variant supports.
///
/// This is the whole of how a client learns which models exist and which one a
/// session is on — ACP carries it as `configOptions` on the `session/new`,
@@ -566,8 +572,8 @@ where
/// One entry per model, using Cursor's own default variant, rather than one per
/// variant: `claude-opus-4-8` alone offers forty, and a picker listing hundreds
/// of near-identical rows is worse than one listing the models. Exposing the
-/// variant parameters (`effort`, `reasoning`, `fast`) is a separate control and
-/// a separate change.
+/// reasoning variant is projected as a separate ACP thought-level control;
+/// unrelated variant parameters remain on Cursor's selected default.
///
/// The entries go out grouped by family ([`ModelFamily`]) — ACP's select
/// options may be headed groups — so a client can show `Claude Opus` once with
@@ -596,7 +602,7 @@ where
return Vec::new();
}
};
- let current = match service.session_model_id(session).await {
+ let current = match service.session_model(session).await {
Ok(current) => current,
Err(error) => {
tracing::warn!(error = %error, "could not read the session's model");
@@ -616,7 +622,7 @@ where
//
// If Cursor ever drops the entry there is no honest resting value, and no
// picker beats one resting on a guess.
- cursor_model_config_options(&models, current)
+ cursor_session_config_options(&models, current.as_ref())
}
/// Advertise the curated Cursor slash-command catalog as an
diff --git a/crates/cursor_cloud_agents/src/inbound/acp/test.rs b/crates/cursor_cloud_agents/src/inbound/acp/test.rs
index 9f0f51509c..cb93e6e5ec 100644
--- a/crates/cursor_cloud_agents/src/inbound/acp/test.rs
+++ b/crates/cursor_cloud_agents/src/inbound/acp/test.rs
@@ -761,17 +761,29 @@ fn offered_models() -> Vec<CursorModel> {
display_name: "GPT-5.5".to_owned(),
variants: vec![
ModelVariant {
- params: vec![ModelParam {
- id: "reasoning".to_owned(),
- value: "low".to_owned(),
- }],
+ params: vec![
+ ModelParam {
+ id: "reasoning".to_owned(),
+ value: "low".to_owned(),
+ },
+ ModelParam {
+ id: "fast".to_owned(),
+ value: "true".to_owned(),
+ },
+ ],
is_default: false,
},
ModelVariant {
- params: vec![ModelParam {
- id: "reasoning".to_owned(),
- value: "medium".to_owned(),
- }],
+ params: vec![
+ ModelParam {
+ id: "reasoning".to_owned(),
+ value: "medium".to_owned(),
+ },
+ ModelParam {
+ id: "fast".to_owned(),
+ value: "true".to_owned(),
+ },
+ ],
is_default: true,
},
],
@@ -946,7 +958,7 @@ async fn a_listing_with_families_is_advertised_as_headed_groups() {
/// run carries it — the point being that Cursor honours `model` on a follow-up
/// run, so a change does not have to wait for a new agent.
#[tokio::test]
-async fn setting_the_model_changes_what_the_next_run_asks_for() {
+async fn setting_the_model_and_effort_changes_what_the_next_run_asks_for() {
let cursor = FakeCursor::new();
cursor.script_models(offered_models());
let (_service, mut client) =
@@ -980,6 +992,22 @@ async fn setting_the_model_changes_what_the_next_run_asks_for() {
// Answered with the whole option set, so a client folds config from one
// shape whichever response carried it.
assert_eq!(result["configOptions"][0]["currentValue"], "gpt-5.5");
+ assert_eq!(result["configOptions"][1]["id"], "reasoning_effort");
+ assert_eq!(result["configOptions"][1]["currentValue"], "medium");
+
+ let response = client
+ .call(
+ 3,
+ "session/set_config_option",
+ serde_json::json!({
+ "sessionId": session,
+ "configId": "reasoning_effort",
+ "value": "low",
+ }),
+ )
+ .await;
+ let result = expect_result(&response);
+ assert_eq!(result["configOptions"][1]["currentValue"], "low");
// And the run actually asks for it. This is the behaviour the whole feature
// rests on: Cursor honours `model` on a follow-up run, so the choice does
@@ -998,7 +1026,7 @@ async fn setting_the_model_changes_what_the_next_run_asks_for() {
events.send(CursorEvent::Done).expect("stream open");
client
.call(
- 3,
+ 4,
"session/prompt",
serde_json::json!({
"sessionId": session,
@@ -1019,11 +1047,17 @@ async fn setting_the_model_changes_what_the_next_run_asks_for() {
assert_eq!(asked.id, "gpt-5.5");
assert_eq!(
asked.params,
- vec![ModelParam {
- id: "reasoning".to_owned(),
- value: "medium".to_owned(),
- }],
- "the default variant's params travel with the id"
+ vec![
+ ModelParam {
+ id: "reasoning".to_owned(),
+ value: "low".to_owned(),
+ },
+ ModelParam {
+ id: "fast".to_owned(),
+ value: "true".to_owned(),
+ }
+ ],
+ "the selected effort travels as Cursor's accepted model variant"
);
}
@@ -1174,10 +1208,16 @@ async fn a_restored_session_keeps_its_model() {
assert_eq!(asked.id, "gpt-5.5");
assert_eq!(
asked.params,
- vec![ModelParam {
- id: "reasoning".to_owned(),
- value: "medium".to_owned(),
- }],
+ vec![
+ ModelParam {
+ id: "reasoning".to_owned(),
+ value: "medium".to_owned(),
+ },
+ ModelParam {
+ id: "fast".to_owned(),
+ value: "true".to_owned(),
+ }
+ ],
"params come from the live table's default variant, not from persistence"
);
}
diff --git a/docs/AGENT_EFFORT.md b/docs/AGENT_EFFORT.md
index 1142a31596..fc250f827e 100644
--- a/docs/AGENT_EFFORT.md
+++ b/docs/AGENT_EFFORT.md
@@ -15,3 +15,12 @@ empty list removes it. Select values and configuration ids remain opaque.
The generic setConfigOption action records a correlated control outcome. HTTP
queue acceptance does not mean the runtime accepted the setting. Clients must
wait for the runtime outcome before presenting a change as confirmed.
+
+## Cursor
+
+The authenticated Cursor catalog supplies concrete model variants. Discovery
+uses the selected model's default variant; an active session uses its effective
+variant. Only effort values with identical remaining parameters are shown.
+Changing effort preserves those parameters and selects an actual catalog variant.
+Automatic selection, missing reasoning parameters, or fewer than two compatible
+values produce no effort control. No static provider effort list is used.