Skip to main content

AgentContext

Struct AgentContext 

Source
pub struct AgentContext {
    pub agent_id: AgentId,
    pub session_id: SessionId,
    pub pid: u32,
    pub started_at: Timestamp,
    pub metadata: BTreeMap<String, String>,
    pub governance_level: GovernanceLevel,
    pub parent_agent_id: Option<AgentId>,
    pub team_id: Option<String>,
    pub depth: u32,
    pub delegation_reason: Option<String>,
    pub spawned_by_tool: Option<String>,
    pub root_agent_id: Option<AgentId>,
}
Expand description

Identity carrier for an agent execution.

AgentContext flows through every governance event in the system. It captures the stable agent identity, per-session identity, process ID, start time, any additional runtime metadata, and optional topology/lineage fields that describe the agent’s position in a delegation hierarchy.

Requires the alloc feature.

Fields§

§agent_id: AgentId

Stable identifier for the agent (UUID v4 bytes).

§session_id: SessionId

Per-execution session identifier (UUID v4 bytes).

§pid: u32

OS process ID of the agent process.

§started_at: Timestamp

Nanoseconds since the Unix epoch when this context was created.

§metadata: BTreeMap<String, String>

Extensible key-value metadata attached to this execution context.

Keys are owned String so the map is serde-compatible and accepts both string-literal keys and computed keys at runtime.

§governance_level: GovernanceLevel

Governance level (L0–L3) carried for level-conditional policy rules.

Populated by the gateway from the agent’s AgentRecord (defined in aa-gateway) at the boundary between transport and the policy engine. Defaults to GovernanceLevel::L0Discover so old serialised contexts — and callers that have not yet been updated — deserialise or construct without churn.

§parent_agent_id: Option<AgentId>

The agent that spawned this one; None for root agents.

§team_id: Option<String>

Team this agent belongs to; None if no team is assigned.

§depth: u32

Delegation depth — 0 for root agents, incremented by 1 per delegation level.

§delegation_reason: Option<String>

Human-readable reason the parent delegated to this agent.

§spawned_by_tool: Option<String>

Tool or framework that triggered the spawn (e.g. "langgraph.subgraph").

§root_agent_id: Option<AgentId>

Root of the delegation chain — the top-level agent that ultimately spawned this one.

For root agents this equals Some(agent_id). For sub-agents it is set server-side to parent.root_agent_id.unwrap_or(parent.agent_id) so that any node in a delegation chain can resolve its root in O(1).

Implementations§

Source§

impl AgentContext

Source

pub fn now(agent_id: AgentId, session_id: SessionId, pid: u32) -> Self

Construct an AgentContext stamped at the current wall-clock time.

metadata is initialised empty; insert entries after construction.

Source

pub fn builder() -> AgentContextBuilder

Return a fresh AgentContextBuilder for topology-aware construction.

Trait Implementations§

Source§

impl Clone for AgentContext

Source§

fn clone(&self) -> AgentContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for AgentContext

Source§

fn eq(&self, other: &AgentContext) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for AgentContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.