Josh Purtell says stateful environments fix agent derailment

AI Engineer////2 min read

Architecture for Long-Horizon Agency

Developing AI agents for specialized fields like finance or healthcare requires more than simple tool-calling. Josh Purtell, founder of Synth, argues that we must move away from clumping logic within the agent itself. Instead, developers should implement stateful environments: external engines that compute results and maintain a persistent "system of record" independent of the AI model. This separation ensures that as Claude 3.5 Sonnet or future models emerge, the core business logic remains intact while the agentic "brain" is swapped out.

Josh Purtell says stateful environments fix agent derailment
Stateful environments for vertical agents — Josh Purtell, Synth Labs

Prerequisites and Key Tools

To build these systems, you should be comfortable with asynchronous programming and the concept of containerization. Historically, this draws from RL Glue and the OpenAI Gym. Modern implementations often utilize MCP (Model Context Protocol) for tool use. For those looking to dive into the code, Synth Laboratories maintains an open-source repository called Environments which provides a unified interface for benchmarks like SWE-bench.

Code Walkthrough: The Network Boundary

A critical component of a stateful environment is the network boundary. By running the environment in a separate process, you enable reliable multi-agent collaboration.

# Conceptualizing the Environment Interface
class StatefulEnvironment:
    def __init__(self, initial_state):
        self.state = initial_state

    def step(self, action):
        # Compute results external to the agent
        self.state = self.apply_logic(self.state, action)
        return self.observe_state()

    def reset(self):
        # Revert to a known good state
        self.state = self.get_checkpoint()

This structure allows the agent to observe and manipulate a representation of the system—such as a terminal view—rather than the entire underlying operating system. This abstraction reduces cognitive load on the model and prevents hallucinations by grounding the agent in a concrete, computable reality.

Resetting the Path to Success

The most powerful advantage of this architecture is the ability to perform rollbacks. When an agent gets "derailed" during a complex task, a stateful environment allows for Language Agent Tree Search. Similar to how an agent playing Minecraft might branch out in multiple directions, you can programmatically identify the most successful branch, reset the environment to that specific state, and proceed. This makes long-horizon tasks—those requiring hundreds of steps—actually viable in a production setting.

Topic DensityMention share of the most discussed topics · 11 mentions across 11 distinct topics
Claude 3.5 Sonnet
9%· products
Environments
9%· products
Josh Purtell
9%· people
MCP
9%· products
Minecraft
9%· products
Other topics
55%
End of Article
Source video
Josh Purtell says stateful environments fix agent derailment

Stateful environments for vertical agents — Josh Purtell, Synth Labs

Watch

AI Engineer // 6:51

We turn high signal in-person events for the top AI engineers, founders, leaders, and researchers in the world into the best free learning opportunities for millions around the world here on YouTube. Your subscribes, likes, comments, speaking, attendance, or sponsorships goes a long way toward making our biz model sustainable indefinitely. We strongly believe this industry deserves a better class of community and that we know how to do this well; we just need your support.

Who and what they mention most
Anthropic
26.9%21
Claude
21.8%17
OpenAI
19.2%15
Cursor
15.4%12
2 min read0%
2 min read