# AI Harness as Function Composition: Orchestrating Systems Around a Frozen M(x)
A first-principles abstraction of AI Harness as function composition: freeze the foundation map M(x), orchestrate the outer chain H. Single-turn is strict multi-layer composition; multi-turn fuses composition with a state machine. Optimize H, not weights by default.
Same base model, same task brief—swap the rule files, validators, and tool allowlists, and the outcome can look like two different systems. The instinctive fix is often “use a stronger model.” A stabler diagnosis: failure lives in the chain around the model.
This piece offers a decomposable abstraction: designing and running an AI Harness is multilayer composition and constraint wrapping around a frozen foundation function . Single-turn inference is close to classical composition; multi-turn agents add state iteration on top. The optimization target therefore shifts from “change the weights” to “change the outer .” It is the first-principles companion to Harness Engineering: that article builds the control system; this one says what it is as a map.
1. Foundation function : a frozen black-box operator
A mainstream Transformer LM can be treated mathematically as a high-dimensional, nested multilayer composite. Vaswani et al. describe encoders/decoders as stacks of identical layers, each built from attention and feed-forward sub-transforms. With weights fixed at inference, the forward pass is:
Here is the input representation and each a layer transform. is the Harness system’s core foundation operator: parameters stay put; what changes is how it is called and what wraps it.
Two properties explain why a Harness is needed—not only better prompts:
| Property | Meaning | System consequence |
|---|---|---|
| Opacity | Inner-layer transforms are not business-editable step by step | Controllability must be external: contracts, permissions, checks |
| Stochastic outputs | Sampling injects noise; format, bounds, and coherence are not hard guarantees | Deterministic post-processing and feedback loops must compensate |
Tighten the claim: frozen weights at inference do not make the whole pipeline a deterministic map. Temperature, top-, tool returns, and context drift all change effective outputs. A Harness’s job is to produce predictable system behavior around a stochastic core.
In one line: the model supplies possibility; the Harness supplies reliability—aligned with “Agent = Model + Harness” in Agentic Coding Agent core concepts.
2. Three first principles of composition
Classical compresses to three criteria—also the bottom constraints of Harness architecture:
- Layer dependence — Inner outputs feed outer inputs; order is not free, or the whole map changes.
- I/O closure — Each stage’s shape, format, and semantics must match the next contract.
- Composable extension — Simple operators nest into higher-order systems; a stage can be added, removed, or swapped without retraining .
In engineering terms:
| Criterion | Engineering meaning | Typical failure when broken |
|---|---|---|
| Layer dependence | Assemble → infer → parse → tool → re-validate; order is policy | “Polish before validate” beautifies broken JSON into something harder to fix |
| I/O closure | Schemas, MIME, auth boundaries, error shapes must be explicit | Hallucinated tool args, truncated JSON, type drift |
| Composable extension | Guides, Sensors, MCP tools are pluggable | Only a rewrite of one “god prompt” seems possible |
These do not claim a proven optimal Harness. They give a design language you can reason with: which layer to change, why, and how the map moves.
3. Single-turn: static multilayer composition
A Harness does not edit ’s parameters. It orchestrates an outer family . In the minimal stateless, one-shot case, the pipeline is ordinary multilayer composition:
Roles, coarsely (implementations often split further):
| Symbol | Role | Typical operations |
|---|---|---|
| Preprocess | Cleaning, context assembly, prompt/skill packing, format normalization | |
| Foundation | Semantic understanding and generation (black box) | |
| Post-parse | Decode, structure, JSON/Schema validate and repair | |
| Function & constraint | Tool dispatch, filtering, logic checks, permission gates, polish |
Mini example. User: “Turn last week’s failed payment alerts into a table.” injects field conventions and log sources; proposes a table and query intent; checks column names against a Schema; runs the query read-only; strips PII and returns. Break any contract (e.g. accepts illegal columns) and later stages amplify the error—order sensitivity made concrete.
Single-turn Harness thus embodies order sensitivity, nesting, and I/O closure: classical composition instantiated as an engineering system.
4. Multi-turn agents: stateful dynamic composition
A full agent system leaves the “stateless, finite, one-shot map” boundary: it stacks state-machine iteration, branches, retries, and memory updates on multilayer composition. Schematically:
is state at step : session memory, iteration count, tool traces, task progress, budgets (tokens / time / steps), and so on. Each composite pass updates state and feeds the next round.
Versus static composition:
| Static | Dynamic | |
|---|---|---|
| Map | Approximately fixed (given seed and input) | State-driven; same can yield different outcomes via |
| Stop | One forward pass ends | Needs explicit stop / budget / human escalation |
| Failure modes | One-shot contract breaks | Infinite loops, context bloat, repeated no-op actions |
This lines up with ReAct (interleaved reasoning traces and actions, observations written back): Thought / Act / Observation unfolds , and observations are deterministic writes into —not something the model should invent. Production turn caps, duplicate-action breakers, and verbatim tool-result injection are convergence and anti-divergence constraints on state iteration.
Multi-turn Harness is therefore not “longer composition” but composition × state machine: still discussable layer by layer, but stop and verify must be designed on their own.
5. Concept contrast: Guides, Sensors, ReAct, and Loop
Mid-weight contrast—not a survey. The point: familiar engineering terms land in one composition frame.
5.1 Where Guides / Sensors sit in
In Harness Engineering, Guides are feed-forward; Sensors are feedback.
| Control type | Place in the composition view | Note |
|---|---|---|
| Guides | Mostly and routing-related | Raise prior odds of first-try correctness: rules, skills, knowledge pointers |
| Computational Sensors | Deterministic (tests, lint, types, policy engines) | Judgable without re-sampling |
| Inferential Sensors | Sub-composites that call again (e.g. independent reviewer agents) | Semantic judgment; costlier; contracts still must close |
Mature systems need both: Guides alone, and the model may “know the rules without knowing compliance”; Sensors alone, and it burns tokens on the same walls. Composition language treats both as swappable outer function units, not scattered ops scripts.
5.2 ReAct as stateful unrolling
ReAct expands the action space to “environment actions ∪ linguistic reasoning,” so thoughts update context and acts produce observations. In our notation:
- One step “assemble → → parse tool calls → execute → write observation” ≈ one stateful
- Until
finishor budget exhaustion ≈ stop conditions
The payoff: when improving an agent, ask whether you are changing a layer , or the update / stop rules on —not only “add another system-prompt sentence.”
5.3 Loop Engineering: the cross-turn control plane
Loop Engineering asks a different question: which work deserves a closed loop, and what Trigger, Verifier, Budget, and Handoff contracts look like. Briefly:
- Harness / — within a turn or session, how is composed and constrained safely
- Loop — how cross-turn work units are hosted, verified, and escalated
Harness is the runtime mapping layer; Loop is the control plane above it. For Inner / Middle / Outer stratification see the three loops. The composition view helps ground Loop contracts’ Verifier, State, and Budget in concrete and fields—so “loop” is not only a slogan.
5.4 Boundary with “improve ” research
| Paradigm | Optimization target | Typical means | Cost shape |
|---|---|---|---|
| Model-centric | Parameters and alignment of | Pretrain, fine-tune, RLHF, etc. | Heavy data/compute; slow iteration |
| Harness-centric | and rules on | Add/replace outer units, tighten contracts, strengthen Sensors | Fast engineering iteration; local rollback |
Complementary, not exclusive. When base capability is “enough” and delivery bottlenecks are controllability and maintainability, changing is often the higher-leverage path. Böckeler’s Agent = Model + Harness, with a user-built outer harness as the main trust and toil surface, points the same way as “freeze , orchestrate the outside.”
6. Boundaries, anti-patterns, and discipline of claims
Formalism is a design language, not a finished optimality proof. Common anti-patterns:
| Anti-pattern | Problem in composition terms | Stabler move |
|---|---|---|
| Over-composition | Too many overlapping ; order cost exceeds gain | Fold what can be deterministic into computational Sensors; cut decorative layers |
| Broken contracts | Output shape fails the next input | Explicit Schema; failures as observations into retry, not silent swallow |
| Non-convergent loops | without budget, duplicate detection, or escalation | Turn caps, same-action breakers, HOTL escalation |
| Using for the already-decidable | Lint/type judgments left to sampling | Deterministic first; LLM for semantic trade-offs |
| Pretending determinism | Ignoring sampling and tool noise | Spec the randomness envelope and retry policy |
Three claim disciplines to avoid empty academic tone:
- Notation ≠ theorem — summarizes structure; semantics depend on the implementation.
- Frozen weights ≠ frozen behavior — fixed does not fix system outcomes.
- Every must be testable — a layer you cannot unit-test is often not a function unit but a liability.
7. Conclusions, open problems, and minimal actions
Conclusions
- Essence — Harness work is outer-composition orchestration, unit design, chain optimization, and iteration constraints around : higher-order packaging and controlled amplification of capability.
- Forms — Single-turn ≈ strict multilayer composition; multi-turn ≈ composition fused with a state machine—layered where useful, flexible where engineering requires.
- Optimization logic — Prefer improving reliability by adding, replacing, and tuning and rules—not defaulting to weight updates.
Open problems (research agenda)
- How to search or evolve optimal combinations of outer units under constraints?
- What convergence mechanisms for state iteration (when to stop; when to escalate to humans)?
- How to systematize functional constraints on uncertain outputs (Schema, types, policy, independent review) under cost–risk trade-offs?
Minimal action list
- Sketch your current : label , , parse, tools, permissions.
- For multi-turn paths, write fields and stop conditions; missing them is an anti-pattern by default.
- Route recurring failures back into some or Sensor—not only a one-off chat correction.
- Align with site practice: Guides / Sensors in Harness Engineering; cross-turn contracts in Loop Engineering.
Much research still optimizes . Harness opens another path: leave the foundation operator alone; reshape system outputs via higher-order composition rules. When capability is relatively saturated and delivery bars rise, Harness iteration grounded in composition is the main arena for cheaper robustness and interpretability—from empirical assembly toward decomposable, verifiable system optimization.
References
- Vaswani et al., Attention Is All You Need, NeurIPS 2017
- Birgitta Böckeler, Harness engineering for coding agent users, Martin Fowler, 2026
- Yao et al., ReAct: Synergizing Reasoning and Acting in Language Models, ICLR 2023
- On this site: Harness Engineering, Loop Engineering, Agentic Coding Agent core concepts, Inner / Middle / Outer Loop