PTENES
MODULE 3.2

🏗️ Deterministic Workflows with Archon

Beyond the pure loop: how to use Archon to create step-by-step controlled workflows, with a mix of models, durability via Postgres, and true separation between coding agent sessions.

6
Topics
40
Minutes
Advanced
Level
Hands-on
Type
GitHub Issue Input Extract deterministic regex/API Classify LLM (cheap) Haiku / Kimi Implement LLM (strong) Claude Code Validate tests + lint deterministic Pull Request output Archon Deterministic Pipeline human defines the steps; agent executes within each one human control: you define the sequence; the agent only executes within each step
1

🎯 What Is Archon and Why Does It Exist

Archon is the “harness builder” created by Cole Medin. It lets you build workflows that orchestrate multiple coding agent sessions for larger tasks. The fundamental difference from a pure loop: you define the process, not the agent. In a pure loop, the agent decides how to make progress. In Archon, you define the steps, and the agent executes within each one.

🧱 Pure Loop vs. Deterministic Workflow

Pure Loop (/loop)

  • Agent decides the next steps
  • One session for everything
  • One model for everything
  • Inevitable context bloat
  • No built-in observability

Archon Workflow

  • Human defines the sequence of steps
  • Separate session per step
  • Different model for each step
  • Fresh context at every step
  • Integrated logs and dashboard

Cole Medin explains the direct motivation: "O Archon é meu criador de harness; ele nos permite criar fluxos de trabalho que orquestram várias sessões de agentes de programação para lidar com tarefas maiores." The idea is that a workflow like "fix GitHub issue" doesn’t need an agent deciding how to solve it. The process is known: extract context, classify, research, implement, validate, create a PR.

2

🔧 Anatomy of the "Fix GitHub Issue" Workflow

Archon's most classic workflow is "Fix GitHub Issue." Cole Medin uses this day to day: "Most of the input for my day-to-day work is issues in a repo. Either I'll create them or someone else will." The workflow follows a fixed sequence of steps, each with a specific role.

📋 Workflow steps

Step 1: Extract Issue Number

Deterministic. Extracts the issue number via regex or the GitHub API. No LLM.

Type: deterministic | Model: none

Step 2: Fetch Issue Context

Deterministic. Fetches the issue title, description, labels, and comments via the GitHub API.

Type: deterministic | Model: none

Step 3: Classify

LLM decides: is it a bug or a feature? The rest of the workflow changes based on that decision.

Type: LLM | Model: Haiku / Kimi K2.7 (inexpensive)

Step 4: Research & Investigate

Explores the codebase, identifies relevant files, and understands the problem context.

Type: LLM | Model: Kimi K2.7 (exploration)

Step 5: Implement

Writes the actual code. This is where you need a powerful model.

Type: LLM | Model: Claude Code (strong)

Step 6: Validate

Runs tests and linting, and checks whether the issue was resolved. It can be deterministic or use an LLM for review.

Type: mixed | Model: Codex for review

Step 7: Create PR

Create the pull request with a description based on the context accumulated from previous steps.

Type: deterministic + LLM | Model: Claude

The key point: "We're not having the agent drive the entire thing. It's more deterministic because we set up the process in this workflow file." You define the steps, Archon ensures they run in the right order, and each step runs in an isolated session with the ideal model for that task.

3

🧩 The Philosophy: Taking Decisions Away from the Agent

The fundamental principle of Archon is counterintuitive: the fewer decisions the agent makes, the better the result. Cole Medin makes this explicit: "We want to actually take the decision away from the coding agent as much as we can, only applying the reasoning of the LLM when we actually need it to write the code."

Where to Use LLMs vs. Where Not to Use Them

Requires an LLM

  • *Classify issue type (bug vs. feature)
  • *Research the codebase and understand the context
  • *Write implementation code
  • *Semantic code review

No LLM Needed

  • *Extract issue number (regex)
  • *Fetch issue data (API call)
  • *Run tests (npm test)
  • *Create PR (gh pr create)

💻 Example: Deterministic Step in TypeScript

// Step deterministico: nao precisa de LLM
async function extractIssueNumber(input: string): Promise<number> {
  const match = input.match(/issues\/(\d+)/);
  if (!match) throw new Error("Invalid issue URL");
  return parseInt(match[1], 10);
}

// Step deterministico: API call pura
async function fetchIssueContext(owner: string, repo: string, num: number) {
  const res = await fetch(
    `https://api.github.com/repos/${owner}/${repo}/issues/${num}`,
    { headers: { Authorization: `token ${process.env.GITHUB_TOKEN}` } }
  );
  return res.json();
}

// Step LLM: aqui sim o agente precisa raciocinar
async function classifyIssue(context: IssueContext): Promise<"bug" | "feature"> {
  // Roda num modelo barato (Haiku, Kimi K2.7)
  const response = await llm.complete({
    model: "haiku",
    prompt: `Classify this GitHub issue as "bug" or "feature":\n${context.title}\n${context.body}`
  });
  return response.trim() as "bug" | "feature";
}

🤔 Reflection Point

This philosophy is what Cole Medin calls "layering on top of loop engineering." You don't abandon loops entirely. You take the good parts (automation, cycles) and add a layer of human control. The result: less token waste, more predictability, and easier debugging.

