DEV Community

Cover image for Every AI Agent Runs on the Same Five Primitives
Jamie Duncan
Jamie Duncan

Posted on Originally published at jduncan.io

Every AI Agent Runs on the Same Five Primitives

Originally published at jduncan.io.

In the early days of generative AI, I talked with customers and engineers about what AI could brings to software that was genuinely new.

The idea was simple. Every line of code ever written, regardless of platform, language, or era, was built using four constructs:

  • if
  • else
  • for
  • while

That's it. Everything else (classes, type systems, async runtimes, design patterns) was built for human understanding and efficiency. AI felt like the first time we were introducing something genuinely new into programming workflows: agentic judgement.

The nuance

Now, that claim isn't 1,000% accurate.

Back in 1966, Corrado Böhm and Giuseppe Jacopini proved in the Structured Program Theorem that you technically only need three control structures (sequence, selection, and iteration) to express any computable algorithm. And AI doesn't magically replace those structures with a new computer science primitive.

In practice, it's closer to saying agents manage those four constructs much faster than a human can. They translate fuzzy intent into deterministic branches and loops, over and over, at machine speed.

Still, the spirit of the argument holds. Instead of forcing an engineer to hardcode every possible branch upfront, the workflow can apply judgement between deterministic steps. As I argued in Coding Was Never About Syntax, typing syntax was never the real job anyway. At least it wasn't supposed to be.

Now we're watching the same compression happen inside the AI ecosystem itself.

Five primitives, same walls

Spend ten minutes scanning product announcements and every vendor claims to have invented a brand-new paradigm. Cognitive architectures. Agentic operating systems. Autonomous swarms.

Strip away the branding, and regardless of what someone says they're doing with AI, every system has the same handful of core primitives underneath:

  • System prompts: The identity, boundaries, and operating rules loaded on turn zero.
  • Skills: Reusable playbooks and domain workflows pulled in on demand.
  • Harness tools: Shell access, file reads and edits, search, and subagent orchestration.
  • MCP: Standardized connectors to external APIs, databases, and services.
  • Context (in a few flavors): The active message window, repository docs or wikis, compaction summaries, and injected runtime state.

That's the whole kit. An agent can write additional scripts or custom CLI helpers to get a job done, just like a developer builds libraries. Under the hood, it can only ever work through those five primitives.

And every team building on them is constrained by the exact same three walls we've been fighting since day one:

  • Context window rot: Bigger token windows don't mean uniform reasoning. In Chroma's July 2025 Context Rot study across 18 frontier models, performance degraded continuously as input length grew, even on simple tasks and long before hitting the maximum token cap. Synthetic benchmarks are also far tidier than a 40-turn debugging session full of failed builds and partial diffs, so real production loops rot even faster once plausible distractors pile up.
  • LLM memory shaping: Models don't read documents like humans do. Stanford's "Lost in the Middle" research mapped the U-shaped recall curve: models attend strongly to the beginning and end of a prompt while losing facts buried in the middle. In practice, models also treat stale notes with the same weight as current truth. When I built a wiki for a machine reader, I had to delete outdated caveats instead of annotating them. When my factory prompts bloated to 17,072 words, I had to cut 65% of them (taking _base.md from 2,861 words down to 55) before agents stopped wasting turns on defensive rituals.
  • Poorly-designed tooling interfaces: Hand an agent ambiguous parameters, noisy stack traces, or bloated tool catalogs, and you pay for it on every turn. As I tracked in MCP Context Bloat, a single 93-tool GitHub MCP server can burn roughly 55,000 tokens before the agent writes a single line of code.

Same five building blocks.

Same three physics constraints.

What programming languages already taught us

We've solved this kind of puzzle before. Every mainstream programming language compiles down to the same machine-level conditionals and loops. Nobody picks Rust over Python because Rust discovered a fifth control structure.

They pick a language because different operating conditions reward different ways of assembling the same blocks.

Agent harnesses follow the exact same engineering trade-offs.

C vs. Rust: human discipline vs. enforced invariants

