pub struct RuntimeContext {
pub execution_id: ExecutionId,
pub step_id: Option<StepId>,
pub parent: ParentLink,
pub tenant: TenantContext,
pub trace: TraceContext,
pub session: Option<SessionContext>,
pub created_at: DateTime<Utc>,
pub spawn_mode: Option<SpawnMode>,
pub cancellation_policy: CancellationPolicy,
pub parent_execution_id: Option<ExecutionId>,
pub metadata: HashMap<String, Value>,
}Expand description
RuntimeContext - The context passed through all execution
Created per Execution, inherited by child executions (sub-agents) with appropriate field updates.
§Usage
let tenant = TenantContext::new(TenantId::from("tenant_acme"))
.with_user(UserId::from("usr_alice"));
let ctx = RuntimeContext::new(
ExecutionId::new(),
ParentLink::from_user_message("msg_123"),
tenant,
);
// For sub-agent invocation:
let child_ctx = ctx.child_context(ExecutionId::new(), &step_id);Fields§
§execution_id: ExecutionIdThe current execution ID
step_id: Option<StepId>Current step ID (if within a step)
parent: ParentLinkWhat triggered this execution
tenant: TenantContextTenant context for multi-tenant isolation
trace: TraceContextOpenTelemetry trace context
session: Option<SessionContext>Session context (for user-initiated flows)
created_at: DateTime<Utc>When this context was created
spawn_mode: Option<SpawnMode>How this context was spawned (for inbox routing decisions) @see docs/TECHNICAL/32-SPAWN-MODE.md
cancellation_policy: CancellationPolicyCancellation policy for child executions spawned from this context
parent_execution_id: Option<ExecutionId>Parent execution ID (for Child spawn mode inbox routing)
metadata: HashMap<String, Value>Extensible metadata
Implementations§
Source§impl RuntimeContext
impl RuntimeContext
Sourcepub fn new(
execution_id: ExecutionId,
parent: ParentLink,
tenant: TenantContext,
) -> Self
pub fn new( execution_id: ExecutionId, parent: ParentLink, tenant: TenantContext, ) -> Self
Create a new RuntimeContext for an execution
TenantContext is REQUIRED - this ensures every execution runs within a tenant boundary.
Sourcepub fn from_user_message(
execution_id: ExecutionId,
message_id: impl Into<String>,
tenant: TenantContext,
) -> Self
pub fn from_user_message( execution_id: ExecutionId, message_id: impl Into<String>, tenant: TenantContext, ) -> Self
Create a RuntimeContext for a user message trigger
Sourcepub fn with_trace(self, trace: TraceContext) -> Self
pub fn with_trace(self, trace: TraceContext) -> Self
Set trace context
Sourcepub fn with_session(self, session: SessionContext) -> Self
pub fn with_session(self, session: SessionContext) -> Self
Set session context
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add metadata
Sourcepub fn with_spawn_mode(self, spawn_mode: SpawnMode) -> Self
pub fn with_spawn_mode(self, spawn_mode: SpawnMode) -> Self
Set spawn mode
Sourcepub fn with_cancellation_policy(self, policy: CancellationPolicy) -> Self
pub fn with_cancellation_policy(self, policy: CancellationPolicy) -> Self
Set cancellation policy
Sourcepub fn child_context(
&self,
child_execution_id: ExecutionId,
parent_step_id: &StepId,
) -> Self
pub fn child_context( &self, child_execution_id: ExecutionId, parent_step_id: &StepId, ) -> Self
Create a child RuntimeContext for a sub-agent invocation
The child context:
- Gets a new execution ID
- Has parent pointing to the current step
- Inherits tenant context (with same user or overridden)
- Inherits trace context (new span ID)
Uses default SpawnMode::Child with no background and no inbox inheritance.
For custom SpawnMode, use child_context_with_spawn_mode.
Sourcepub fn child_context_with_spawn_mode(
&self,
child_execution_id: ExecutionId,
parent_step_id: &StepId,
spawn_mode: SpawnMode,
) -> Self
pub fn child_context_with_spawn_mode( &self, child_execution_id: ExecutionId, parent_step_id: &StepId, spawn_mode: SpawnMode, ) -> Self
Create a child RuntimeContext with explicit SpawnMode
@see docs/TECHNICAL/32-SPAWN-MODE.md
Sourcepub fn enter_step(&self, step_id: StepId) -> Self
pub fn enter_step(&self, step_id: StepId) -> Self
Enter a step (returns new context with step_id set)
Sourcepub fn execution_id(&self) -> &ExecutionId
pub fn execution_id(&self) -> &ExecutionId
Get the execution ID
Sourcepub fn tenant(&self) -> &TenantContext
pub fn tenant(&self) -> &TenantContext
Get the tenant context
Trait Implementations§
Source§impl Clone for RuntimeContext
impl Clone for RuntimeContext
Source§fn clone(&self) -> RuntimeContext
fn clone(&self) -> RuntimeContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more