pub struct SessionLoop { /* private fields */ }Expand description
Supervised session loop — one per active session.
Runs as a background tokio::spawned task. Receives user events via an
mpsc channel, processes each turn through the real Runner, and broadcasts
session events via a tokio::broadcast channel.
§Example
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::{broadcast, mpsc, Mutex, Notify};
use tokio_util::sync::CancellationToken;
use adk_managed::session_loop::SessionLoop;
use adk_managed::parking::ToolParkingLot;
let (event_tx, event_rx) = mpsc::channel(64);
let (broadcast_tx, _) = broadcast::channel(256);
let cancel = CancellationToken::new();
let parking = Arc::new(ToolParkingLot::new(Duration::from_secs(300)));
let loop_handle = SessionLoop::new(
"session_001".to_string(),
event_rx,
broadcast_tx,
parking,
cancel.clone(),
agent,
session_service,
);
let handle = tokio::spawn(loop_handle.run());
// Send events via event_tx...Implementations§
Source§impl SessionLoop
impl SessionLoop
Sourcepub fn new(
session_id: String,
event_rx: Receiver<UserEvent>,
event_tx: Sender<SessionEvent>,
parking: Arc<ToolParkingLot>,
cancel_token: CancellationToken,
agent: Arc<dyn Agent>,
session_service: Arc<dyn SessionService>,
) -> Self
pub fn new( session_id: String, event_rx: Receiver<UserEvent>, event_tx: Sender<SessionEvent>, parking: Arc<ToolParkingLot>, cancel_token: CancellationToken, agent: Arc<dyn Agent>, session_service: Arc<dyn SessionService>, ) -> Self
Create a new session loop.
§Arguments
session_id- The session this loop operates on.event_rx- Receiver for incoming user events.event_tx- Broadcast sender for outgoing session events.parking- Shared parking lot for custom tool calls.cancel_token- Token to signal interrupt/shutdown.agent- The built agent to drive through the Runner.session_service- Session persistence for the Runner.
Sourcepub fn with_pause_controls(
session_id: String,
event_rx: Receiver<UserEvent>,
event_tx: Sender<SessionEvent>,
parking: Arc<ToolParkingLot>,
cancel_token: CancellationToken,
pause_flag: Arc<Mutex<bool>>,
pause_notify: Arc<Notify>,
checkpoint: Arc<RwLock<CheckpointManager>>,
agent: Arc<dyn Agent>,
session_service: Arc<dyn SessionService>,
) -> Self
pub fn with_pause_controls( session_id: String, event_rx: Receiver<UserEvent>, event_tx: Sender<SessionEvent>, parking: Arc<ToolParkingLot>, cancel_token: CancellationToken, pause_flag: Arc<Mutex<bool>>, pause_notify: Arc<Notify>, checkpoint: Arc<RwLock<CheckpointManager>>, agent: Arc<dyn Agent>, session_service: Arc<dyn SessionService>, ) -> Self
Create a session loop with custom pause controls (for external pause/resume).
See the memory-enabled variant for full documentation.
Sourcepub fn pause_flag(&self) -> Arc<Mutex<bool>>
pub fn pause_flag(&self) -> Arc<Mutex<bool>>
Get a clone of the pause flag for external control.
Sourcepub fn pause_notify(&self) -> Arc<Notify>
pub fn pause_notify(&self) -> Arc<Notify>
Get a clone of the pause notify for external control.
Sourcepub async fn run(self) -> Result<(), RuntimeError>
pub async fn run(self) -> Result<(), RuntimeError>
Run the session loop (consumes self).
This is the main loop body, designed to be tokio::spawned. It runs
until the input channel is closed or the cancellation token is triggered.
§Returns
Returns Ok(()) on graceful shutdown, or Err(RuntimeError) if an
unrecoverable error occurs.