C gives you raw speed and total flexibility because it trusts the programmer to track every pointer and free every allocation by hand. Rust keeps the speed, then moves ownership and lifetime checks into the compiler so whole classes of memory bugs can't ship.

Interactive terminal sessions loaded with giant global skill catalogs are C. Across 385 interactive Claude sessions I measured in Why Giant Agent Skill Repos Won't Survive 2027, Turn 1 opened at a median of 45,136 tokens. That still works interactively because a human is sitting right there acting as the brake pedal, smashing Esc or /clear the second the model wanders off.

Unattended software factories like Wedgwood have to be Rust. When no human is watching the terminal, a worker pod starts around 6,200 tokens, runs inside an isolated worktree, and hits hard deterministic CI/CD gates at every handoff. You don't ask an unattended model to remember line 200 of a markdown file when code can enforce the boundary.

Python vs. Go: rapid exploration vs. boring production plumbing

Python is unmatched when requirements are fuzzy and you want fast feedback, dynamic typing, and glue code across ten libraries. Go intentionally strips away clever abstractions in favor of predictable concurrency, explicit error handling, and boring production binaries you can trust at 3 a.m.

Interactive coding assistants (Claude Code, Antigravity, Cursor) are Python. When you're prototyping a feature or debugging a weird race condition, rich exploratory context and flexible skills help you figure out what to build.

Background factory loops are Go. They want narrow role prompts, small path-scoped skills (around 65 lines at median in our factory repos), explicit state handoffs, and zero surprises. Writing a throwaway data script in Go feels miserable; running a five-host autonomous fleet on an exploratory chat loop falls apart just as fast.

npm sprawl vs. a tight standard library: dependency weight

Pull 800 transitive packages into a small web service and you inherit cold-start lag, version conflicts, and supply-chain noise. Languages with strong standard libraries trade a bit of ecosystem flash for fast startup and predictable behavior.

Strapping 15 MCP servers and a 100-skill starter pack onto an agent is node_modules all over again. Every extra tool schema and global skill description sits in context as a tempting doorknob the model can pull by mistake. A tight set of core harness tools (bash, file edits, search) paired with two or three scoped skills beats an overloaded MCP stack on both speed and accuracy.

SQL vs. nested imperative loops: declaring the contract

A database engine still executes loops, branches, and scans under the hood. Yet SQL transformed data engineering by separating what must be true from the step-by-step path used to compute it, handing execution planning to an optimizer.

Writing a 2,800-word step-by-step checklist inside a system prompt ("first grep this directory, then check this flag, then run tests twice") is hand-coding brittle imperative loops in English. Giving an agent clean context, sharp tools, and hard verification contracts (type checks, unit tests, cognitive complexity gates) is declarative engineering. Let agentic judgement pick the path, and let deterministic tooling verify the state.

Programming Trade-Off Interactive Agent Harness Unattended Factory Harness
C vs. Rust Human watches the loop (Esc / /clear) Compiler-style gates (worktrees, CI/CD)
Python vs. Go Rich context for fuzzy exploration Minimal roles for predictable execution
npm vs. stdlib Broad MCPs and global skill packs Core CLI tools and ~65-line scoped skills
Loops vs. SQL Step-by-step conversational steering Clean context plus deterministic test contracts

Same four constructs. Different trade-offs.

Same five primitives. Same craft.

So what?

If you're building with agents or designing harnesses right now, three habits keep you out of the hype cycle:

  • Stop hunting for a sixth primitive. When a new agent framework launches, strip off the marketing names and map it back to system prompts, skills, harness tools, MCP, and context. Look at what it actually changes under the hood.
  • Match the harness to the operating conditions. Use Python-style flexibility when a human is steering interactively. Switch to Rust-style invariants and Go-style subtraction the moment a loop runs unattended.
  • Debug the real constraint first. Before adding another stern paragraph to your system prompt, check whether the failure came from context rot, muddy memory shaping, or a noisy tool interface.

Everyone gets the exact same five building blocks. Making them hold up under load is still engineering.

Top comments (0)