Skip to main content

conversation_api/execution/
context.rs

1//! Invocation identity and tracing context.
2
3use serde::{Deserialize, Serialize};
4
5use crate::execution::{
6    ClientId, ConversationSurface, OperationId, RunId, ScopeId, TenantId, ThreadId, UserId,
7};
8
9/// Ownership boundary used for authorization and persistence partitioning.
10#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
11#[serde(deny_unknown_fields)]
12pub struct Scope {
13    /// Optional tenant for multi-tenant deployments.
14    pub tenant_id: Option<TenantId>,
15    /// Application scope that owns Agent state and application capabilities.
16    pub scope_id: ScopeId,
17}
18
19/// Authenticated actor that initiated an Agent run.
20#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
21#[serde(deny_unknown_fields)]
22pub struct Actor {
23    /// Authenticated user identity.
24    pub user_id: UserId,
25    /// Optional originating application client used for routed responses.
26    pub client_id: Option<ClientId>,
27}
28
29/// Context that follows one Agent invocation across all ports.
30#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
31#[serde(deny_unknown_fields)]
32pub struct InvocationContext {
33    /// Authorization and persistence scope.
34    pub scope: Scope,
35    /// Authenticated actor; never accepted from model-generated arguments.
36    pub actor: Actor,
37    /// Trusted, canonical conversation space. Runtime uses it only as thread identity.
38    pub surface_id: ConversationSurface,
39    /// Durable conversation thread.
40    pub thread_id: ThreadId,
41    /// Current run identifier.
42    pub run_id: RunId,
43    /// Idempotency identifier for the initiating operation.
44    pub operation_id: OperationId,
45    /// Optional absolute Unix deadline in milliseconds.
46    pub deadline_unix_ms: Option<u64>,
47    /// Optional W3C traceparent propagated by the deployment.
48    pub traceparent: Option<String>,
49}