Fix max turns configuration (#7612)

Signed-off-by: alexyao2015 <alexyao2015@users.noreply.github.com>
Co-authored-by: alexyao2015 <alexyao2015@users.noreply.github.com>
This commit is contained in:
Alex Yao
2026-03-05 15:42:12 -05:00
committed by GitHub
parent 2675a0bd74
commit abadb87892
3 changed files with 16 additions and 11 deletions
+5 -1
View File
@@ -1118,7 +1118,11 @@ impl Agent {
let reply_stream_span = tracing::info_span!(target: "goose::agents::agent", "reply_stream");
let _stream_guard = reply_stream_span.enter();
let mut turns_taken = 0u32;
let max_turns = session_config.max_turns.unwrap_or(DEFAULT_MAX_TURNS);
let max_turns = session_config.max_turns.unwrap_or_else(|| {
Config::global()
.get_param::<u32>("GOOSE_MAX_TURNS")
.unwrap_or(DEFAULT_MAX_TURNS)
});
let mut compaction_attempts = 0;
let mut last_assistant_text = String::new();
@@ -1455,9 +1455,8 @@ impl SummonClient {
let max_turns = self.resolve_max_turns(session);
let mut task_config =
TaskConfig::new(provider, &session.id, &session.working_dir, extensions);
task_config.max_turns = Some(max_turns);
let task_config = TaskConfig::new(provider, &session.id, &session.working_dir, extensions)
.with_max_turns(Some(max_turns));
Ok(task_config)
}
@@ -1512,6 +1511,7 @@ impl SummonClient {
}
fn resolve_max_turns(&self, session: &crate::session::Session) -> usize {
// Priority: env var > recipe settings > config.yaml > default
std::env::var("GOOSE_SUBAGENT_MAX_TURNS")
.ok()
.and_then(|v| v.parse().ok())
@@ -1522,6 +1522,11 @@ impl SummonClient {
.and_then(|r| r.settings.as_ref())
.and_then(|s| s.max_turns)
})
.or_else(|| {
Config::global()
.get_param::<usize>("GOOSE_SUBAGENT_MAX_TURNS")
.ok()
})
.unwrap_or(DEFAULT_SUBAGENT_MAX_TURNS)
}
@@ -1,6 +1,6 @@
use crate::agents::ExtensionConfig;
use crate::config::Config;
use crate::providers::base::Provider;
use std::env;
use std::fmt;
use std::path::{Path, PathBuf};
use std::sync::Arc;
@@ -8,9 +8,6 @@ use std::sync::Arc;
/// Default maximum number of turns for task execution
pub const DEFAULT_SUBAGENT_MAX_TURNS: usize = 25;
/// Environment variable name for configuring max turns
pub const GOOSE_SUBAGENT_MAX_TURNS_ENV_VAR: &str = "GOOSE_SUBAGENT_MAX_TURNS";
/// Configuration for task execution with all necessary dependencies
#[derive(Clone)]
pub struct TaskConfig {
@@ -46,9 +43,8 @@ impl TaskConfig {
parent_working_dir: parent_working_dir.to_owned(),
extensions,
max_turns: Some(
env::var(GOOSE_SUBAGENT_MAX_TURNS_ENV_VAR)
.ok()
.and_then(|val| val.parse::<usize>().ok())
Config::global()
.get_param::<usize>("GOOSE_SUBAGENT_MAX_TURNS")
.unwrap_or(DEFAULT_SUBAGENT_MAX_TURNS),
),
}