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<()>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, soArcsuffices (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: ReceivesAgentTaskEvents — typically aChannelHandler.config: Loop config (max_steps, loop_abort_threshold).