[research@ai4se] : ~ $
cd ../
[tools] | | 18 min

# 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.

[harness-engineering][function-composition][agentic-systems]

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 M(x)M(x). 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 H\mathcal{H}.” 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 M(x)M(x): 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 NN identical layers, each built from attention and feed-forward sub-transforms. With weights θ\theta fixed at inference, the forward pass is:

M(x)=Fn ⁣(Fn1(F1(x;θ)))M(x) = F_n\!\big(F_{n-1}(\cdots F_1(x;\theta)\cdots)\big)

Here xx is the input representation and each FiF_i a layer transform. MM 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:

PropertyMeaningSystem consequence
OpacityInner-layer transforms are not business-editable step by stepControllability must be external: contracts, permissions, checks
Stochastic outputsSampling injects noise; format, bounds, and coherence are not hard guaranteesDeterministic 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-pp, 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 H(x)=f(g(x))H(x)=f(g(x)) compresses to three criteria—also the bottom constraints of Harness architecture:

  1. Layer dependence — Inner outputs feed outer inputs; order is not free, or the whole map changes.
  2. I/O closure — Each stage’s shape, format, and semantics must match the next contract.
  3. Composable extension — Simple operators nest into higher-order systems; a stage can be added, removed, or swapped without retraining MM.

In engineering terms:

CriterionEngineering meaningTypical failure when broken
Layer dependenceAssemble → infer → parse → tool → re-validate; order is policy“Polish before validate” beautifies broken JSON into something harder to fix
I/O closureSchemas, MIME, auth boundaries, error shapes must be explicitHallucinated tool args, truncated JSON, type drift
Composable extensionGuides, Sensors, MCP tools are pluggableOnly 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 Hsingle\mathcal{H}_{single}

A Harness does not edit MM’s parameters. It orchestrates an outer family H={h0,h1,,hk}\mathcal{H}=\{h_0,h_1,\ldots,h_k\}. In the minimal stateless, one-shot case, the pipeline is ordinary multilayer composition:

Hsingle(x)=hk ⁣(h2(h1(M(h0(x)))))\mathcal{H}_{single}(x) = h_k\!\big(\cdots h_2\big(h_1\big(M(h_0(x))\big)\big)\cdots\big)

Roles, coarsely (implementations often split further):

SymbolRoleTypical operations
h0h_0PreprocessCleaning, context assembly, prompt/skill packing, format normalization
MMFoundationSemantic understanding and generation (black box)
h1h_1Post-parseDecode, structure, JSON/Schema validate and repair
h2hkh_2\sim h_kFunction & constraintTool dispatch, filtering, logic checks, permission gates, polish

Mini example. User: “Turn last week’s failed payment alerts into a table.” h0h_0 injects field conventions and log sources; MM proposes a table and query intent; h1h_1 checks column names against a Schema; h2h_2 runs the query read-only; h3h_3 strips PII and returns. Break any contract (e.g. h1h_1 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 Hmulti\mathcal{H}_{multi}

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:

Hmulti(x,St)=Loop ⁣(Hsingle(x,St),  StSt+1)\mathcal{H}_{multi}(x, S_t) = \mathcal{Loop}\!\big(\mathcal{H}_{single}(x, S_t),\; S_t \to S_{t+1}\big)

StS_t is state at step tt: 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 Hsingle\mathcal{H}_{single}Dynamic Hmulti\mathcal{H}_{multi}
MapApproximately fixed (given seed and input)State-driven; same xx can yield different outcomes via StS_t
StopOne forward pass endsNeeds explicit stop / budget / human escalation
Failure modesOne-shot contract breaksInfinite loops, context bloat, repeated no-op actions

This lines up with ReAct (interleaved reasoning traces and actions, observations written back): Thought / Act / Observation unfolds Loop\mathcal{Loop}, and observations are deterministic writes into StS_t—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 hih_i

In Harness Engineering, Guides are feed-forward; Sensors are feedback.

Control typePlace in the composition viewNote
GuidesMostly h0h_0 and routing-related hih_iRaise prior odds of first-try correctness: rules, skills, knowledge pointers
Computational SensorsDeterministic hjh_j (tests, lint, types, policy engines)Judgable without re-sampling MM
Inferential SensorsSub-composites that call MM 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 → MM → parse tool calls → execute → write observation” ≈ one stateful Hsingle\mathcal{H}_{single}
  • Until finish or budget exhaustion ≈ Loop\mathcal{Loop} stop conditions

The payoff: when improving an agent, ask whether you are changing a layer hih_i, or the update / stop rules on StS_t—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 / H\mathcal{H} — within a turn or session, how MM 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 hih_i and StS_t fields—so “loop” is not only a slogan.

5.4 Boundary with “improve MM” research

ParadigmOptimization targetTypical meansCost shape
Model-centricParameters and alignment of MMPretrain, fine-tune, RLHF, etc.Heavy data/compute; slow iteration
Harness-centricH\mathcal{H} and rules on SSAdd/replace outer units, tighten contracts, strengthen SensorsFast engineering iteration; local rollback

Complementary, not exclusive. When base capability is “enough” and delivery bottlenecks are controllability and maintainability, changing H\mathcal{H} 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 MM, 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-patternProblem in composition termsStabler move
Over-compositionToo many overlapping hih_i; order cost exceeds gainFold what can be deterministic into computational Sensors; cut decorative layers
Broken contractsOutput shape fails the next inputExplicit Schema; failures as observations into retry, not silent swallow
Non-convergent loopsLoop\mathcal{Loop} without budget, duplicate detection, or escalationTurn caps, same-action breakers, HOTL escalation
Using MM for the already-decidableLint/type judgments left to samplingDeterministic first; LLM for semantic trade-offs
Pretending determinismIgnoring sampling and tool noiseSpec the randomness envelope and retry policy

Three claim disciplines to avoid empty academic tone:

  1. Notation ≠ theoremHmulti\mathcal{H}_{multi} summarizes structure; semantics depend on the implementation.
  2. Frozen weights ≠ frozen behavior — fixed θ\theta does not fix system outcomes.
  3. Every hih_i 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

  1. Essence — Harness work is outer-composition orchestration, unit design, chain optimization, and iteration constraints around MM: higher-order packaging and controlled amplification of capability.
  2. Forms — Single-turn ≈ strict multilayer composition; multi-turn ≈ composition fused with a state machine—layered where useful, flexible where engineering requires.
  3. Optimization logic — Prefer improving reliability by adding, replacing, and tuning hih_i and SS 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

  1. Sketch your current Hsingle\mathcal{H}_{single}: label h0h_0, MM, parse, tools, permissions.
  2. For multi-turn paths, write StS_t fields and stop conditions; missing them is an anti-pattern by default.
  3. Route recurring failures back into some hih_i or Sensor—not only a one-off chat correction.
  4. Align with site practice: Guides / Sensors in Harness Engineering; cross-turn contracts in Loop Engineering.

Much research still optimizes M(x)M(x). 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