Skip to main content

agent_turn

Function agent_turn 

pub async fn agent_turn(
    config: Option<&Config>,
    model_provider: &dyn ModelProvider,
    history: &mut Vec<ChatMessage>,
    tools_registry: &[Box<dyn Tool>],
    observer: &(dyn Observer + 'static),
    provider_name: &str,
    model: &str,
    temperature: Option<f64>,
    silent: bool,
    channel_name: &str,
    channel_reply_target: Option<&str>,
    multimodal_config: &MultimodalConfig,
    max_tool_iterations: usize,
    approval: Option<&ApprovalManager>,
    excluded_tools: &[String],
    dedup_exempt_tools: &[String],
    activated_tools: Option<&Arc<Mutex<ActivatedToolSet>>>,
    model_switch_callback: Option<Arc<Mutex<Option<(String, String)>>>>,
    strict_tool_parsing: bool,
    parallel_tools: bool,
    max_tool_result_chars: usize,
    context_token_budget: usize,
    channel: Option<&dyn Channel>,
    origin: TurnOrigin,
    memory: Option<TurnMemory<'_>>,
    agent_alias: Option<&str>,
    turn_id: Option<&str>,
) -> Result<String, Error>
Expand description

Execute a single turn of the agent loop: send messages, parse tool calls, execute tools, and loop until the LLM produces a final text response. When silent is true, suppresses stdout (for channel use). agent_alias, when the caller has resolved one, is threaded onto the turn’s AgentStart/AgentEnd brackets and onto the inner ToolLoop, so every lifecycle observer event of the turn (agent_start, llm_request, llm_response, tool_call_start, tool_call, agent_end) carries the full (channel, agent_alias, turn_id) correlation triple that observer consumers (Prometheus, OTel, the gateway /api/events stream) rely on for per-agent attribution. None opts out for callers without a resolved alias (tests, benches). turn_id follows the same pattern: Some reuses a caller-minted id so pre-turn events (the process_message RAG retrieval) join the bracket; None self-mints.