mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-22 16:02:24 +00:00
feat: configurable max ai agent iterations (#7302)
* feat: configurable max ai agent iterations * nit * increase limit
This commit is contained in:
@@ -118,6 +118,7 @@ pub struct AIAgentArgs {
|
||||
pub user_images: Option<Vec<S3Object>>,
|
||||
pub streaming: Option<bool>,
|
||||
pub messages_context_length: Option<usize>,
|
||||
pub max_iterations: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
||||
@@ -75,7 +75,8 @@ lazy_static::lazy_static! {
|
||||
};
|
||||
}
|
||||
|
||||
const MAX_AGENT_ITERATIONS: usize = 10;
|
||||
const DEFAULT_MAX_AGENT_ITERATIONS: usize = 10;
|
||||
const HARD_MAX_AGENT_ITERATIONS: usize = 1000;
|
||||
|
||||
pub async fn handle_ai_agent_job(
|
||||
// connection
|
||||
@@ -547,8 +548,13 @@ pub async fn run_agent(
|
||||
None
|
||||
};
|
||||
|
||||
let max_iterations = args
|
||||
.max_iterations
|
||||
.map(|m| m.clamp(1, HARD_MAX_AGENT_ITERATIONS))
|
||||
.unwrap_or(DEFAULT_MAX_AGENT_ITERATIONS);
|
||||
|
||||
// Main agent loop
|
||||
for i in 0..MAX_AGENT_ITERATIONS {
|
||||
for i in 0..max_iterations {
|
||||
if used_structured_output_tool {
|
||||
break;
|
||||
}
|
||||
@@ -717,7 +723,7 @@ pub async fn run_agent(
|
||||
|
||||
if tool_calls.is_empty() {
|
||||
break;
|
||||
} else if i == MAX_AGENT_ITERATIONS - 1 {
|
||||
} else if i == max_iterations - 1 {
|
||||
return Err(Error::internal_err(
|
||||
"AI agent reached max iterations, but there are still tool calls"
|
||||
.to_string(),
|
||||
|
||||
@@ -65,6 +65,12 @@ export const AI_AGENT_SCHEMA = {
|
||||
description:
|
||||
'Controls randomness in text generation. Range: 0.0 (deterministic) to 2.0 (random).',
|
||||
showExpr: "fields.output_type === 'text'"
|
||||
},
|
||||
max_iterations: {
|
||||
type: 'number',
|
||||
description:
|
||||
'Limits how many times the agent can loop through reasoning and tool use. Range: 1-1000.',
|
||||
default: 10
|
||||
}
|
||||
},
|
||||
required: ['provider', 'user_message', 'output_type'],
|
||||
@@ -78,7 +84,8 @@ export const AI_AGENT_SCHEMA = {
|
||||
'output_schema',
|
||||
'user_images',
|
||||
'max_completion_tokens',
|
||||
'temperature'
|
||||
'temperature',
|
||||
'max_iterations'
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user