feat: Adds max_turns for the agent without user input (#3208)

This commit is contained in:
Jarrod Sibbison
2025-07-03 11:57:25 +10:00
committed by GitHub
parent cf818ada89
commit 2c86a0eb6e
13 changed files with 284 additions and 2 deletions
+18
View File
@@ -55,6 +55,8 @@ use super::subagent_manager::SubAgentManager;
use super::subagent_tools;
use super::tool_execution::{ToolCallResult, CHAT_MODE_TOOL_SKIPPED_RESPONSE, DECLINED_RESPONSE};
const DEFAULT_MAX_TURNS: u32 = 1000;
/// The main goose Agent
pub struct Agent {
pub(super) provider: Mutex<Option<Arc<dyn Provider>>>,
@@ -707,7 +709,23 @@ impl Agent {
Ok(Box::pin(async_stream::try_stream! {
let _ = reply_span.enter();
let mut turns_taken = 0u32;
let max_turns = session
.as_ref()
.and_then(|s| s.max_turns)
.unwrap_or_else(|| {
config.get_param("GOOSE_MAX_TURNS").unwrap_or(DEFAULT_MAX_TURNS)
});
loop {
turns_taken += 1;
if turns_taken > max_turns {
yield AgentEvent::Message(Message::assistant().with_text(
"I've reached the maximum number of actions I can do without user input. Would you like me to continue?"
));
break;
}
// Check for MCP notifications from subagents
let mcp_notifications = self.get_mcp_notifications().await;
for notification in mcp_notifications {
+2
View File
@@ -26,4 +26,6 @@ pub struct SessionConfig {
pub schedule_id: Option<String>,
/// Execution mode for scheduled jobs: "foreground" or "background"
pub execution_mode: Option<String>,
/// Maximum number of turns (iterations) allowed without user input
pub max_turns: Option<u32>,
}
+1
View File
@@ -1203,6 +1203,7 @@ async fn run_scheduled_job_internal(
working_dir: current_dir.clone(),
schedule_id: Some(job.id.clone()),
execution_mode: job.execution_mode.clone(),
max_turns: None,
};
match agent