From Pi Agents to a Controlled Host
Locate each required host decision before choosing an integration seam; record unsupported seams.
This chapter starts where Book I stops and asks what a host around Pi must
decide for itself. Pi supplies the agent loop; the host supplies the
conditions under which that loop is allowed to run, the record of what it
did, and the independent check of whether it worked. Pi API names below
come from research track R02’s source inspection of the installed Pi 1.6.0
artifact (docs/research/HARNESS-RESEARCH-01/R02-PI.md). They are
DOCUMENTED/OBSERVED source inspection for that artifact, but TEST NOT RUN
by this book. That is not a tested Pi API contract.
Evidence status. Draft manuscript. HARNESS-RESEARCH-01 returned a CONDITIONAL GO for the offline Project 01 foundation only. That is not full-book Gate A acceptance. The five host decisions below (§2.3) are each executed as deterministic mechanisms: admission and settlement checks (Project 01 lab, REJECTED candidate scope), budgets (D17), durable state (D09), plans and typed gates (D14), and completion and settlement (D15, D01-WALKTHROUGH). Pi seam facts remain DOCUMENTED/OBSERVED source inspection, TEST NOT RUN. EXPERIMENT PENDING for live-model seam behaviour and the formal comparisons.
2.1 Prerequisites from Book I — referred back, not retaught
Book I (Pi Agents: Building on the Coding Agent) establishes the primitives this book builds on: the agent loop, tools, extensions, sessions, context admission, compaction, recovery, lifecycle seams, and stochastic testing. This book assumes a reader familiar with that material and does not repeat its tutorials. Two Book I foundations matter most here:
- Pi is already a minimal harness: it reasons, invokes tools, streams events, and persists its own conversation state. We extend capabilities around that loop at the application and execution layers; we do not convert an ordinary model into an agent from scratch.
- In-process extensions inherit the process’s OS authority. Book I’s authority/isolation treatment is prerequisite reading for Chapters 11–12 of this book: an extension allowlist is a configuration choice, not a security sandbox.
Where Book I pins Pi 1.0.4 for its examples, note the scope: that pin
belongs to Book I. R02 audited the installed Pi 1.6.0 distribution
(@earendil-works/pi-coding-agent 1.6.0; R02 inspection date 22 November
2026; SDK-declaration SHA-256
2CB83C8604497198EDA83BA4691D9C001C971C6B358AF05F42355AFC7666C669).
The R02 source inventory records package/lockfile identity and retrieval
provenance; an installed-artifact hash is not a publisher attestation.
The reviewed candidate pin for this book is exact 1.6.0, with its
dependency lock recorded at implementation. Drift matters in both
directions. agent_settled, context edits, agent_before_settle and broad
usage aggregation already exist in 1.0.4, so calling them new 1.6
capabilities would be wrong. The real differences include the aborted
field on settlement, +name / -name tool modifiers, changed find
pattern behaviour, idle cache-warming changes and provider-reported-cost
provenance (R02-PI.md, drift section). No complete compatibility test has
run.
2.2 What the Pi runtime provides — and what it cannot settle
R02 source inspection reports code consistent with the blueprint’s broad
picture for the inspected 1.6.0 artifact: a minimalist agent loop with a TypeScript SDK, an event stream,
custom tools and extensions, session management, and a settlement signal
distinct from loop termination (CLAIM-LEDGER.md H01-C01; DOCUMENTED/OBSERVED,
not executed). What matters for a host is the detail, and the limits:
| Seam | R02 finding (inspected 1.6.0; TEST NOT RUN) | Why it matters |
|---|---|---|
| Session creation | createAgentSession accepts explicit runtime/model, settings, resources, manager and tool selection. Default construction uses ambient services (C01) |
A controlled run must construct every service explicitly |
| Event stream | Extensions receive events before public listeners. Public callbacks are synchronous and not awaited. Completed-message persistence follows public message_end (C09) |
The ledger must enqueue copies without throwing, and read canonical state only after settlement and idle |
| Loop completion vs settlement | agent_end is low-level completion; retry, compaction or queued work may follow. agent_settled adds aborted (C08) |
Neither means task success. Equating them is the trace-equals-outcome failure (Chapter 4) |
| Tools | tools is a name/pattern allowlist, and a list of only +name / -name modifies the defaults (C02). The normal read tool resolves paths against cwd without a fixture-root guard (C04) |
“Read-only” is effect selection, not isolation. Project 01 uses data-only custom tools instead |
| Resources | Discovery-suppression flags default false. Reload still resolves packages before filtering (C05/C06) | Suppression flags alone do not prove no ambient discovery. Use an explicit inert loader |
| Defaults | Compaction and retry on, retry maximum three, cache warming idle (C13) |
Each can confound a measured run, so pin and assert them |
| Usage, cancellation | Session stats aggregate everything and are not an invoice (C10). abort() awaits idle; dispose() returns void (C11) |
No hard spend cap or bounded-termination guarantee comes from the SDK alone |
| Context projection | Compaction/branch selection project context without erasing raw history (R02 C07); TEST NOT RUN | A hidden selection policy: off in every arm unless it is the treatment (Chapters 7–8) |
Every seam is classified on four axes — observation (can the host see it?), control (can the host steer it?), authority (can the host’s decision bind effects?), and isolation (does a boundary outside the process enforce it?). A seam that offers observation without isolation is useful for measurement and useless for safety; confusing the two is the central error Chapters 11–12 exist to prevent.
Unsupported seams must be recorded explicitly. R02 lists several that the
adapter alone does not supply: transactional effects, exactly-once tools,
guaranteed invoice completeness, hard cancellation latency, a durable event
sink, root confinement, a task-success verdict, and a hard token or spend
cap (R02-PI.md, output contract). Any chapter that needs one of these
must say so, and the host design must route around the gap. It must never
silently assume the seam exists.
2.3 The decisions the host must own
Whatever the pinned SDK offers, five decisions cannot live inside the runtime without creating a second, ungoverned authority:
- Admission. Which task, which frozen fixture snapshot, which model configuration, which capability names, which budget, which approval policy, which acceptance oracle. Admission happens before the loop starts and is recorded in a manifest with digests. Rationale: the loop cannot impartially define the test it is about to take.
- Budgets. Token, spend, wall-clock, and human-review-minute limits, with enforcement points (warn, pause for approval, cancel) distinct from the model’s own stopping behavior. Rationale: stochastic loops do not self-limit against an adversary or a runaway plan; Chapters 17–18 make budgets part of every comparison.
- Durable task state. A journal of intentions, authorizations, checkpoints, and acknowledgments that survives process death — separate from Pi’s conversation persistence. Rationale: conversation history answers “what was said,” not “which effects settled”; Chapters 9–10 define that contract and its reconciliation rules.
- Plans and workflows. Typed states, bounded retries, and explicit human gates for multi-step work (Project 06). Rationale: free-form looping has no place to say “reproduction failed, stop and report”; Chapters 13–14 supply the states without rebuilding the loop.
- Completion and settlement. The host declares a run complete only after the oracle and settlement checks pass — artifacts verified, effects reconciled, unresolved intentions listed. Rationale: loop termination is an observation about reasoning; settlement is a judgment about the world.
2.4 Four boundaries that are not the same boundary
New harness builders collapse four distinct mechanisms into one. Keep them separate from the start:
- Observation sees events (tracing, telemetry). It improves diagnosis and changes nothing about what can happen.
- Control steers the loop (budgets, pauses, plan states, retries). It changes what the agent attempts next.
- Authority binds effects (approval tokens scoped to task, tool, args digest, and expiry; recorded before execution). It changes what the world permits.
- Isolation enforces authority outside the agent process (OS/container sandbox, broker deny-by-default). It survives a compromised or mistaken loop.
Three consequences follow, each stated here as a constraint and then demonstrated where the mechanism exists (the isolation half remains pending, Chapter 12):
- No automatic authority flows from prompts, skills, agent decisions, or same-process extensions. A tool allowlist names proposal routes; the gate decides execution, and only the broker would execute. (Executed at rung 2 by D11-AUTH-01 and D12-BROKER-01 decision logic, including cross-process principal authentication; to be qualified at Gate C with malicious-path and unsafe-command tests, including a Windows record.) Chapter 11 develops this into the capability / permission / authority / isolation distinction and an enforcement ladder.
- File identity is digest-bound and tested against symlinks/junctions,
casing, normalization, concurrency, and out-of-root writes — on Windows,
not only on POSIX assumptions. (Executed for the decision layer by
D12-BROKER-01, including a junction swap refused with its canary
intact; R04 establishes that lexical path checks alone do not give
containment,
CLAIM-LEDGER.mdH01-C11. No broker deployment or attack corpus has passed qualification.) - Raw Pi events are preserved separately from normalized harness traces, which are preserved separately from evaluations. Each transformation is versioned and re-runnable; the evaluator never edits its inputs. (Executed: the Project 01 lab’s recorder and replay, the D09 journal with exact-prefix replay, and the D15 evaluation records; PROPOSED as a book convention the candidate has not passed acceptance with.)
2.5 Host sketch — which portion belongs where, executed
Separation of concerns, not a validated Pi API. This sketch shows the intended host/adapter/broker division using the blueprint’s shapes. The control flow below runs as D01-WALKTHROUGH (one pass, composed deterministic mechanisms); the Pi loop and the isolated broker remain the unexecuted seams, stated as such.
// Executed shape in test/harness-walkthrough.test.ts (D01-WALKTHROUGH);
// broker.execute stands for the isolated effect, demonstrated separately
// at rung 2 (D11-AUTH-01, D12-BROKER-01) and pending at Gate C.
async function runTask(host: Host, task: IllustrativeTask) {
const manifest = host.admit(task); // freeze fixture, oracle, budget
const session = host.attachRuntime(manifest); // OBSERVATION seam (R02 C01/C09)
for await (const proposal of session.proposals()) {
const intent = host.recordIntent(manifest, proposal); // durable first
const grant = await host.policy.check(intent); // AUTHORITY decision
if (!grant.allowed) { host.ledger.deny(intent, grant); continue; }
const receipt = await host.broker.execute(intent, grant); // ISOLATED effect
host.ledger.settle(intent, receipt); // reconcile, don't assume
if (host.budgets.exhausted(manifest)) break;
}
return host.evaluator.judge(manifest); // independent, post hoc
}
Read the sketch as an allocation of blame: if an effect executes without
a recorded intent, admission failed. If it executes without a grant, the
broker failed. If the run reports success without the judge, settlement
failed. Each host.* call above is a chapter-sized obligation, and each
one ships with a failure-injection test before this book claims it works —
the executed ones are named in §§2.3–2.4; the Pi seam and the isolated
broker are the named gaps.
2.6 What remains unverified
- Tested behaviour of the R02 seams in the pinned artifact. Source inspection is not a passing test. The Project 01 implementation exercises several of them but has not been accepted (Chapter 4).
- Agent Framework source, version and license (R01, incomplete). The compact-host decision stands for Project 01: reuse invariants, not another runtime or ACP service.
- Whether anything from the existing ECK is needed before Project 10; current stance is nothing before then (R06).
- Windows isolation behaviour and approval-token semantics (R04, blocking for any effect claim past Project 01’s read-only fixture; broker decisions and object identity executed in-process in D12).
EXPERIMENT PENDING. This chapter establishes no tested Pi API contract and reports no measured live result. The seam findings are source inspection of the candidate 1.6.0 artifact. The Project 01 adapter is an unaccepted implementation candidate. The host-side mechanisms (admission, budgets, state, gates, settlement) are executed as deterministic demonstrations named in §§2.3–2.5.