@hexr_agent is the core decorator in the Hexr SDK. Apply it to any function or class and the runtime assigns a cryptographic SPIFFE identity to that process, initializes OpenTelemetry instrumentation, scopes cloud credential access via OPA policies, and optionally starts an A2A bridge so other agents can discover and invoke yours. Everything else in the SDK — hexr_tool, hexr.vault, hexr.sandbox — depends on this identity being present.
Signature
Parameters
The agent’s name. Used in SPIFFE ID generation, Kubernetes resource naming, and observability spans.Must be kebab-case:
research-analyst, content-crew, data-pipeline.The tenant (organization) this agent belongs to. Maps to a Kubernetes namespace:
tenant-{tenant}.Cloud resources this agent needs access to. OPA uses this list to scope which credential exchanges are permitted.Examples:
["aws_s3", "gcp_bigquery", "azure_storage"]Fine-grained access: ["aws_s3:read"]Enable subprocess role management. When
True, child processes can declare different roles and receive distinct SPIFFE identities within the same pod.Multi-region credential configuration. Specifies which region to use per cloud provider.Example:
{"aws": "us-west-2", "gcp": "us-central1"}Enable Agent-to-Agent communication. Starts an HTTP server on port
8080 that receives JSON-RPC messages from the A2A sidecar. Serves an Agent Card at /.well-known/agent.json.A2A skill declarations for the Agent Card. Each skill requires
id, name, and description fields.Human-readable description for the Agent Card. Visible to other agents during A2A discovery.
Agent version string. Included in the Agent Card and all OTel spans.
Basic usage
Function decorator
Class decorator
What @hexr_agent does
When you decorate a function or class, the following happens at startup:
Sets agent context
Calls
HexrContext.set_agent_context() which sets ContextVars (tenant, agent_name, framework, resources), writes a process context marker file to /tmp/hexr-context/, and registers the process with the Auto-Registrar.Initializes OpenTelemetry
Creates a
TracerProvider and MeterProvider pointing at the OTel Collector. All subsequent SDK calls emit spans and metrics automatically.Starts A2A bridge (if a2a=True)
Starts an HTTP server on port
8080 that receives /execute calls from the A2A sidecar, calls your function with the message content, and returns the result as a Task artifact.Framework detection
hexr build uses AST analysis to auto-detect your agent framework. The result is stored in the HEXR_FRAMEWORK environment variable and included in all OTel spans:
| Framework | Detection pattern |
|---|---|
| CrewAI | from crewai import Agent, Crew |
| LangChain | from langchain import ..., from langchain_core import ... |
| AutoGen | from autogen import ..., AssistantAgent, UserProxyAgent |
| Strands Agents | from strands import Agent, @tool decorator |
| OpenAI Swarm | from swarm import Swarm |
| Pure Python | No framework detected — uses @hexr_agent directly |
A2A agent card
Whena2a=True, your agent is discoverable by other agents via the A2A protocol. The card is served at GET /.well-known/agent.json:
Examples
Multi-cloud agent
CrewAI with A2A
Subprocess support
Whensubprocess_support=True, child processes each receive distinct SPIFFE identities scoped to their role within the parent agent: