Multi-agent pipeline architecture: the run is the unit, not the agent

A generic multi-agent pipeline: ingest, plan, tools and MCP, workers.

I have now built four agent systems that run in production or close to it: the runtime behind an AI-visibility platform with 35 agents, a research cascade of 10+ agents for startup validation, a content conveyor with human gates, and an AI layer for a fintech platform on Temporal. The agents themselves never carried over – different models, prompts, frameworks. The multi-agent pipeline architecture around them did, almost unchanged.

The short version: design the run, not the agent. A run is a durable record with a budget, an owner for every decision and a check that the producer can’t pass on its own. Everything below is a consequence of that.

Code owns the control flow

Anthropic’s guide to building effective agents separates workflows, where code drives LLMs through predefined paths, from agents, which choose their own steps. Every pipeline I trust is a workflow at the top level. Models make decisions inside a step; they never decide which step runs next.

I pay for that in flexibility and get three things back. A run can be replayed and explained step by step. A stage can be tested in isolation. And the outcome is decided by code that a reviewer can read. In the fintech AI layer this went one level further: where the answer is a rule or a date, code computes it and a model only writes the explanation, and the final status of an answer – final, needs information, preliminary – is set by code from the rules and the evidence, never from a confidence score the model reports about itself.

Durability: build it or buy it

Every run needs to survive a crashed worker, a provider outage and a deploy in the middle of a step. There are two honest ways to get that.

On the visibility platform I built it: an API that never calls a model inline, a queue, background workers and a harness that schedules agents, enforces budgets and records every step. That was the right call there. Runs are minutes long, nothing waits on a person, and the harness was small enough to own.

The fintech AI layer was different. An answer could pause for days waiting for a client’s clarification or an approval, and nothing was allowed to be lost, stuck or left unaccepted. I compared a scheduler of my own on task tables, Redis with RQ, LangGraph with Postgres checkpoints, DBOS, Hatchet and Temporal Cloud, and chose self-hosted Temporal: deterministic replay, durable timers and signals, and a retry policy per step. Temporal Cloud was out because workflow history would sit with a third party.

Buying durability doesn’t buy you correctness, and three things stayed my problem:

  • Payloads carry IDs, not data. Workflow history is a second database with its own retention, so personal data stays in the application’s PostgreSQL, which remains the source of truth.
  • Changes are replayed against old histories in CI. Workflow code must stay deterministic, and the only reliable proof is replaying real past runs through the new code.
  • Starting a workflow after a commit is a trap. In FastAPI the database session commits after the handler returns, so a workflow started from the handler can run before its row exists. Starts go through a background task plus a scheduled reconciliation, and a deterministic workflow ID makes a duplicate start harmless.

Budgets in money, checked before the step

A budget that is checked after a step has already been overspent. Check before, against the worst case of the next step:

type Spend = { steps: number; usd: number };

function assertCanRun(run: Run, next: StepEstimate): void {
  const after: Spend = {
    steps: run.spent.steps + 1,
    usd: run.spent.usd + next.maxUsd,
  };
  if (after.steps > run.budget.steps || after.usd > run.budget.usd || Date.now() > run.budget.deadline) {
    throw new BudgetExceeded(run.id, after);
  }
}

Steps and tokens are proxies; money is what someone eventually asks about. In the fintech AI layer a client question may spend up to $0.50, a system-triggered run $0.05 and one user $3.00 a day. The limits live in environment variables, so tightening them doesn’t need a release. Anthropic’s guide makes the general point – agents bring higher costs and compounding errors, so put stopping conditions on them – and a money cap is the stopping condition finance understands.

One owner for retries

Retries are cheap to add and expensive to have twice. If the SDK, the gateway and the workflow each make three attempts, one failure becomes up to 27 calls, and most of them never appear in your record. In the fintech AI layer retries inside LiteLLM are switched off and the harness owns them, so each attempt is its own recorded step.

The other half is idempotency. Stripe’s idempotent requests are the model I copy: a retry with the same key returns the saved result of the first attempt instead of repeating it. In a pipeline the key is the run and the step, and any side effect outside the system – an email, a payment, a publish – is keyed the same way.

A check the producer can’t pass

An agent grading its own output tells you very little. Every pipeline I run has an independent pass, and I enforce the independence rather than trusting configuration. In the fintech AI layer the critic always runs on a different model from the author, and the worker refuses to start if the two are configured the same.

The check also needs a bound, or it becomes a loop that spends money arguing with itself. The content conveyor allows one return for rework per gate; if a material comes back a second time, the problem is the brief, not the draft, and it goes to a person. Gates fail closed: an unanswered approval is a stopped run, not a published one.

Traces, not logs

If you can’t see why an agent did what it did, you can’t run it. I want a span per step – in OpenTelemetry terms, a unit of work inside one trace – with its inputs and outputs. Then ‘the answer is wrong’ becomes ‘the planner picked the wrong tool at step four’, which is a bug with an address. On the visibility platform that trace-first design is the part I would keep if I had to throw everything else away.

Where this is overkill

Not every LLM feature is a pipeline. A single call behind an endpoint needs a timeout, a fallback and a test of the provider contract – I wrote about that in testing LLM integrations – not a workflow engine. A few minutes-long steps with no humans in the loop can live on a queue and a small harness. Reach for a durable engine when runs wait on people or timers for longer than a deploy cycle, because that is the point where building it yourself stops being small.

The same rule applies to the tools agents call: keep the logic in one place and expose it, don’t copy it. That is the subject of MCP server design.