An agent harness is a carefully crafted program built out of a few moving parts working in sync: a model, context (system instructions, tool descriptions, short-term conversation, and long-term memory), and the tools the model can call.
Over the past few months I built Symphony, an open-source agent harness in Python. This guide walks through those moving parts, how they fit together in Symphony, and the practical lessons from building it.
A large language model (LLM) is stateless: text goes in, text comes out. It cannot read a file, run a command, or recall yesterday's work unless an outer runtime executes those actions and feeds the results back into the next request.
That outer runtime is the harness—it shapes what enters context, executes tools, manages memory, enforces limits, and streams events to whatever interface you use.
Swapping the model takes one config string; designing the harness around it is where an agent's reliability is won or lost.
At first glance, an agent loop is just a 20-line while loop that relies on whatever the model sends back: call the model, run any requested tools, append the results, and repeat until the model stops asking for tools.
The harness is what completes that loop and makes it reliable enough to trust on a real task—something meant to save you twenty minutes or days of work instead of failing silently halfway through.
1 · task in
A task arrives. The harness sends the prompt and history to the model.
Production reliability lives in the edge cases around that loop:
completed, limit exceeded, cancelled, or error).Tools are the contract between the model and the environment. To the model, a tool is a name, a description, and a typed parameter schema. To the harness, a tool is a function guarded by validation and output caps.
1 · ask
The model names a tool and fills in its arguments.
Three design principles matter most for tool interfaces:
read_file tool should natively handle UTF-8 text (paged with line offsets), CSVs, images, and sampled video frames—otherwise you end up relying on the model's ability to call bash reliably and continuously just to inspect basic project files.The context window is the agent's working memory, and it degrades before it overflows. Before you type a prompt, the window already holds the system prompt, project instructions, tool schemas, and skill listings. Every file read and command output shrinks the remaining budget—and as token count grows, models lose recall precision on earlier details.
There are several ways to keep a long session inside that window: dropping stale tool calls outright, shrinking or stubbing old tool logs while keeping only the assistant and user turns, or summarizing older slices of the conversation. Each trades off detail for space.
What worked best in Symphony is a two-stage process that keeps the saved transcript intact while compacting only what the model sees:
cat of a huge log never burns thirty turns of budget.[compacted earlier context] checkpoint—falling back to a deterministic template summary if the model call fails.Short-term context ends when the session ends. Long-term memory gives an agent continuity across sessions—without forcing you to re-explain repository conventions, past fixes, or recurring workflows every time you start a new run.
In practice, long-term memory works best when you combine three mechanisms rather than relying on one giant file:
Before the first model call, the harness queries structured facts and searches scenario docs by task type.
Symphony combines file-backed topics with a rebuildable SQLite index and runs reflection in the background after runs finish. Because model-written memory can still go stale or overgeneralize a one-off preference, every recalled entry is labeled explicitly as untrusted reference data—hints to verify, never blind rules.
Large investigations fill a single context window quickly. Instead of letting one agent read forty files into its main history, the parent forks scoped subtasks onto isolated subagent branches—just like checking out feature branches in git, doing heavy work in isolation, and merging back only a short answer.
Isolating child context keeps the parent's window small and focused. In Symphony, children cannot spawn further children—one simple rule that prevents recursive fan-out and runaway token spend.
When not to fork: Subagents add startup latency, duplicate prompt overhead, and cannot see each other's intermediate edits. Skip subagents when two steps modify the same files or depend tightly on each other's discoveries.
The harness is the checkpoint between a model's tool call and your machine. Putting an approval policy directly in front of tool execution ensures every risky action is checked consistently, regardless of which UI triggered it.
1 · gate
Nothing runs until the approval policy sees the call.
Symphony uses a before_tool approval policy with ask and always_allow modes plus ordered deny and allow patterns (where deny always wins, even in unattended runs). Before matching any rule, the harness normalizes relative segments and resolves symlinks so path tricks cannot slip past a rule.
Protecting API keys and credentials from being read or leaked takes a layered approach:
0o600) or in the OS keychain—never inside the project tree where file search and read tools operate.Where user-space policies stop and OS locks begin: an approval policy is still user-space code—once you approve a shell command, that child process runs with your user permissions unless the kernel restricts it. Stronger setups enforce OS-level read and write locks directly on the process:
sandbox-exec) profiles lock a child process to explicit file-read* and file-write* paths and can disable outbound network sockets at the kernel level.seccomp, and namespaces (bubblewrap) restrict which directory file descriptors a process can read or modify and which syscalls it can invoke—so even a rogue shell command cannot read credentials outside the granted tree.Checked before each tool runs. Stops bad paths early, but an approved shell still runs as your user.
An agent harness should never print directly to stdout or assume a single screen. Symphony emits structured events for everything that happens—turns starting, text streaming, tool calls running, and token usage updating.
Today, Symphony ships three listeners on that same event stream: the terminal UI (TUI), editors such as Zed over the Agent Client Protocol (ACP), and a web interface. Because the harness knows nothing about layout, adding a new client—such as a mobile app—requires zero changes to the agent loop.
Look back at sections 1 through 7: the core mechanics—the run loop, budgets, compaction, memory, subagents, approval policy, and event streams—are not coding-specific. Only the tools, policies, and clients change.
Separating the generic harness from product logic turns a new agent into a thin layer of tools and prompts instead of a new codebase. Symphony's harness powers three distinct products:
the core
The loop, budgets, memory, and events stay the same.

Osmo ↗ · Voice workspace
Osmo is a voice-first assistant you run locally. You talk, Osmo answers immediately, and when a question needs deep work it delegates to a background agent while the conversation continues. The harness underneath is unchanged—the tools are voice, a notes canvas, and background runs instead of file patches.

Somnia ↗ · Shared agent memory
Somnia is shared memory for coding agents. Agents submit completed sessions, and scheduled dreaming passes consolidate them into durable memories and a resume checkpoint so the next agent starts with context. It extracts the memory cycle from Section 4 into a standalone service shared across agents.
Most of the real engineering in an agent harness happens after the first working loop—in latency, caching, edge cases, and deleting features you outgrow.
Providers cache prompts strictly in order: tools → system → messages. When a request matches a prior prefix up to a cache breakpoint, the model reuses saved key-value (KV) states instead of recomputing those tokens—cutting both input cost and time to first token. Change a single byte early (like editing system), and that layer plus everything after it misses the cache:
Turn 1 (cold start): tools, system, and turn 1 are computed fresh and saved as the initial prefix.
Agent harnesses are powerful and fun to build, but the real takeaway wasn't some new AI trick—it was core software engineering principles. Clear boundaries, append-only state, explicit failure modes, and decoupled event streams are what actually make a harness durable.
Those same fundamentals are what let one harness scale across completely different form factors—whether it runs in the cloud or as a local-first JSON-RPC agent—without turning every new product into a rewrite.
Symphony is up for developer preview—open source on GitHub (Python 3.11+ on macOS or Linux). Try it in your terminal or visit the Symphony site for demos and editor setup.