Harness

Embed type-safe AI agent execution in your Python application with composable tools, CodeAct, subagents, and durable state.

Harness (a13n-harness) is the embeddable Python agent SDK at the core of Agent Foundation. You define instructions, a model, typed tools, and capabilities; Harness executes the reasoning and tool-calling loop in your Python process and returns validated output plus a serializable HarnessState for the next turn.

Start with the quickstart to run an offline Agent, continue a multi-turn Thread, stream incremental events, and connect a live model provider.

Core execution loop

Follow these four guides in order to build your first production-ready integration:

StepWhat you buildOutcome
1. QuickstartAn ExecutableAgent backed by a deterministic offline modelExecute two turns in the same Thread and stream live text events
2. Tools and dependenciesA typed Python function tool with per-Run AgentContext accessThe Agent invokes double(4) and uses injected request metadata
3. State and resumeJSON checkpoint persistence across process restartsReload HarnessState from disk and continue the same Thread ID
4. TestingDeterministic unit tests with FunctionModel and TestModelAssert tool calls, structured outputs, and policies without network calls

Build the ExecutableAgent once with HarnessBuilder, then call await executable.run(...) for a final result or async with executable.stream(...) for real-time events. Pass previous_state to continue the conversation. See Agents and Runs for the full execution lifecycle.

Three-lifetime architecture

Harness cleanly separates build-time definitions, per-run live authority, and portable conversation state so your application stays in control of multi-tenancy, credentials, and storage:

LifetimePrimary objectsWhat belongs here
Build time (reusable)AgentSpec, AgentDefinition, HarnessBuilderInstructions, output type or JSON Schema, Python function tools, static Capabilities, subagent definitions, and plugins
Run time (fresh per turn)RunBindings, invocation argumentsCurrent caller identity, live model resolver, authorized Environment mounts, MCP connections, and invocation approval policies
Continuation (portable JSON)HarnessStateStable thread_id, message history, versioned Capability state, and portable environment state

Your application owns credentials, access policy, and database storage. On every turn, load the saved HarnessState and pair it with freshly authorized RunBindings.

Add tools, context, and capabilities

Extend your Agent one capability at a time:

GoalGuide
Connect OpenAI, Anthropic, Gemini, Bedrock, Vertex, or custom gatewaysModels and Authentication and HTTP clients
Register Python functions and inject live application servicesTools and dependencies
Pause for human questions or sensitive tool approvalsHuman-in-the-loop and Managed tools
Execute tools in the caller's frontend or external workerClient tools
Validate Pydantic outputs or pass multimodal inputsInputs and outputs and Multimedia understanding
Give the Agent sandboxed file, shell, and desktop toolsEnvironments
Connect MCP servers and interactive MCP AppsMCP
Load on-demand SKILL.md workflowsSkills
Scale to hundreds of tools with native or grouped discoveryToolSearch
Delegate to child Agents or orchestrate tools with Python CodeActDelegation and CodeAct
Hold real-time bidirectional voice sessionsLive
Compose built-in or custom capabilitiesCapabilities

Manage long conversations and production operations

GoalGuide
Save, restore, fork, or recover interrupted tool callsState and resume
Compact long histories, filter context, and manage working notes/tasksContext
Share file or record memories across ThreadsMemory
Architect a multi-tenant Host around HarnessHosting and Plugins
Enforce token/request budgets and calculate costsUsage and limits
Export OpenTelemetry traces or stream AG-UI events to a browserObservation and Stream Protocol

If you want a ready-to-use interactive terminal and browser workbench built on Harness, see Harness UI. If you want a self-hosted multi-tenant platform with Console, RBAC, and background workers, see Service.

Complete runnable example projects

Explore full multi-file reference applications in the repository's examples/ directory:

ExampleWhat it demonstrates
Agent applicationOffline streaming turns, persisted checkpoints, and restart recovery
Environment ProvidersDirect Local, Local Envd, and Docker execution lifecycles
PluginsCustom Capabilities, Harness middleware plugins, and environment extensions
Installed ProviderPackaging and discovering an Environment Provider via Python entry points
MCP AppInteractive browser tool UI backed by a stdio MCP server

Versioning and specifications

These guides track the main branch and use the repository lockfile in quickstart examples. a13n-harness and a13n-stream-protocol always release together at the exact same version. Deep architectural contracts live in spec/a13n-harness/.

On this page