
Most developers assume that running a multi-agent coding setup requires mixing multiple AI models: an expensive frontier model for architecture, a mid-tier model for coding, and a separate fast model for review. In practice, juggling multiple model providers often introduces rate limit bottlenecks, fragmented context handling, and high API costs.
Worse, running an entire project in a single, monolithic chat session leads to the snowball effect: by turn 25, your agent carries 120,000 tokens of accumulated terminal outputs, compiler errors, and raw file dumps. The model slows down, burns tokens on every simple question, and starts forgetting its original engineering rules.
You can solve this without paying for multiple models. By combining a single fast, high-reasoning model (such as Gemini 3.8 Flash) with isolated subagent context windows and aggressive token filters, you get a fully autonomous software engineering loop that cuts token consumption by 60% to 75%.
Here is how the architecture works and how to set it up on your own machine.
1. The Core Idea: Context Boundaries Over Model Diversity
The primary advantage of multi-agent systems is not model diversity. It is context isolation.
When an AI agent spends twenty turns debugging a database migration, its context window fills up with migration error logs and stack traces. If you then ask that same session to build a clean frontend component, it must process all those past database logs on every prompt.
Monolithic Session (Token Accumulation):
Turn 1 [Plan] -> 5k tokens
Turn 10 [Backend] -> 45k tokens
Turn 20 [Frontend] -> 95k tokens (carries dead backend logs)
Turn 30 [Audit] -> 150k+ tokens (high latency, rule drift)
Phased Orchestra (Isolated Contexts):
Lead Orchestrator -> 15k tokens total (persists only milestones & tasks)
├── Subagent: architect -> 20k tokens (disposed on completion)
├── Subagent: builder (BE) -> 80k tokens (disposed on completion)
├── Subagent: builder (FE) -> 80k tokens (fresh context, disposed on completion)
└── Subagent: security-auditor -> 40k tokens (fresh context, disposed on completion)
Each subagent runs in its own process with a clean context window. When a subagent finishes its phase, its massive intermediate tool outputs are discarded, and only a concise summary is returned to the Lead Orchestrator. The model stays sharp, hallucination drops, and API costs plunge.
2. The Multi-Layer Efficiency Stack
To maximize speed and minimize token waste, this setup layers three distinct optimization tools:
┌─────────────────────────────────────────────────────────────┐
│ User Natural Prompt │
└──────────────────────────────┬──────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ Lead Orchestrator (Main Session) │
│ Maintains project roadmap in Obsidian Second Brain │
└──────────────┬──────────────────────────────┬───────────────┘
│ │
▼ ▼
┌──────────────────────────────┐┌─────────────────────────────┐
│ Subagents (Task Tool) ││ Fast File Finder (FFF) │
│ - architect ││ Rust-based MCP server │
│ - builder ││ Frecency-ranked AST grep │
│ - security-auditor ││ Auto-expands definitions │
│ - code-reviewer │└─────────────────────────────┘
└──────────────┬───────────────┘
▼
┌──────────────────────────────┐
│ Rust Token Killer (RTK) │
│ Intercepts bash execution │
│ Cuts command stdout by 70% │
└──────────────────────────────┘
- Rust Token Killer (
rtk): A shell proxy extension that intercepts commands likegit status,cargo test, andls, filtering verbose boilerplates before they reach the model. - Fast File Finder (
fff-mcp): A Rust MCP server that indexes codebases by frecency and git status, auto-expanding function definitions so the agent does not need to read full files. - Compaction Guardrail: An active compaction threshold at 140,000 tokens (collapsing back to 35,000 tokens), preventing unexpected runaways.
- Single Source of Truth (SSOT): An Obsidian Second Brain project folder (
projects/<slug>/docs/) storingprd.md,architecture.md,rules.md, andtasks.md.
3. Step-by-Step Setup Guide
Step 1 Configure OMP Model Roles
Map all agent roles to Gemini 3.8 Flash, enable inline graphics, and set up your compaction ceiling.
Open or create ~/.omp/agent/config.yml:
modelRoles:
default: google-antigravity/gemini-3.8-flash:high
smol: google-antigravity/gemini-3.8-flash:low
advisor: google-antigravity/gemini-3.8-flash:high
task: google-antigravity/gemini-3.8-flash:high
reviewer: google-antigravity/gemini-3.8-flash:high
plan: google-antigravity/gemini-3.8-flash:high
compaction:
enabled: true
thresholdTokens: 140000
keepRecentTokens: 35000
midTurnEnabled: false
asyncEnabled: true
methodOrder:
- remote
- handoff
- soft
- shake
- snapcompact
terminal:
showProgress: false
showImages: true
prewalk:
enabled: false
Note on Prewalk: Prewalk is a feature in OMP designed to hand off work from an expensive model to a cheaper model once planning ends. Because you are using Gemini 3.8 Flash across the board, keep prewalk.enabled: false.
Step 2 Establish the Global Autonomous Protocol
This file injects global rules into your agent's primary prompt. It instructs the Lead Agent to automatically dispatch subagents without waiting for manual user commands.
Create ~/.omp/agent/APPEND_SYSTEM.md:
# Autonomous Second Brain & Multi-Agent Orchestration Protocol
You are the Lead Engineer and Autonomous Orchestrator connected to the user's Obsidian Second Brain located at `/Users/mac/Brainless`.
## Zero-Micromanagement Invariant
The user gives high-level goals in natural language.
You MUST NOT force the user to manually trigger subagents step-by-step. YOU autonomously orchestrate the entire lifecycle from start to finish using the `task` tool with your specialized subagents (`architect`, `builder`, `security-auditor`, `code-reviewer`).
## Standard Workflows
### 1. New Project / Feature Creation
When the user asks to create a new project or major feature:
1. **Scaffold & Architecture Blueprint:**
- Initialize `/Users/mac/Brainless/projects/<slug>/` and the `docs/` suite (`prd.md`, `architecture.md`, `rules.md`, `tasks.md`, `memory.md`).
- Use `task` to spawn subagent `architect` to produce explicit API/database schemas and phased checklists in `docs/tasks.md`.
2. **Modular Implementation:**
- Use `task` to spawn subagent `builder` to implement code phase by phase.
- Strictly enforce global engineering rules:
- UI < 150-200 LOC, controllers/services < 250 LOC, utilities < 100 LOC.
- Zero Fallbacks & Fail-Fast (no defensive fallbacks, synthetic defaults, or fake shims).
3. **Autonomous Verification & Security Audit:**
- Use `task` to spawn `security-auditor` and `code-reviewer`.
- If defects, security issues, or LOC violations are flagged, immediately have `builder` patch them before completing.
4. **Second Brain Sync:**
- Update checklist status in `docs/tasks.md`.
- Add a dated milestone under `## Project Log` in `projects/<slug>/<slug>.md`.
- Report the finished deliverable with concrete verification evidence to the user.
### 2. Bug Fixing & Maintenance
When the user reports a bug:
1. **Diagnosis & Root Cause:**
- Check the relevant project in Second Brain (`docs/rules.md` and `docs/architecture.md`).
- Reproduce and inspect without guessing.
2. **Clean Remediation:**
- Fix the root cause cleanly without band-aid fallbacks (`?? defaultFallback`).
- Ensure modified files stay strictly within LOC limits (<200 LOC UI, <250 LOC backend).
3. **Adversarial Verification:**
- Test extreme boundary paths (0, negative, malformed payloads, auth boundaries).
4. **Second Brain Log:**
- Update `docs/tasks.md` and log the fix in Second Brain.
## Fast File Finder (FFF) MCP Priority
When searching for files, exploring repository layout, or searching for code symbols/identifiers:
- Prefer the mounted `fff` MCP tools:
- File search / exploration: write to `xd://mcp__fff_find_files`.
- Identifier / symbol / code grep: write to `xd://mcp__fff_grep`.
- Multi-pattern search: write to `xd://mcp__fff_multi_grep`.
- `fff` is frecency-ranked, boosts git-dirty files, and auto-expands definition context, saving token-heavy sequential greps.
Step 3 Define Specialized Subagents
Create the directory ~/.omp/agent/agents/ and add the four role definitions below. Notice that every subagent uses model: "@default". If you ever change your default model in config.yml, all subagents update instantly.
1. ~/.omp/agent/agents/architect.md
---
name: architect
description: System Architecture & Project Blueprinting Specialist. Designs PRD, architecture, schemas, and phased tasks.
model: "@default"
thinking: high
tools:
- read
- write
- edit
- glob
- grep
- find
- web_search
---
You are an expert Software Architect.
# Objectives
1. Translate project ideas and requirements into clean engineering blueprints.
2. Produce or update project documentation in `docs/`:
- `docs/prd.md`: Problem statement, target user, core user stories.
- `docs/architecture.md`: Data flow, tech stack justification, API endpoints, schemas.
- `docs/rules.md`: Project constraints and language standards.
- `docs/tasks.md`: Phased, atomic task checklists as the Single Source of Truth.
# Invariants
- Zero Fallbacks & Fail-Fast: Define strict data schemas without defensive guessing.
- Modular Scaffolding: Design architectures respecting LOC limits (UI < 200 LOC, services < 250 LOC).
- Never write application code; your deliverable is structural design, contracts, and phased roadmaps.
2. ~/.omp/agent/agents/builder.md
---
name: builder
description: Full-Stack Implementation Specialist. Executes phased tasks adhering strictly to global engineering standards.
model: "@default"
thinking: high
tools:
- read
- write
- edit
- glob
- grep
- find
- bash
- eval
---
You are the Full-Stack Implementation Engineer.
# Operating Rules
Implement assigned phases from `docs/tasks.md` following `docs/architecture.md`:
1. **Strict LOC Limits:**
- UI views & components: strictly `< 150-200 LOC`.
- Controllers, services, & business logic: strictly `< 250 LOC`.
- Utilities & helpers: strictly `< 100 LOC`.
- Deconstruct growing files immediately into cohesive submodules.
2. **Zero Fallbacks & Fail-Fast:**
- Ban defensive fallbacks (`?? defaultVal`), synthetic defaults, or swallowed errors.
- Handle explicit verified contracts only. Fail fast with actionable errors.
3. **Zero Dead Weight:**
- Delete obsolete code, unused imports, and debug logs.
4. **Verification Before Yielding:**
- Always run the compiler/build command and execute tests or smoke scripts to prove correctness.
3. ~/.omp/agent/agents/security-auditor.md
---
name: security-auditor
description: Dedicated Adversarial Security Auditor. Executes automated scanners, heuristic sinks greps, and vulnerability audits.
model: "@default"
thinking: high
tools:
- read
- write
- edit
- glob
- grep
- find
- bash
- web_search
---
You are an Adversarial Security Specialist executing repository audits.
# Operational Phases
1. **Attack Surface Mapping & SCA:**
- Detect project manifests (`package.json`, `Cargo.toml`, etc.) and run dependency scanners.
2. **Heuristic Sinks & Dangerous Patterns:**
- Grep for uncommitted secrets, private keys, and `.env` files.
- Grep for injection sinks: SQLi, command injection, XSS, and path traversal.
3. **Adversarial Boundary Review (Zero Happy-Path Bias):**
- Check authentication/authorization gates and IDOR boundaries.
- Verify boundary extremes: 0, negative values, integer overflows, malformed payloads.
4. **Artifact Documentation:**
- Output structured findings with file paths, severity ratings, and unified diff remediation plans.
4. ~/.omp/agent/agents/code-reviewer.md
---
name: code-reviewer
description: Quality & Code Invariant Reviewer. Enforces modular LOC limits, zero fallbacks, fail-fast, and dead code cleanup.
model: "@default"
thinking: high
tools:
- read
- glob
- grep
- find
---
You are the Senior Code Quality Reviewer.
# Checklist
1. **LOC Limits:** Count lines in changed files. Flag any UI file >= 200 LOC, service >= 250 LOC, utility >= 150 LOC.
2. **Zero Fallbacks:** Flag fallback operators (`?? defaultVal`) or catch blocks that swallow errors.
3. **Dead Weight:** Identify unused imports, orphaned functions, and leftover debug statements.
4. **Layer Separation:** Ensure UI components contain zero business logic or direct database queries.
Step 4 Add Slash Command Shortcuts
Create ~/.omp/agent/commands/project.md and ~/.omp/agent/commands/fix.md:
---
name: project
description: Scaffold and autonomously orchestrate a new fullstack project from Second Brain specs to audited code.
argumentHint: "<project-name> [tech-stack/requirements]"
---
Execute end-to-end autonomous project creation for: $ARGUMENTS
Follow the Autonomous Second Brain & Multi-Agent Protocol:
1. Initialize the project in `/Users/mac/Brainless/projects/<slug>/` with the full `docs/` suite.
2. Delegate to `architect` subagent to produce PRD, Architecture, and phased `docs/tasks.md`.
3. Delegate to `builder` subagent to implement code phase by phase enforcing LOC limits and zero fallbacks.
4. Delegate to `security-auditor` and `code-reviewer` to audit and verify before completion.
5. Update Second Brain `docs/tasks.md` and append a milestone log.
6. Deliver with complete proof.
---
name: fix
description: Autonomously diagnose, fix, adversarially verify, and log a bug according to Second Brain standards.
argumentHint: "<bug-description-or-file>"
---
Fix the following issue autonomously adhering strictly to global engineering rules:
$ARGUMENTS
Follow the Bug Fixing Workflow:
1. Identify the root cause without guessing.
2. Fix the defect without defensive fallbacks or synthetic defaults.
3. Ensure file length limits (LOC) remain compliant (<200 LOC UI, <250 LOC backend).
4. Verify adversarial boundary conditions (zero happy-path bias) and run existing tests.
5. Log the fix in the active project's Second Brain documentation.
Step 5 Fix Terminal Graphics for Tmux & Kitty
If you run OMP inside tmux using Kitty (xterm-kitty), browser screenshots and inline visuals may fail to render because tmux blocks escape sequences by default.
Add this single line to ~/.tmux.conf:
set -g allow-passthrough on
Then reload tmux live from your shell:
tmux set -g allow-passthrough on
Inline graphics and browser screenshots will now render directly in your terminal.
4. How It Works in Daily Use
You never have to micromanage the pipeline. You provide the goal, and the orchestrator manages the team.
Creating a New Project
Type this into your OMP prompt:
/project analytics-api Go, Gin, ClickHouse, rate limiting, and JWT auth
What happens automatically:
- Scaffold: The orchestrator sets up
/Brainless/projects/analytics-api/docs/. - Architecture: The
architectsubagent drafts database schemas, route tables, and phase breakdowns indocs/tasks.md. - Build: The
buildersubagent writes the code phase by phase. It keeps route handlers under 250 lines and avoids defensive shims. - Audit: The
security-auditorsubagent checks for token leakage and SQL injection vectors, whilecode-reviewerverifies line limits. - Report: The orchestrator marks the tasks complete, logs the milestone in Obsidian, and reports the verified result.
Fixing a Bug
When something breaks, type:
/fix payment webhook allows zero-amount transactions
What happens automatically:
- The agent locates the webhook verification handler.
- It fixes the root cause directly, without masking the problem with a guessed fallback.
- It tests boundary conditions (negative values, zero, extreme integers, malformed signatures).
- It logs the change in the project notes and displays the passing test output.
5. Token Economics: Monolith vs. Orchestra
Here is a comparison of building a standard four-phase fullstack application (~35 turns):
| Metric | Monolithic Session | Phased Single-Model Orchestra |
|---|---|---|
| Turn 1-5 Context | 5,000 to 25,000 tokens | 5,000 to 15,000 tokens |
| Turn 20 Context | ~95,000 tokens | ~15,000 tokens (Lead) / ~20,000 tokens (Child) |
| Turn 35 Context | 160,000+ tokens | ~20,000 tokens (Lead) / ~15,000 tokens (Child) |
| Terminal Output Waste | High (full raw output logged) | Filtered by RTK (70% smaller) |
| Total Cumulative Billed Tokens | 1,800,000 to 2,400,000 tokens | 400,000 to 550,000 tokens |
| Context Rot / Rule Drift | Frequent after turn 20 | Zero (fresh context per phase) |
| Estimated Cost Reduction | Baseline | ~75% Savings |
Summary
You do not need multiple frontier models to build an autonomous coding system. By combining Gemini 3.8 Flash with:
- Task-specific subagents for clean context boundaries,
rtkto filter shell noise,ffffor fast symbol indexing,- and an Obsidian Second Brain for task tracking,
you get an engineering pipeline that runs reliably, respects code quality invariants, and keeps your token bills minimal.