Skip to main content
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:
  1. Read the incoming agent state from headers
  2. Enrich it with hop-specific variables and metadata
  3. Forward the updated state to the next hop
This creates a continuous context chain that enables downstream hops to make informed decisions and enables audit analytics across the full request graph.

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, the GATEWAY scope contains:

Orchestrator Plan Chain

Orchestrators can record their planned intent chain:

Agent Execution Reflection

Agents can reflect what actually occurred:
By keeping both plan and execution records in agent state, analytics can compute deviation metrics without inspecting raw prompts or payloads.

Safety Rules

  1. Derived only: Never store raw mandates, secrets, or configuration in agent state
  2. Version everything: Each payload has a version field for forward compatibility
  3. Opt-in: Higher-level SDKs require an explicit toggle before adding telemetry to agent state