# 7.1 Harness: composing the patterns

A harness composes every agent pattern around the LLM into one environment it can operate in.

1. The LLM alone: no tools, no state, no environment.
2. Each agent pattern is one piece.
3. Composed around the LLM, they form the harness.
4. The harness is the environment: any task in, grounded result out.

- **Use when:** Any agent beyond a single call: choose the pieces the task needs.
- **Avoid:** Assembling every piece by default: each adds latency, tokens and failure modes.

```
harness = compose(
    llm,
    loop       = agent_loop(max_turns),
    workflows  = [chain, route, evaluate],
    tools      = [*native, *mcp],
    skills     = discover("skills/"),
    context    = [cache_prefix, compaction],
    memory     = [working, semantic, episodic],
    subagents  = orchestrator(workers),
    guardrails = [input, hitl, output],
)
result = harness.run(task)
```

## References

- [The anatomy of an agent harness](https://www.langchain.com/blog/the-anatomy-of-an-agent-harness) (LangChain)
- [Agent harness engineering](https://addyosmani.com/blog/agent-harness-engineering/) (Addy Osmani)
- [Unrolling the Codex agent loop](https://openai.com/index/unrolling-the-codex-agent-loop/) (OpenAI)
- [Building agents with the Claude Agent SDK](https://www.anthropic.com/engineering/building-agents-with-the-claude-agent-sdk) (Anthropic)
