pub async fn agent_loop(
context: AgentLoopContext,
config: AgentLoopConfig,
hooks: &dyn AgentHooks,
events: AgentEventSink,
cancel: CancellationToken,
) -> Result<Vec<AgentMessage>, AgentError>Expand description
Run the agent loop until completion or cancellation.
The loop iterates: provider request → stream response → detect tool calls → validate and execute tools → send tool results back → repeat until no tool calls or stop condition.