Expand description
Supervised session loop for the managed agent runtime.
The SessionLoop is the core execution engine. It runs as a
tokio::spawned background task, dequeues UserEvents from an
mpsc channel, processes each turn, and broadcasts SessionEvents
to stream subscribers.
§Architecture
The loop composes:
SequenceCounter— assigns monotonically increasingseqto each eventToolParkingLot— parks oncustom_tool_useuntil client delivers a resultCheckpointManager— atomic checkpoint after each eventtokio::broadcast— fan-out to stream subscribersRunner— drives the agent through the real LLMSessionUsageTracker— tracks per-turn and cumulative token usage
§Control Flow
Dequeue UserEvent → emit status.running → invoke Runner
→ for each output event: classify, map, assign seq, checkpoint, broadcast
→ if custom tool call: park, wait for result, resume
→ track usage → emit status.idle → loop§Interrupt and Pause
- Interrupt: A
CancellationTokensignals the loop to stop at the next boundary. On interrupt, the loop emitsstatus.idleand exits. - Pause/Resume: A pause flag +
Notifyallow the loop to park until resumed.
Structs§
- Session
Loop - Supervised session loop — one per active session.