Games Technology About Blog Contact Press
← All Posts 3 June 2026

Retiring the Supervisor: Pi's Flow-Native Brain

The supervisor was 1,050 lines of TypeScript spread across 15 files — a hardcoded orchestration loop that ran contract-gated, verify-heavy sessions over isolated Pi processes. Today we deleted it. What replaced it is simpler, more flexible, and already passing real builds.

What the Supervisor Did

The .pi/supervisor/ directory was the orchestration brain Pi left to us. For every task, it ran a fixed loop:

1. Contract gate — skip-to-human if "done" wasn't programmatically verifiable

2. TDAID phase A — a test-writer agent writes RED tests, never implementation

3. TDAID phase B — a code-writer agent makes them green; on failure, a Reflexion follow-up retries (capped)

4. Verification gate — run the build, check tests, pass or fail with a report

It worked. It caught broken builds before they hit CI. It enforced the discipline of "define done before you start." But it had a structural problem: the loop was hardcoded. Every decision tree, every gate, every retry policy was baked into TypeScript. To change the workflow, you changed code. To add a new gate — vision QA, linting, asset validation — you added more code to the same monolithic loop.

The supervisor was doing what pi-flows was designed to do, but from the wrong side of the architecture. Flows composes agents, gates, and decision points into pipelines. The supervisor reimplemented that logic in a single file. It was fighting the framework.

What Replaced It

The verify-heavy brain now runs as a pi-flows flow — a pipeline of oracle-backed gates orchestrated by the flow engine, visualized in FlowDashboard, and composable by agents themselves.

The core pieces:

The result is a pipeline that flows naturally:

context → build → build-gate → (pass? → tests → tests-gate → vision)
                          ↘ (fail? → report)

Critically, the flow is not fixed. Agents can add gates, reorder steps, or branch on conditions. The flow engine handles orchestration; the agents handle decisions.

What We Deleted

The commit removes 1,050 lines across 15 files:

None of this was bad code. It was just the wrong layer. Flows gives us all of this — orchestration, state, gates, retry policy, event routing — as a framework primitive. We were maintaining a parallel implementation of something the framework already provided.

The durable asset we kept: verify_build, the build oracle. It's now reused as the gate tool that powers the flow pipeline.

The Bug That Took a Day to Find

Moving to flows exposed a subtle problem. Flow sub-agents run in their own extension stack — the main session's extensions don't reach them. The build-verifier and test-runner agents declared verify_build in their frontmatter, but the tool was never actually in their toolset.

The symptom was confusing: the agents would report "oracle not available" and route to fail/report, silently skipping the test gate entirely. The build would pass, tests would never run, and the pipeline would report success. A false green.

The fix was a single pattern: emit flow:register-tool with the full tool definition at extension activation, and re-announce on flow:rediscover. The flow engine collects these into getExtensionTools() and hands them to every sub-agent that declares the tool. Three lines of orchestration, a day of debugging.

Verified live: game-check now routes context → build → build-gate(pass) → tests → tests-gate(pass) → vision. Every gate fires. No false greens.

Why This Architecture Wins

Composability. Agents can add gates without touching framework code. Want a linting gate? Add a sub-agent with a linter tool. Want a security scan? Same pattern. The flow engine handles routing; you just declare the gate.

Reusability. The verify_build oracle that powered the old supervisor now powers the flow gates. Same tool, same interface, different orchestration. No rewrite needed.

Observability. FlowDashboard visualizes the entire pipeline. You can see which gates passed, which failed, and where the agent decided to retry. The old supervisor logged to stdout.

Self-modification. Agents can read the flow graph, understand where they are in the pipeline, and decide what to do next. The supervisor's decision tree was opaque to the agents it was supervising. Flows makes the pipeline itself part of the agent's context.

The Stack Today

| Layer | What | How |

|——-|——|—–|

| Flow engine | pi-flows orchestrator | Composes agents, gates, and decision points |

| Gates | verify_build oracle | Compiles, tests, returns PASS/FAIL with errors |

| Sub-agents | G1 (build), G2 (test), G3 (vision) | Role-split, each with its own toolset |

| Decision | Agent-loop Reflexion | Self-reflect on failures, retry or escalate |

| Visualization | FlowDashboard | Real-time pipeline state |


The old supervisor was 1,050 lines of code that did one thing well: verify that agent output compiled and passed tests. The new flow-native brain does the same thing with less code, more flexibility, and a bug we'll never hit again. Sometimes the best commit is a deletion.

The flow-native brain runs on our Pi fork inside Tinqs Studio. The verify_build extension is ~300 lines of TypeScript, MIT licensed, and reusable in any Pi project.