4

🔀 Model Mix: The Right Model for Each Step

One of the biggest problems with a pure loop using /loop or /routines: "You're just using one model for pretty much everything. That's part of the problem of why it's so expensive." In Archon, each workflow node can use a different model, optimizing cost without sacrificing quality.

🎛️ Model Map by Step

Step Suggested Model Rationale Relative Cost
Extract / Fetch None (API) Deterministic, no reasoning $0
Classify Haiku / Kimi K2.7 Simple decision, no need for an expensive model $
Research Kimi K2.7 Codebase exploration, context loading $$
Implement Claude Code Writing real code that requires quality $$$
Validate Tests + Codex Tests are deterministic; review is by an LLM $$

Cole Medin demonstrates this in practice: "We can use Cloud Code for the implementation. And then we can use Codex for the review. And then for all of our context loading and exploration up front, we can use a smaller model like Kimi K 2.7." This is model routing applied to agent workflows.

💡 Practical Tip

The general rule: use inexpensive models for decisions and powerful models for creation. Classifying an issue as a bug vs. a feature doesn’t require Opus. Writing the fix does. The cost difference can be 10x or more per step.

5

💾 Durability: State in Postgres/Neon

One of the biggest weaknesses of the basic loop: if the terminal closes, you lose everything. Archon solves this by storing all the state in an external database. "Estou armazenando aqui todos os loops que executamos, os diferentes eventos e logs, para que possamos sempre retomar um fluxo de trabalho mais tarde."

💻 Simplified Schema: Durability with Neon

-- Cada run tem um ID e estado persistente
CREATE TABLE workflow_runs (
  id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  workflow_id TEXT NOT NULL,
  status      TEXT DEFAULT 'running', -- running | paused | completed | failed
  input       JSONB NOT NULL,
  state       JSONB DEFAULT '{}',
  created_at  TIMESTAMPTZ DEFAULT now(),
  updated_at  TIMESTAMPTZ DEFAULT now()
);

-- Cada step registra sua execucao
CREATE TABLE step_executions (
  id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  run_id      UUID REFERENCES workflow_runs(id),
  step_name   TEXT NOT NULL,
  status      TEXT DEFAULT 'pending', -- pending | running | completed | failed
  input       JSONB,
  output      JSONB,
  model_used  TEXT,
  tokens_used INTEGER DEFAULT 0,
  started_at  TIMESTAMPTZ,
  finished_at TIMESTAMPTZ
);

-- Logs de conversacao para replay
CREATE TABLE conversation_logs (
  id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  run_id      UUID REFERENCES workflow_runs(id),
  step_name   TEXT NOT NULL,
  role        TEXT NOT NULL, -- system | user | assistant
  content     TEXT NOT NULL,
  created_at  TIMESTAMPTZ DEFAULT now()
);

Cole Medin emphasizes: "Todas as minhas conversas e bases de código em que trabalho com o Archon ficam salvas, e é muito fácil retomar qualquer trabalho que eu esteja fazendo." With the state in a Postgres database (Neon), you can resume workflows after a crash, view the complete history of each run, and audit agent decisions.

🤔 Reflection Point

Durability isn't a "nice to have" for serious loops. It's a requirement. If you're running a 2-hour loop and the machine restarts at minute 90, you've lost everything without external state. With Neon/Postgres, you can resume at the exact step where you left off. The setup cost (one hour of configuration) pays for itself the first time you DON'T lose your work.

6

❓ Questions: Archon vs. Pure Loop

Archon solves many problems of a pure loop, but introduces its own complexity. It’s worth being honest about the trade-offs.

Open Questions

When does a deterministic workflow become too restrictive?

If you define every step rigidly, you lose the agent's ability to improvise. For exploratory tasks (proofs of concept, ideation), a pure loop may be more suitable because the agent needs the freedom to discover unexpected paths.

Is the engineering overhead worth it?

Configuring Archon, defining workflows, and maintaining Postgres is real engineering. For a one-off task, it probably isn't worth it. For repetitive tasks (processing issues every day), it pays off quickly. Cole Medin uses Archon daily for issues.

Harness engineering vs. loop engineering?

Cole Medin proposes: "I’d include loop engineering under harness engineering. It doesn’t really deserve its own buzzword." The view is that loops are a tool within a larger harness, not a separate paradigm. The harness defines the process; loops carry out parts of it.

🎯 Choice Summary

  • *Pure loop: ideal for exploration, PoCs, simple one-off tasks
  • *Archon/Workflow: ideal for repetitive, multi-step tasks with controlled costs
  • *Hybrid: deterministic workflow with internal loops in the steps that need iteration

📝 Module Summary

✓
Archon - harness builder that orchestrates multiple coding agent sessions in deterministic workflows
✓
Deterministic steps - human defines the process, agent executes each step with fresh context
✓
Model mix - inexpensive model for classification, powerful model for implementation, no LLM for deterministic steps
✓
Durability - state in Postgres/Neon lets you resume workflows after a crash without losing progress
✓
Harness > Loop - loops are a tool within a larger harness, not a standalone paradigm

Next Module:

3.3 - Control Dashboard (Agent Control Plane): how to observe orchestrator decisions in real time and add human-in-the-loop