sec0-sdk/agent-state provides the primitives for propagating agent state across hops in the Sec0 runtime. It ensures state is predictable, header-safe, and supports opt-in analytics for intent-vs-execution deviation tracking.
Runtime Contextual Agent Governance
In a multi-hop agentic system, a single user request can traverse an orchestrator, multiple agents, tool servers, and external APIs. Each hop needs context about who initiated the request, what the objective is, and what happened at previous hops to make governance decisions. Sec0 solves this by encoding runtime context into a canonical agent state payload that flows with every call. At each hop, the agent state carries:| Context | Purpose | Governance Use |
|---|---|---|
nodeId | Identifies which agent/hop is executing | Resolves agent-scoped policy for this node |
runId | Links all hops in a single request graph | Correlates audit trail across distributed hops |
variables | Scoped key-value pairs per hop type | Compliance rules can inspect objective, plan, and execution state |
metadata | Arbitrary data attached by each hop | Enriches audit envelopes with model, temperature, etc. |
parentRef | Reference to the parent hop | Reconstructs the hop graph for deviation analysis |
nodeId drives per-agent policy selection, and the Instrumentation Config reference for how hops are configured.
How Agent State Works
As a request flows through an agentic runtime (agent, orchestrator, gateway, tool), each hop can:- Read the incoming agent state from headers
- Enrich it with hop-specific variables and metadata
- Forward the updated state to the next hop
State Structure
Variable Scopes
Each hop type writes to its own scope, preventing collisions:| Scope | Written By | Typical Contents |
|---|---|---|
AGENT | Agent hops | Objective, execution reflections, status |
ORCHESTRATOR | Orchestrator hops | Plan chain, workflow metadata |
GATEWAY | Gateway hops | AP2 analytics, risk telemetry |
SERVER | Server/middleware hops | Server-level signals, decision data |
TOOL | Tool hops | Tool-specific state |
Header Transport
Agent state is propagated across HTTP/MCP boundaries via three canonical headers:| Header | Content |
|---|---|
x-node-id | The node identifier |
x-agent-ref | The run/inference reference |
x-agent-state | Base64-encoded full state payload |
Encoding
Decoding
Merging Variables
Analytics Conventions
sec0-sdk/agent-state defines opt-in analytics payloads that higher-level components can include in agent state variables. These are never automatically enabled. Application authors must explicitly turn on the relevant telemetry flags.
Gateway Analytics
When analytics are enabled on the gateway, theGATEWAY scope contains:
Orchestrator Plan Chain
Orchestrators can record their planned intent chain:Agent Execution Reflection
Agents can reflect what actually occurred:Safety Rules
- Derived only: Never store raw mandates, secrets, or configuration in agent state
- Version everything: Each payload has a
versionfield for forward compatibility - Opt-in: Higher-level SDKs require an explicit toggle before adding telemetry to agent state