pub struct AgentRunner {
pub event_sender: Sender<AgentEvent>,
pub cancel_token: CancellationToken,
pub status: AgentStatus,
pub started_at: DateTime<Utc>,
pub completed_at: Option<DateTime<Utc>>,
pub last_budget_event: Option<AgentEvent>,
pub last_critical_events: Vec<AgentEvent>,
pub last_tool_name: Option<String>,
pub last_tool_phase: Option<String>,
pub last_event_at: Option<DateTime<Utc>>,
pub round_count: u32,
pub run_id: String,
}Expand description
Runner that manages agent execution for a session.
Each active agent run has an associated AgentRunner that coordinates
event broadcasting, cancellation, and status tracking.
§Event Broadcasting
Uses a broadcast channel to support multiple subscribers watching the same agent run simultaneously.
§Cancellation
Provides a cancellation token that can be used to gracefully stop an in-progress agent execution.
Fields§
§event_sender: Sender<AgentEvent>Broadcast sender for agent events.
Allows multiple clients to subscribe to agent events
via event_sender.subscribe().
cancel_token: CancellationTokenCancellation token for graceful shutdown.
When triggered, the agent should stop execution at the next safe point.
status: AgentStatusCurrent status of the agent run.
started_at: DateTime<Utc>Timestamp when the run was started.
completed_at: Option<DateTime<Utc>>Timestamp when the run completed (if finished).
last_budget_event: Option<AgentEvent>Last token budget event to replay for new subscribers.
When a new client subscribes to an ongoing run, this allows them to receive the most recent token usage info.
last_critical_events: Vec<AgentEvent>Small ring of critical state events (TaskListUpdated, SubSession*, etc.) cached for replay to late/reconnecting subscribers.
Bounded to [CRITICAL_EVENTS_CAPACITY] entries; oldest are evicted.
last_tool_name: Option<String>Name of the most recently executed tool (if any). Updated live during execution for diagnostic visibility.
last_tool_phase: Option<String>Phase of the most recently executed tool: “begin”, “finished”, or “error”. Updated live during execution for diagnostic visibility.
last_event_at: Option<DateTime<Utc>>Timestamp of the last event received during this run. Updated live during execution for liveness checks.
round_count: u32Number of completed rounds (turns) so far. Updated live during execution for progress tracking.
run_id: StringUnique identifier for this execution run.
Generated fresh for every try_reserve_runner call so that
frontend SSE events can be matched to the correct run even
across reconnects.
Implementations§
Source§impl AgentRunner
impl AgentRunner
Sourcepub const EVENT_CHANNEL_CAPACITY: usize = 1000
pub const EVENT_CHANNEL_CAPACITY: usize = 1000
Broadcast channel capacity for agent events.
Sourcepub const CRITICAL_EVENTS_CAPACITY: usize = 32
pub const CRITICAL_EVENTS_CAPACITY: usize = 32
Maximum number of critical events cached for late-subscriber replay.
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new agent runner with default settings.
Initializes a broadcast channel, a fresh cancellation token,
and Pending status.
Sourcepub fn push_critical_event(&mut self, event: AgentEvent)
pub fn push_critical_event(&mut self, event: AgentEvent)
Push a critical event into the bounded replay cache.
If the cache is full, the oldest entry is evicted.
Trait Implementations§
Source§impl Clone for AgentRunner
impl Clone for AgentRunner
Source§fn clone(&self) -> AgentRunner
fn clone(&self) -> AgentRunner
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more