Skip to main content

spawn_agent_loop

Function spawn_agent_loop 

Source
pub fn spawn_agent_loop<A, H>(
    agent: Arc<A>,
    session: Arc<Mutex<Session<A::Msg>>>,
    pending_notes: Arc<Mutex<Vec<String>>>,
    handler: H,
    config: LoopConfig,
) -> JoinHandle<()>
where A: TuiAgent + Send + Sync + 'static, H: AgentEventHandler,
Expand description

Run the agent loop as a tokio task with TUI event integration.

Key design: session is unlocked during LLM streaming (so TUI can read messages for display) and locked during action execution (which modifies session).

§Arguments

  • agent: Shared agent ref. Takes &self, so Arc suffices (no Mutex). Use interior mutability (Mutex) inside agent for stateful tools (MCP, etc).
  • session: Shared session behind Mutex. TUI can lock to read messages.
  • pending_notes: Queue of user messages injected between steps.
  • handler: Receives AgentTaskEvents — typically a ChannelHandler.
  • config: Loop config (max_steps, loop_abort_threshold).