-
Notifications
You must be signed in to change notification settings - Fork 328
Support model and effort selection for external agents #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -70,6 +70,7 @@ impl ExternalAgentTransport for CodexTransport { | |||||||||||||||||||
| } else { | ||||||||||||||||||||
| spec.args.clone() | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| let args = args_with_model_and_effort(args, spec.model.as_deref(), spec.effort.as_deref()); | ||||||||||||||||||||
| Ok(Box::new( | ||||||||||||||||||||
| CodexAppServerSession::start( | ||||||||||||||||||||
| binary, | ||||||||||||||||||||
|
|
@@ -382,6 +383,75 @@ fn extract_usage(value: &Value) -> Option<crate::types::TokenUsage> { | |||||||||||||||||||
| }) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| fn args_with_model_and_effort( | ||||||||||||||||||||
| mut args: Vec<String>, | ||||||||||||||||||||
| model: Option<&str>, | ||||||||||||||||||||
| effort: Option<&str>, | ||||||||||||||||||||
| ) -> Vec<String> { | ||||||||||||||||||||
| let insert_at = args.iter().position(|arg| arg == "app-server").unwrap_or(0); | ||||||||||||||||||||
| let mut inserts = Vec::new(); | ||||||||||||||||||||
| if let Some(model) = model | ||||||||||||||||||||
| && !has_model_arg(&args) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| inserts.extend(["--model".to_string(), model.to_string()]); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if let Some(effort) = effort | ||||||||||||||||||||
| && !has_effort_arg(&args) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| inserts.extend([ | ||||||||||||||||||||
| "-c".to_string(), | ||||||||||||||||||||
| format!("model_reasoning_effort=\"{effort}\""), | ||||||||||||||||||||
| ]); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| for (offset, arg) in inserts.into_iter().enumerate() { | ||||||||||||||||||||
| args.insert(insert_at + offset, arg); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| args | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| fn has_model_arg(args: &[String]) -> bool { | ||||||||||||||||||||
| let mut iter = args.iter().peekable(); | ||||||||||||||||||||
| while let Some(arg) = iter.next() { | ||||||||||||||||||||
| if matches!(arg.as_str(), "--model" | "-m") { | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Similar to the
Suggested change
|
||||||||||||||||||||
| if matches!(arg.as_str(), "--config" | "-c") | ||||||||||||||||||||
| && iter | ||||||||||||||||||||
| .peek() | ||||||||||||||||||||
| .is_some_and(|next| next.trim_start().starts_with("model=")) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if arg | ||||||||||||||||||||
| .strip_prefix("--config=") | ||||||||||||||||||||
| .is_some_and(|value| value.trim_start().starts_with("model=")) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| false | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| fn has_effort_arg(args: &[String]) -> bool { | ||||||||||||||||||||
| let mut iter = args.iter().peekable(); | ||||||||||||||||||||
| while let Some(arg) = iter.next() { | ||||||||||||||||||||
| if matches!(arg.as_str(), "--config" | "-c") | ||||||||||||||||||||
| && iter | ||||||||||||||||||||
| .peek() | ||||||||||||||||||||
| .is_some_and(|next| next.trim_start().starts_with("model_reasoning_effort=")) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if arg | ||||||||||||||||||||
| .strip_prefix("--config=") | ||||||||||||||||||||
| .is_some_and(|value| value.trim_start().starts_with("model_reasoning_effort=")) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| return true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| false | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| fn token_count_field(value: &Value, fields: &[&str]) -> Option<u32> { | ||||||||||||||||||||
| fields.iter().find_map(|field| { | ||||||||||||||||||||
| value | ||||||||||||||||||||
|
|
@@ -443,6 +513,44 @@ mod tests { | |||||||||||||||||||
| assert_eq!(camel.output_tokens, 55); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #[test] | ||||||||||||||||||||
| fn inserts_model_and_effort_before_app_server_command() { | ||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||
| args_with_model_and_effort( | ||||||||||||||||||||
| vec!["app-server".to_string()], | ||||||||||||||||||||
| Some("gpt-5.5"), | ||||||||||||||||||||
| Some("xhigh") | ||||||||||||||||||||
| ), | ||||||||||||||||||||
| vec![ | ||||||||||||||||||||
| "--model", | ||||||||||||||||||||
| "gpt-5.5", | ||||||||||||||||||||
| "-c", | ||||||||||||||||||||
| "model_reasoning_effort=\"xhigh\"", | ||||||||||||||||||||
| "app-server" | ||||||||||||||||||||
| ] | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||
| args_with_model_and_effort( | ||||||||||||||||||||
| vec![ | ||||||||||||||||||||
| "--model".to_string(), | ||||||||||||||||||||
| "configured".to_string(), | ||||||||||||||||||||
| "-c".to_string(), | ||||||||||||||||||||
| "model_reasoning_effort=\"high\"".to_string(), | ||||||||||||||||||||
| "app-server".to_string() | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| Some("ignored"), | ||||||||||||||||||||
| Some("ignored"), | ||||||||||||||||||||
| ), | ||||||||||||||||||||
| vec![ | ||||||||||||||||||||
| "--model", | ||||||||||||||||||||
| "configured", | ||||||||||||||||||||
| "-c", | ||||||||||||||||||||
| "model_reasoning_effort=\"high\"", | ||||||||||||||||||||
| "app-server" | ||||||||||||||||||||
| ] | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #[tokio::test] | ||||||||||||||||||||
| async fn codex_session_reuses_thread_for_multiple_prompts() -> anyhow::Result<()> { | ||||||||||||||||||||
| let unique = SystemTime::now() | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has_model_argandhas_effort_argmiss the--flag=valueformIf a user configures
args = ["--model=opus"]orargs = ["--effort=low"]in their agent config (equals-sign form), these guards returnfalseand a second conflicting flag is appended — e.g.["--model=opus", "--model", "claude-opus-4"]. The codex version handles--model=valueviastrip_prefix("--config=")but the Claude Code version has no equivalent.