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
+13 -1
View File
@@ -41,6 +41,8 @@ pub struct SessionBuilderConfig {
pub debug: bool,
/// Maximum number of consecutive identical tool calls allowed
pub max_tool_repetitions: Option<u32>,
/// Maximum number of turns (iterations) allowed without user input
pub max_turns: Option<u32>,
/// ID of the scheduled job that triggered this session (if any)
pub scheduled_job_id: Option<String>,
/// Whether this session will be used interactively (affects debugging prompts)
@@ -122,7 +124,13 @@ async fn offer_extension_debugging_help(
std::env::temp_dir().join(format!("goose_debug_extension_{}.jsonl", extension_name));
// Create the debugging session
let mut debug_session = Session::new(debug_agent, Some(temp_session_file.clone()), false, None);
let mut debug_session = Session::new(
debug_agent,
Some(temp_session_file.clone()),
false,
None,
None,
);
// Process the debugging request
println!("{}", style("Analyzing the extension failure...").yellow());
@@ -367,6 +375,7 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> Session {
session_file.clone(),
session_config.debug,
session_config.scheduled_job_id.clone(),
session_config.max_turns,
);
// Add extensions if provided
@@ -516,6 +525,7 @@ mod tests {
settings: None,
debug: true,
max_tool_repetitions: Some(5),
max_turns: None,
scheduled_job_id: None,
interactive: true,
quiet: false,
@@ -528,6 +538,7 @@ mod tests {
assert_eq!(config.builtins.len(), 1);
assert!(config.debug);
assert_eq!(config.max_tool_repetitions, Some(5));
assert!(config.max_turns.is_none());
assert!(config.scheduled_job_id.is_none());
assert!(config.interactive);
assert!(!config.quiet);
@@ -547,6 +558,7 @@ mod tests {
assert!(config.additional_system_prompt.is_none());
assert!(!config.debug);
assert!(config.max_tool_repetitions.is_none());
assert!(config.max_turns.is_none());
assert!(config.scheduled_job_id.is_none());
assert!(!config.interactive);
assert!(!config.quiet);
+4
View File
@@ -52,6 +52,7 @@ pub struct Session {
debug: bool, // New field for debug mode
run_mode: RunMode,
scheduled_job_id: Option<String>, // ID of the scheduled job that triggered this session
max_turns: Option<u32>,
}
// Cache structure for completion data
@@ -113,6 +114,7 @@ impl Session {
session_file: Option<PathBuf>,
debug: bool,
scheduled_job_id: Option<String>,
max_turns: Option<u32>,
) -> Self {
let messages = if let Some(session_file) = &session_file {
match session::read_messages(session_file) {
@@ -135,6 +137,7 @@ impl Session {
debug,
run_mode: RunMode::Normal,
scheduled_job_id,
max_turns,
}
}
@@ -757,6 +760,7 @@ impl Session {
.expect("failed to get current session working directory"),
schedule_id: self.scheduled_job_id.clone(),
execution_mode: None,
max_turns: self.max_turns,
}
});
let mut stream = self