pub async fn run_agent(
provider: &dyn ModelProvider,
tools: &[Arc<dyn Tool>],
messages: &mut Vec<AgentMessage>,
model: &Model,
config: &RunConfig,
cancel: &CancellationToken,
hooks: &RunHooks<'_>,
) -> Result<RunOutcome>Expand description
Run the agent loop.
messages is seeded by the caller (typically a System message followed
by a User message) and mutated in place as the loop appends assistant
turns and tool results.
Budgets (from RunConfig):
max_turnscaps total model turns.turn_timeout_mscaps each providerinvoke.max_tool_calls_per_turnrejects runaway responses.
Concurrency: when tool_concurrency > 1, tool calls within a turn run on
a JoinSet with the configured cap; results are always appended in the
order the model issued them. tool_concurrency == 1 is sequential.
Cancellation: the loop checks cancel.is_cancelled() between turns and
composes it into each tool call.