AI Engineer World's Fair 2025
Stateful environments for vertical agents — Josh Purtell, Synth Labs
Read the talk
Stateful environments for vertical agents
Separate an agent’s decisions from the application state it changes, so models can be replaced, work can be shared, and failed trajectories can be rolled back.
From a talk by Josh Purtell
Before you start: Familiarity with tool-calling agents and the distinction between application state and model context will help.
Where should an agent’s working state live?
When an agent works in finance, accounting or health, where should the application’s state and task logic live? Putting everything inside the agent makes those concerns difficult to separate as the system grows. Josh Purtell, introducing himself as Synth’s founder, calls the alternative a stateful environment: a workspace that captures state for the agent, with application logic organized separately from its decision-making.
This separation has a long history in reinforcement learning. The task specifies what the AI should accomplish without prescribing every action; the environment contains the task’s logic, while the learning algorithm decides how to act. RL-Glue was an early standard interface for that separation, followed in Purtell’s account by OpenAI Gym. These are precedents for the architecture, rather than a claim that RL-Glue originated all environment interfaces.
Software engineering brings that idea closer to a vertical application. SWE-bench provides an evaluation framework for resolving repository issues; SWE-agent develops the agent-computer interface through which an agent navigates, edits and executes code. The shared idea is a contained workspace with an interface suited to the AI using it. Stateful environments build on that lineage.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
From answering a request to developing an artifact
A calculator call or a weather search needs little persistent workspace. Purtell contrasts those early language-model tools with richer API access, including interest in the Model Context Protocol. As tools become more capable, the agent can do more than return an answer: it can change something that subsequent actions depend on.
Purtell identifies Claude 3.5 Sonnet as a capability milestone for this shift. An agent can work on a product or artifact, inspect it, and improve it over successive steps. Claude Artifacts makes that persistent object visible in a web application. This is a progression in kinds of work, rather than release order: Sonnet and Artifacts arrived in June 2024, before MCP’s November announcement. The architectural pressure comes from maintaining a coherent object across a long sequence of actions.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Compute outside the agent, expose what it needs
The environment computes results outside the agent implementation. The agent requests a change; the environment owns the underlying work. That work might call an API, manipulate an Excel document, or compute against an external source of truth whose results enter a system of record. The model’s decision and the application’s computation become separate responsibilities.
Excel makes the interface problem concrete. Giving an agent the entire application exposes far more surface area than a particular task may require. Instead, an environment can expose a representation that the agent can observe and manipulate usefully. Purtell compares this to showing an agent the relevant terminal view instead of the whole operating system: the interface should make the required work accessible without exposing everything underneath.
A network boundary extends this separation beyond code organization. The agent and its environment can run in different processes, which is useful for reinforcement-learning training and for multiple agents interacting with a workspace. The agent-facing representation, the computation behind it, and the process hosting that computation need not be the same thing.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Recover state, then explore alternatives
Once working state has an explicit owner, reset and rollback become environment operations. A coding agent that derails can return to an earlier workspace instead of continuing from its accumulated mistakes. Recovery concerns the thing the agent changed, not just the messages describing its actions.
A small Python example makes that distinction concrete for the spreadsheet case. Here, the environment owns two cells and computes their total. It saves a checkpoint before an exploratory edit, then restores the cells after abandoning that edit.
python
from copy import deepcopy
class SheetEnvironment:
def __init__(self):
self.cells = {"A1": 100, "A2": 50}
def observe(self):
return {"cells": dict(self.cells),
"total": sum(self.cells.values())}
def set_cell(self, cell, value):
self.cells[cell] = value
return self.observe()
def snapshot(self):
return deepcopy(self.cells)
def restore(self, checkpoint):
self.cells = deepcopy(checkpoint)
return self.observe()
sheet = SheetEnvironment()
checkpoint = sheet.snapshot()
trial = sheet.set_cell("A2", 500)
restored = sheet.restore(checkpoint)
The trial state has A2 = 500; the restored state has A2 = 50, with A1 preserved. For a real environment, the checkpoint must cover the state needed for recovery. Restoring local cells does not automatically reverse a write already sent to an external system of record.
Recovery also enables search. Purtell points to Language Agent Tree Search, or LATS, and attributes its production implementation difficulty to missing environment abstractions. His description of getting it “for free” with a resettable environment is shorthand for removing a major obstacle: exploring an alternative requires returning to a comparable starting state. LATS still needs its search procedure, value estimation, reflection and environmental feedback; reset alone does not choose a good trajectory.
The Minecraft example shows how that capability is used:
- Start alternative trajectories from a shared point.
- Let the agent act along two branches.
- Compare the resulting progress.
- Select the better branch and continue from its state.
Purtell describes one branch as doing substantially better. The displayed terminal comparison shows Branch 1 and Branch 2, their action sequences and achievements, and a prompt asking which branch to continue. The useful result is the ability to retain a promising trajectory without remaining committed to the other one.
Purtell describes Minecraft tasks spanning hundreds or thousands of steps as a setting where rollback can help prevent derailment. That is his motivation for the example, rather than a measured trajectory length for the displayed run. The same need appears whenever an agent must sustain useful work over a long horizon: a bad stretch of actions should not force it to abandon everything that came before.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Finding environment implementations
Purtell closes by pointing builders to GitHub with the search phrase Synth AI Environments. He describes an open-source repository containing these abstractions and implementations across academic benchmarks—a place to examine how the environment boundary is expressed in working task interfaces.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
The 2009 paper explains the separation of agent, environment and experiment programs, including communication across process boundaries.
The historical introduction of Gym's common toolkit and environments for reinforcement-learning experiments.
Research on interfaces that help language agents navigate repositories, edit files and execute tests.
The original benchmark for resolving real GitHub issues by modifying existing codebases.
Anthropic's June 2024 announcement introduces Artifacts as a workspace for iteratively developing generated content.
The original introduction to MCP's client/server approach for connecting AI applications with tools and data.
Combines Monte Carlo Tree Search with language-model reasoning, reflection and environmental feedback.
Further reading
Official experiments, prompts and setup instructions for programming, HotPotQA and WebShop.
Read the complete timestamped transcript
- 0:00
[upbeat music] All right.
- 0:16
Hi, I'm Josh, founder of Synth. I help people make their agents a lot better. And over the last few months, uh, I found s-some patterns around structuring people's agent code that I think they've found very helpful and I've found very helpful for, you know, thinking about how to build effective agents, especially for vertical applications like finance,
- 0:41
accounting, health, um, and so on and so forth. So I like to call these stateful environments because they're environments that capture state for the agent.
- 0:51
So, um, let's define terms. What is an environment? Uh, it, it feels like a loose term, but it actually has quite a long history. People working on reinforcement learning tasks, which are really just tasks where you're trying to get the AI to do something, um, without stipulating how to do it, have been using environments to kinda containerize
- 1:11
the logic behind the task away from their AI algorithm for quite a while. So the first implementation was RL Glue, then OpenAI, back when OpenAI was an RL company and, and not really a language model company, came out with the OpenAI Gym.
- 1:26
And then most recently, probably the first kind of vertical-ish application in academic papers, uh, SWE-bench and SWE-agent, um, kinda coined the term of agent-computer interface. So people have been thinking about containerizing a kind of stateful, uh, workspace for AIs to have for, for quite a while.
- 1:47
This is not reinventing the wheel, we're just building on top of what o-people have already thought about.
- 1:53
Okay, um, so why are we adding on this abstraction of statefulness now? Well, two years ago, um, people mostly gave their LMs tools to calculate simple sums or, uh, you know, maybe search the internet for the weather.
- 2:12
You really didn't need to have a lot of clean, heavy-duty abstractions, um, for, for pretty simple logic like that. As models got better and people wanted them to use more effective tools, they moved to API-based tool use and, you know, maybe you see that with some people getting excited about MCP.
- 2:30
Um, and it wasn't really until models got a lot better with Sonnet 3.5 that people started, uh, kind of thinking about a wor- a, a product or an artifact that the AI works on and iterates on and improves step over step over a long horizon.
- 2:47
Um, and I think when Claude Artifacts came out is probably when a lot of people started thinking about having some abstractions to help agents like Claude work on product, um, and artifacts like Claude Artifacts in the web app.
- 3:03
So, um, that's kind of the impetus, the why now. Uh, so what are we contributing? Well, a stateful environment is an engine that computes results external to the agent implementation.
- 3:16
Um, the agent manipulates the environment somehow, but there's a lot of logic underneath that might involve, uh, accessing an API, working on, um, a-an Excel document or, or some kind of external, um, uh, you know, source of truth that gets computed on and goes into a, a system of record.
- 3:36
It can be a lot for an agent to interact with, uh, Excel though, like the entire application. So a stateful environment exposes a kind of representation or a version of that environment that the agent can, can make sense of, can observe, and, and manipulate, uh, usefully.
- 3:52
So you don't have to show the agent the whole, um, OS. You, you kind of just show it what it needs to see in the terminal. And then often, and this is important for people doing RL training, but it can also be really handy in multi-agent settings, network boundaries, um, so that your agent doesn't have to run
- 4:07
in the same process as whatever your stateful environment is.
- 4:12
Okay, um, so what does this get us? I help people improve their agents. Um, if you containerize the logic of your vertical app into code that never changes, it's a lot easier to completely revamp your agent when the new model comes out.
- 4:27
It's a lot harder to do that when all the logic is kind of just clumped together. Um, what else does it give you? Well, if you have a separate process de-determining your environment, um, that has standard network boundaries, you can easily have multi-agent and spin up new models, uh, or spin up new agents to work on this
- 4:46
single product together, um, across time and, and there's really no problems. People have thought about how to do asynchronous work, and the an- the answer to that question of how to do asynchronous work in a reliable way in production is network boundaries.
- 4:59
Um, and then I think the most exciting thing is once you have, um, this, this boundary, you can start doing things like, uh, resetting the state of the thing that your agent is working on.
- 5:09
You could do rollbacks. I think a lot of people working with agents in a co- in a code setting know how valuable it is to just be able to roll back the agent after it's kind of gotten derailed.
- 5:19
And if you have stateful environments, that's really easy to implement. And so in particular, um, the-- a few years ago, there was a paper called Language Agent Tree Search, um, that was, you know, really impressive and it got really good results, but it was almost impossible to implement in production because just nobody had really good, um, abstractions
- 5:38
for it. And, and techniques like this are really useful in a long-horizon setting, like a lot of builders care about today. Um, and if you have a resettable environment, you sort of get language agent tree search for free.
- 5:50
And so here's kind of a screenshot of, uh, a step in the tree search. The agent branched out in two directions while playing Minecraft. Um, one of those branches did a lot better, and then it's really easy to kind of just converge, pick the best branch, and go from there.
- 6:06
Um, and in a game like Minecraft where you have hundreds or thousands of steps, avoiding derailing and resetting like that can be really handy. Um, but maybe not just in Minecraft, also in, in kind of a lot of other settings where people are having their agents do a lot of work over long horizons.
- 6:23
Um, so if you'd like to see some implementations of stateful environments, you can go to our GitHub. There's an open source repository that captures a lot of these abstractions, and there's implementations across a lot of academic benchmarks.
- 6:37
Um, how do you find that? Look for Synth AI Environments. Um, and, and that's the talk. [upbeat music]