# Agents as reconciliation loops

> Source: <https://rednafi.com/ai/agent-reconciliation-loop/>
> Published: 2026-12-01 23:00:00+00:00

**Recommendation:** Separate decide from apply in your agent loop so the plan is plain data you can log, dry-run and replay in tests before any state changes.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

[Redowan's Reflections](https://rednafi.com/)

# Agents as reconciliation loops

## Table of contents

Over the past year, I’ve written a handful of agents. Some of them handle production traffic
at work, and a couple run on a Raspberry Pi on my desk. I’ve written agent loops by hand and
used most of the popular frameworks: [AWS Strands](https://strandsagents.com/), [Google ADK](https://google.github.io/adk-docs/), [LangGraph](https://www.langchain.com/langgraph), [OpenAI
Agents SDK](https://openai.github.io/openai-agents-python/), [Pydantic AI](https://ai.pydantic.dev/), and the [Claude Agent SDK](https://docs.claude.com/en/api/agent-sdk/overview). Along the way, I settled on a
pattern that I now use for nearly every agent, regardless of the framework.

Note

By agent, I mean a model plus a harness. The harness is the glue code around the model that does things on its behalf, like calling tools, reading files, and talking to other services.

Agents can be triggered by an API call, an event, or a cron job. Once awake, the agent typically follows the same steps, and each run is one pass of a reconciliation loop.

## Reconciliation loops 

In [Reconciling Everything](https://www.youtube.com/watch?v=MuK6lmsfX1E), Andrew Godwin describes a reconciliation loop as stateless
programs that talk to one source of truth. Each program reads the current state and finds
something that doesn’t match the desired state. It takes a small step to close the gap,
writes the result back, and starts again.

Kubernetes is the best-known example. You declare what you want in an object’s `spec`, and a
[controller](https://kubernetes.io/docs/concepts/architecture/controller/) runs a loop that:

- watches the API server for changes to the objects it manages
- compares the desired state in the `spec` with the current state of the cluster
- asks the API server for the changes that close the gap
- records what it saw in the object’s `status`

## Observe, decide, apply, report 

An agent run works the same way, with your prompt or rules defining the desired state.

In code, a run looks like this:

``` php
def reconcile(trigger: Trigger) -> None:
    state = observe(trigger)
    plan = decide(state)  # returns data, changes nothing
    result = apply(plan)
    report(result)
```

Say you’re building an agent that labels and assigns open GitHub issues:

- `observe` fetches the current`state` , like the open issues that still need triage.
Usually this is plain code calling an API. If fetching the data directly is cumbersome or
finding the right context takes judgment, it can ask a model to use read-only tools
instead.
- `decide` compares`state` against your prompt or rules and returns a`plan` as plain data,
like which labels and owners each issue should get. You can write it in ordinary code, or
call an LLM or a decision model.
- `apply` carries out`plan` and makes the changes on GitHub. Depending on the job, it runs
the steps directly or hands them to subagents or a swarm.
- `report` turns`result` into a summary and handles notifications, like posting what
changed to Slack.

In a typical tool-calling loop, the model reads state and mutates it in the same turn. You
can’t see what it’s about to do before it acts. Splitting `decide` from `apply` gets you
closer to [functional core, imperative shell](https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell). Calling a model over the network means
`decide` isn’t strictly pure, since you still have I/O and non-determinism. Still, it never
modifies the system you’re managing, and every change happens in `apply`. Because the plan
is plain data, I can log it before anything runs or skip `apply` for a dry run. I can also
replay recorded state through `decide` in tests.

One call to `reconcile` is a single pass, which is enough for an agent behind an API
endpoint. Put the same function on a schedule and it becomes a loop. As long as `observe`
sees the effect of `apply` on the next run, the agent doesn’t need its own state or
checkpointing. Say that GitHub triage agent crashes halfway through a run. GitHub holds the
state, so the next run just finds whichever issues are still unlabeled and finishes the job.

If you want to see how this looks in real code, I have put together a single-pass example in
[this gist](https://gist.github.com/rednafi/2a6ba6ae79f935f6e011df9377fb57e9). It’s an agent written with the AWS Strands SDK that finds the most
controversial stories on Hacker News and summarizes them.

Outside of software, I’m also building an agent that moves the arms of a servo robot, and this loop fits each individual movement perfectly. Maybe I’ll write about it at some point.
