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:
This means the middleware can enforce contextual governance: a compliance rule can evaluate not just the tool input/output, but also the agent’s stated objective, the orchestrator’s plan, and the full chain of prior hops. See the Agent Scoped Policies reference for how
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:Header Transport
Agent state is propagated across HTTP/MCP boundaries via three canonical headers: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