Files
blog/posts/pi-flow-native-brain.md
T

7.1 KiB

title, slug, date, description, og_description, og_image, excerpt, author, author_initials, author_role
title slug date description og_description og_image excerpt author author_initials author_role
Retiring the Supervisor: Pi's Flow-Native Brain pi-flow-native-brain 2026-06-03 We deleted 1,050 lines of hardcoded supervisor logic and replaced it with oracle-backed pi-flows. The verify_build oracle now powers a gate-based pipeline that agents compose dynamically. Pi's standalone supervisor is gone — replaced by a flow-native brain with oracle-backed gates. https://www.tinqs.com/img/og-cover.jpg We deleted 1,050 lines of hardcoded supervisor logic and replaced it with oracle-backed pi-flows. The verify_build oracle now powers a gate-based pipeline that agents compose dynamically. Ozan Bozkurt OB CTO & Developer, Tinqs

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:

  • Oracle-backed gates. The verify_build tool (.pi/extensions/tinqs-verify.ts) is the canonical gate. It compiles the game and sim, runs tests, and returns a structured PASS/FAIL verdict with file:line errors. Agents route through it; the gate decides whether to proceed.
  • Agent-loop-decision Reflexion. Instead of a fixed two-phase TDAID loop, agents self-reflect on build failures. The flow engine gives them the failure report; they decide whether to fix and retry or escalate.
  • Role-split agents. Build-verifier (G1), test-runner (G2), and vision-QA (G3) are separate sub-agents, each with their own toolset and context, composed by the flow.

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:

  • runner.ts (115 lines) — the main orchestration loop
  • supervisor.ts (119 lines) — the state machine driving sessions
  • gates.ts (75 lines) — hardcoded gate definitions
  • policy.ts (92 lines) — retry limits and decision logic
  • store.ts (54 lines) — session state persistence
  • types.ts (76 lines) — type definitions for the whole system
  • events.ts (47 lines) — inter-process event bus
  • Plus tests, examples, and documentation

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.