Patterns
The Six Primitives of a Loop
Autonomous Agent Systems Β· Loop Orchestration Β· Production Workflows

The Six Primitives of a Loop

The architectural building blocks of reliable autonomous agent loops

THE SIX PRIMITIVES OF A LOOP

The Six Primitives of a Loop

A well-designed agent loop has five working parts plus one place to remember state. These primitives are consistent across both Claude Code and OpenAI Codex.

1. Automations β€” The Heartbeat

Automations are what make a loop an actual loop and not just one run you did once. They surface work on a schedule without you asking β€” everything else in the loop reacts to what they find.

Automations run on a cadence and produce findings. Runs that find something land in a triage inbox or state file. Runs that find nothing archive themselves. The key in-session primitive is /goal: it keeps working across turns until a condition you wrote is actually true, with a separate model checking whether you are done after every turn β€” so the agent that wrote the code is never the one grading it.

2. Worktrees β€” Isolation for Parallel Work

The second you run more than one agent, file collisions become the dominant failure mode. Two agents writing the same file is precisely the same problem as two engineers committing to the same lines without coordination.

A Git worktree fixes it. It is a separate working directory on its own branch sharing the same repository history, so one agent’s edits cannot touch another’s checkout. Both Claude Code and Codex support worktrees natively β€” giving each agent its own isolated environment that cleans itself up after.

3. Skills β€” Codified Project Knowledge

A skill is how you stop re-explaining the same project context every session. Both tools use the same format: a folder with a SKILL.md inside holding instructions and metadata, plus optional scripts, references, and assets.

A skill encodes:

  • Project conventions and build steps
  • Decisions the team made and why
  • The context the agent would otherwise guess at

Without skills, the loop re-derives your whole project from zero every cycle. With skills, the loop’s understanding compounds.

4. Plugins and Connectors β€” The Loop Touches Real Tools

A loop that can only see the filesystem is a tiny loop. Connectors, built on MCP (Model Context Protocol), let the agent read your issue tracker, query a database, hit a staging API, file a PR, or drop a message in Slack.

This is the difference between an agent that says “here is the fix” and a loop that opens the PR, links the Linear ticket, and pings the channel once CI is green β€” entirely on its own.

5. Subagents β€” Separate the Maker from the Checker

The most structurally important thing in a loop is splitting the agent that writes from the agent that checks. The model that wrote the code will grade its own homework too generously. A second agent with different instructions β€” and sometimes a different model β€” catches what the first one talked itself into.

The standard split in both tools:

  • One agent explores and triages
  • One agent implements a fix or feature
  • One agent verifies the result against the spec and existing tests

6. State / Memory β€” The Spine of the Loop

The sixth primitive sounds too simple to matter: a Markdown file, a Linear board, anything that lives outside the single conversation and holds what has been done and what is next.

But it is the trick every long-running agent depends on. The model forgets everything between runs; the repo does not. The state file is the spine. It remembers what was tried, what passed, and what is still open β€” so tomorrow’s run picks up exactly where today’s stopped.

Interactive Tools

Practical tools to help you think systematically, build better AI agents, and master prompt engineering.

Future References

Explore these resources for deeper learning on AI agent development, spec-driven development, and prompt engineering tools.

Spec-Driven Development

Comprehensive guide on Spec-Driven Development practices and methodologies.

Awesome Copilot

Curated list of GitHub Copilot resources, extensions, and best practices.

Promptfoo

Tool for testing, evaluating, and improving LLM prompts and applications.

Prompts.chat

Collection of prompt engineering resources and templates.

Agent Skills

Agent skills resources and documentation for building AI agent skills.

Awesome Skills

Curated list of awesome skill repositories and collections.

Agent Skills Topic

GitHub topic for discovering agent-related skills and repositories.

AI Agent Topic

Trendshift topic for discovering AI agents.

AI Skills Topic

Trendshift topic for discovering AI skills.

Agent Governance Toolkit

Agent governance toolkit.

Pattern Sources

Our patterns are curated from industry-leading sources with proper attribution and licensing compliance.

Refactoring.Guru

Classic GoF design patterns, code smells catalog, and refactoring techniques (https://refactoring.guru).

Enterprise Integration Patterns

65 messaging patterns for integrating enterprise applications by Gregor Hohpe and Bobby Woolf (CC BY 4.0).

Microservices.io

Comprehensive patterns for microservice architectures by Chris Richardson.

Agent Catalog Patterns

Patterns for agentic systems from agentpatternscatalog.org (CC BY 4.0).

OWASP Foundation

Security patterns from OWASP Top 10 for Web Applications, LLM Applications, and Agentic Applications (CC BY-SA 4.0).

Industry Research

ML/AI patterns from Microsoft, Google, Anthropic, and academic research.

AI Agent Patterns

Spec-driven development patterns from Claude, Gemini, OpenAI, and GitHub Copilot on github/spec-kit and OpenSpec.

Data Engineering Leaders

Data platform patterns from Martin Fowler (Data Mesh), Kimball Group (Dimensional Modeling), and cloud providers.

MLOps Best Practices

Data science patterns from MLflow, Great Expectations, and MLOps practitioners.

Streaming & Analytics

Real-time patterns from Confluent/Kafka, Apache projects, and serverless analytics platforms.

Academic Papers

Rigorous ML patterns from peer-reviewed research including data leakage prevention and active learning.

5-Day AI Agents Course

Intensive Vibe Coding Course With Google by Brenda Flynn et al. (2026) on Kaggle.

The Agent Loop

Foundational Agent Definition (Perceive + Act):
Russell, S. J., & Norvig, P. (1995). Artificial Intelligence: A Modern Approach. Prentice Hall. (Current edition: 4th Ed., Pearson, 2020)

Modern Iterative LLM Agent Loop:
Yao, S., Zhao, J., Yu, D., et al. (2022). ReAct: Synergizing Reasoning and Acting in Language Models. arXiv:2210.03629.

Historical Context:
Incorporating AIMA's perceive/act model, Classical robotics' Sense-Plan-Act loop (Brooks, 1986), and ReAct's Thought→Action→Observation cycle.