The State Problem in AI Agents
I recently had an interesting exchange with Martin Casado about the reliability of AI agents operating across third-party systems.
Martin raised several fundamental questions: how do we know whether a crash has left a system in an inconsistent state? How do we achieve transactional guarantees across multiple updates? How do we verify mutable state, and how do we handle race conditions when other actors can modify that state?
My initial argument was that one could partially address the state problem by not letting the language model own the state at all. Instead, the workflow could be represented as an explicit state machine, with the model selecting transitions.
But this addresses only one dimension of the problem. Knowing where an agent is in its workflow is different from knowing where the external world is in relation to that workflow.
The more I think about this distinction, the more I believe that the reliability problem in autonomous agents sits at the intersection of distributed systems, control theory and computational logic.
Why coding agents work relatively well
Coding is an unusually accommodating environment for autonomous agents.
Over several decades, software engineers have built an ecosystem of primitives that make software development observable, verifiable and recoverable:
- Git provides version history, diffs and mechanisms for reverting changes.
- Compilers and type systems enforce structural constraints.
- Tests provide executable specifications of expected behaviour.
- Containers provide reproducible execution environments.
- CI systems provide independent verification.
- Logs and debuggers expose internal system behaviour.
A coding agent does not need to invent these primitives. It inherits them.
When an agent modifies a repository, we can inspect what changed, run tests, compare versions and, within the repository, revert undesirable changes. This does not guarantee correctness, but it gives the agent an environment in which correctness can be investigated.
Now imagine an agent managing procurement across a company’s ERP, email, banking platform and supplier portal.
There is no shared Git history. There is no universal rollback mechanism. There may not even be a consistent representation of the same purchase order across all four systems.
Each system maintains its own state, operates under different consistency guarantees and may be independently modified by humans or other agents.
The agent is no longer simply solving a reasoning problem. It is participating in a distributed system.
1. Separating workflow state from world state
Consider an agent tasked with paying a supplier invoice and updating the corresponding accounting records.
Its internal workflow might look something like this:
Invoice received → Invoice verified → Payment initiated → Payment confirmed → Accounting updated.
Representing this workflow as a persistent state machine is useful. It allows the application to constrain transitions, inspect progress and recover its execution history.
But suppose the agent initiates the payment and crashes before recording the confirmation.
When it restarts, its internal state says that payment has not been confirmed. The bank, however, may have successfully processed it.
If the agent simply resumes from its last recorded state and repeats the operation, it risks paying the invoice twice.
We therefore need to distinguish at least four kinds of state:
- Desired state: What the agent is attempting to achieve.
- Execution state: What operations the runtime has initiated or recorded.
- External state: What has actually happened in the systems being controlled.
- Observed state: What available evidence tells us about those systems.
External state and observed state are not necessarily the same. Observations can be delayed, incomplete or incorrect.
An explicit state machine is necessary for many reliable workflows, but its transitions must be grounded in external evidence.
2. Borrowing from distributed systems
Many of the failure modes we are encountering in autonomous agents are not new.
Distributed systems engineers have been dealing with crashes, partial failures, duplicate messages and concurrent modifications for decades.
There are several established primitives we can borrow.
Durable execution and intent logging
Before performing a consequential external operation, the runtime should persist its intent, including a unique operation identifier, its parameters and the expected outcome.
If the runtime crashes, it can recover not only what it believes was completed, but also what it attempted to do.
Systems such as Temporal provide durable workflow execution, although durability alone does not guarantee that external side effects occur exactly once.
Idempotency
Where supported, external operations should carry stable idempotency keys.
If a payment request times out, repeating it with the same key should not result in a second payment, provided the payment service honours the idempotency contract.
Retries become substantially safer without requiring the model to reason about whether an earlier network request succeeded.
Optimistic concurrency control
Multiple agents and humans may modify the same external resource.
Instead of blindly overwriting it, an agent can make its operation conditional on the resource still being at the version it previously observed.
Compare-and-swap operations, versioned writes and HTTP conditional requests are established mechanisms for doing this.
HTTP’s If-Match header, for example, allows a client to condition an update on the resource’s entity tag.
A version conflict becomes an explicit event that the runtime can handle rather than a silent loss of somebody else’s changes.
Distributed transactions and compensating actions
When multiple systems support a compatible transaction protocol, distributed atomic commit may be possible.
But arbitrary SaaS applications rarely participate in a common transaction manager.
An alternative is the Saga pattern, introduced by Hector Garcia-Molina and Kenneth Salem in 1987. A long-running operation is decomposed into smaller transactions with corresponding compensating actions.
If one operation fails, previously completed operations can, where possible, be compensated for.
Cancelling a reservation or issuing a refund are examples of compensation. They are not necessarily equivalent to rolling back the original operation.
An email that has already been read cannot be unread. Information that has been disclosed cannot be undisclosed.
This distinction matters when designing autonomous systems.
3. Thinking about agents as controllers
Perhaps a more useful architectural inspiration for general-purpose agents is Kubernetes.
Kubernetes does not simply issue a series of commands and assume that they have succeeded. Its controllers repeatedly observe the system and attempt to reconcile its current state with a declared desired state.
If a controller is responsible for maintaining three replicas of an application, it does not need to treat the creation of three processes as the end of its responsibility.
It continues observing the environment and acts when the desired condition is no longer satisfied.
This is fundamentally a closed-loop control architecture.
I think autonomous agents could benefit from a similar model:
- Establish the desired state.
- Observe the external environment.
- Determine the difference between the observed and desired states.
- Select an authorised action.
- Execute the action with appropriate safeguards.
- Observe its effects.
- Reconcile any discrepancies.
The language model becomes one component of this system, rather than the system itself.
The important difference is that Kubernetes operates within a relatively well-defined environment with structured resource representations and established interfaces.
General-purpose agents operate in much less accommodating environments. Their observations may consist of browser pages, emails, API responses, documents or even images from the physical world.
This introduces another fundamental problem: verification.
4. Verification is not the same as execution
An API returning HTTP 200 does not necessarily mean that a business objective has been achieved.
A browser displaying a success message does not necessarily establish that a corresponding transaction has settled.
An agent reporting that it completed a task is not independent evidence that the task was completed correctly.
The execution layer needs to distinguish between an action being attempted, acknowledged and verified.
In practice, this means defining explicit preconditions, postconditions and invariants.
A precondition determines whether an operation is permissible.
A postcondition establishes what must be true after the operation.
An invariant describes a property that must remain true throughout the workflow.
For an invoice-processing agent, these might include:
- The invoice must not have been paid previously.
- The payment must correspond to an authorised supplier.
- The amount must not exceed the approved amount.
- The accounting record must reference the corresponding payment.
- Unrelated financial records must remain unchanged.
Where these conditions can be expressed over reliable structured data, deterministic software should evaluate and enforce them.
The more interesting problem arises when the evidence itself is incomplete, heterogeneous or unstructured.
5. The role of logic models
Consider a simple business rule:
An invoice can be paid if it is valid, and either a manager has approved it or its value is below the pre-authorised threshold, provided the supplier is not blocked.
The rule can be represented as:
Valid AND (Approved OR BelowThreshold) AND NOT Blocked
Now assume the following observations:
- Invoice validity: True
- Manager approval: Unknown
- Below the threshold: True
- Supplier blocked: False
Despite incomplete information, the overall rule can be evaluated as true. The missing manager approval is irrelevant because the alternative authorisation condition is satisfied.
If the invoice were above the threshold, the missing approval would become material and the result would be unknown.
This distinction is important.
An autonomous agent should not necessarily stop whenever information is missing. It should stop when the missing information prevents it from establishing a required condition.
Three-valued logic gives us a useful conceptual foundation:
- True: Available evidence establishes the condition.
- False: Available evidence contradicts the condition.
- Unknown: Available evidence is insufficient to establish either.
There is already substantial research around three-valued semantics and runtime verification of partially observed systems.
At Polygramme, we have been exploring a related architectural idea: separating logical evaluation from decision-making through specialised logic models.
A reasoning model may determine what it wants to achieve and propose an action. A logic model could evaluate whether the available evidence satisfies the conditions required for that action.
The application, rather than either model, retains the authority to execute it.
For structured and fully specified problems, conventional symbolic logic may be entirely sufficient. The potential advantage of a specialised model is its ability to interpret and evaluate conditions over heterogeneous real-world evidence.
This is a research hypothesis that needs to be tested, particularly against deterministic approaches and general-purpose language models.
A learned logic model is not a formal proof system simply because it evaluates logical expressions.
6. The out-of-band control problem
Another interesting issue Martin raised was the possibility of an agent exploiting its own evaluation mechanism or reporting success without actually achieving the objective.
This is particularly relevant as agents become more autonomous.
If the same system is responsible for executing a task, collecting the evidence and declaring that the task succeeded, it can potentially manipulate the entire feedback loop.
Introducing another language model as a reviewer may help, but two models can share the same blind spots.
A stronger architecture separates execution from verification wherever possible.
The verification layer should have independent access to authoritative observations, and the acting agent should not be able to modify the criteria by which its own success is measured.
For a payment, this might mean independently retrieving the transaction record from the payment provider.
For a physical device, it might mean using independent sensor observations rather than relying exclusively on the command acknowledgement.
For a coding agent, it might mean running protected tests that the agent cannot modify.
Independence matters more than simply increasing the number of agents involved.
7. The limits of what an agent runtime can guarantee
There is an important boundary to all of this.
An agent cannot manufacture guarantees that the systems it interacts with do not provide.
If an external system offers no idempotency mechanism and no reliable way of determining whether an operation succeeded, the agent cannot always distinguish between a lost request and a lost acknowledgement.
If an external system does not support conditional writes, reading its state immediately before an update does not eliminate the possibility of a concurrent modification.
If multiple systems do not participate in a common transaction protocol, an orchestration layer cannot unilaterally make their operations atomic.
Even a perfect logic evaluator cannot establish facts that are fundamentally unobservable.
A reliable agent architecture must therefore represent uncertainty explicitly and distinguish between guaranteed, inferred and unknown outcomes.
Sometimes the correct behaviour is to suspend execution, gather additional evidence or escalate to a human.
The objective is not uninterrupted autonomy. It is dependable autonomy.
8. Towards a control plane for autonomous agents
Putting these ideas together, I can imagine an architecture consisting of five distinct layers:
| Layer | Responsibility |
|---|---|
| Reasoning | Understand objectives, construct plans and propose actions. |
| Durable execution | Maintain workflow state, operation history and recovery mechanisms. |
| Transaction management | Enforce idempotency, concurrency controls and compensation where supported. |
| Observation | Collect independent evidence about external state. |
| Logical verification | Evaluate preconditions, postconditions and invariants against that evidence. |
The reasoning layer can be probabilistic. The execution layer should enforce explicit policies. The verification layer must expose uncertainty. The observation layer determines how much can actually be known about the world.
Such an architecture would also provide a more meaningful basis for evaluating autonomous agents.
Rather than measuring only task completion, we should measure duplicate side effects, invariant violations, recovery after crashes, behaviour under concurrent modifications, false declarations of success and the ability to recognise insufficient evidence.
An agent that completes 95% of tasks but silently corrupts external state in some of the remaining cases may be considerably less useful than an agent that completes 85% and reliably escalates the rest.
Conclusion
The evolution of coding agents offers an interesting lesson.
We have spent decades building infrastructure around software development that makes changes observable, testable, recoverable and, within certain boundaries, reversible. Language models have arrived in an environment that already provides much of what autonomous systems require.
Outside software development, that infrastructure is fragmented or missing altogether.
Better reasoning models will undoubtedly improve autonomous agents. But reasoning capability alone cannot resolve inconsistent state, prevent concurrent modifications or independently establish that an external operation has succeeded.
We need to build systems in which intelligence operates inside an architecture of explicit guarantees.
Some of those guarantees can come from decades of distributed systems research. Others may require new interfaces to the external world, better observation mechanisms and specialised models for logical verification.
We have spent the last few years giving AI models the ability to act.
The next challenge is giving the systems around them the ability to establish what those actions actually accomplished.
Further reading
- Hector Garcia-Molina and Kenneth Salem, Sagas, 1987.
- Jim Gray and Leslie Lamport, Consensus on Transaction Commit, 2006.
- Kubernetes, Controllers and the reconciliation pattern.
- Temporal, Activities and durable execution.
- AWS Builders’ Library, Making retries safe with idempotent APIs.
- IETF, RFC 9110 — HTTP Conditional Requests.
- Andreas Bauer, Martin Leucker and Christian Schallhart, Runtime Verification for LTL and TLTL, 2011.