pub struct RunState {Show 13 fields
pub run_id: RunId,
pub session_id: Uuid,
pub status: RunStatus,
pub provider: ProviderId,
pub model: ModelName,
pub metadata: Value,
pub iteration: usize,
pub total_usage: TokenUsage,
pub last_finish: Option<FinishReason>,
pub last_error: Option<String>,
pub event_count: usize,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Projected state of a run, reconstructed from its event log.
Unlike RunRecord which is a static metadata snapshot,
RunState is a fully materialized view derived by folding every
recorded event via apply. This enables replay-based
state recovery and batch inspection of run progress without scanning
raw events.
Fields§
§run_id: RunIdRun identifier.
session_id: UuidSession this run belongs to.
status: RunStatusCurrent status.
provider: ProviderIdProvider used for model calls.
model: ModelNameModel used for generation.
metadata: ValueRun metadata.
iteration: usizeCurrent iteration (0 before first model call).
total_usage: TokenUsageAggregated token usage across all provider calls.
last_finish: Option<FinishReason>Finish reason from the last model response.
last_error: Option<String>Error message if the run failed.
event_count: usizeNumber of events folded into this state.
created_at: DateTime<Utc>When the run was created.
updated_at: DateTime<Utc>When the last event was recorded.
Implementations§
Source§impl RunState
impl RunState
Sourcepub fn create(record: &RunRecord, events: &[RunEventRecord]) -> Self
pub fn create(record: &RunRecord, events: &[RunEventRecord]) -> Self
Sourcepub fn apply(&mut self, event: &AgentEvent)
pub fn apply(&mut self, event: &AgentEvent)
Incrementally updates the projected state by applying a single event.
Handles all AgentEvent variants: RunStarted sets provider/model,
ModelStarted advances iteration, UsageRecorded accumulates tokens,
terminal events set the final status, while informational events
only update the timestamp.