Embed an Agent Host
Compose providers, scoped tools, durable tasks, workers, runs, and targeted refresh through supported public Rust APIs.
Context Harness can be embedded as the execution foundation for a local application without moving that application’s domain policy into the framework. The host owns its events, files, publication rules, and user experience. Context Harness owns the generic contracts for model/tool execution, durable tasks and runs, recovery, and retrieval refresh.
The boundary
Your application
events · domain state · files · publication · UI
│
▼
Context Harness public APIs
AgentHostBuilder · provider/tool catalogs
task worker · TargetedRefresher
│
▼
Canonical local state
SQLite documents · runs · tasks · events · checkpoints
Configuration never loads provider or tool code dynamically. A trusted compiled host registers implementations explicitly, supplies scoped authority, and then builds the runtime. Static resource validation remains inert: it does not resolve secrets, open run databases, contact providers, execute tools, evaluate Lua, start MCP clients, or spawn processes.
Public contracts
Build against the authoritative contracts rather than the historical design plans:
- Model Runtime defines provider registration, identity, capabilities, errors, and offline inspection.
- Local Agent Execution defines the bounded model/tool loop and policy boundary.
- Checkpoints, Recovery and Artifacts defines conservative recovery and durable evidence.
- Durable Agent Tasks defines submission, identity, claims, leases, workers, cancellation, and reconciliation.
- Targeted Document Refresh defines bounded refresh of host-known changed documents without connector discovery.
- Suspended Run Continuation defines explicit, same-run continuation after blocked or needs-input outcomes.
The integration fixture in crates/context-harness/tests/agent_host.rs is the
executable reference: it registers a compiled provider and scoped tool, submits and
runs a durable task, observes typed task/run outcomes, writes a host-owned document,
refreshes it, and verifies retrieval using public APIs only.
Operational handoff
- Start with Build Local Agents for resource, model, tool, permission, and validation concepts.
- Run workers in the foreground or under your own service manager using Operate a Durable Agent Task Worker.
- Establish host-specific baselines with Measure Agent Foundation Performance.
- Keep application job IDs correlated with Context Harness request keys, task IDs, and run IDs; do not duplicate the run lifecycle in application state.
Context Harness intentionally does not define hooks, wiki semantics, evidence rules, publication formats, or application lifecycle states. Those remain in the host.