~4m13:21
Swag

Pi Durable: как построить персистентного AI-агента

Oct 23, 2026

Read: ~4m · You save: 9 min

Pi Durable: How to Build a Persistent AI Agent

How to build an AI agent that runs 24/7, survives crashes, and remembers context. We cover Pi Durable and a Cloudflare + DeepSeek example.

Pi Durable is a framework built on the minimalist Pi agent that enables the creation of long-lived agents. Such agents operate without constant user involvement and recover from failures. The framework was released in October. It is designed for building custom agentic systems and integrating them into web applications.

What Pi and Pi Durable Are

Pi is an agent written in JavaScript. It is run locally, you give it prompts, and the agent sends requests to an LLM model and returns the responses. This is a classic agent.

Pi Durable adds persistent operation to this model. The agent can be deployed on a server, where it runs around the clock. A single agent can be accessed from several devices: a mobile app, a web app, or a terminal. Sessions are created in parallel, and each session is unique.

According to the author's assessment, Pi is among his three favorite agents. He places Open-Interpreter in first place, but notes that this project was recently hacked, so its position drops to third. The second place goes to an agent whose name is not legible in the source material, and Pi.

Comparison with Temporal and Cadence

Temporal and Uber Cadence allow you to manage persistent workflows that execute step by step. If one step fails, the workflow can be rolled back and restarted from that step.

Pi Durable implements similar durable execution only for its own agent. Temporal supports several languages: Python, Go, TypeScript, and Ruby.

Reliability Mechanisms

State Persistence and Recovery

Every agent step is persistent. Between steps, the state is saved to a lightweight database, which in the example is SQLite. After a page reload or the creation of a new process, execution continues from the point where the failure occurred.

Example sequence: the model requests a tool call, then context compaction takes place, then a failure occurs. In a regular agent, execution would have to start over. In Pi Durable, recovery happens from the last saved step.

Tool Re-execution

The tool itself decides whether to retry:

  • read operations marked as replay-safe are re-executed after a failure;
  • commands, such as a deployment, are not retried.

The tool determines which commands are safe to replay. This logic is built into the framework.

Exactly-Once and Idempotency

Every request has an identifier. A request that has already been sent is not repeated. This is how exactly-once delivery is achieved.

Persisting User Decisions

The framework stores confirmations and data provided by the user across sessions. If the user has answered "yes, deploy," the agent does not ask for confirmation again. The decision is stored in the agent's memory. The memo function is used for this.

Cancellation of Operations

Cancellation is implemented along an operation tree. When an operation is cancelled, the operations linked to it up the tree are cancelled as well.

Context Compaction and Dialogue Branching

Compaction runs in the background. When a dialogue reaches the limit, the context is compressed, and the conversation continues. Old messages are not deleted but are kept in compressed form within the context. The author draws an analogy with garbage collection in Java.

Dialogues can be branched. From any agent message, a fork is created, and the conversation continues in the new branch.

Architecture and Deployment

Pi Durable is written entirely in TypeScript and runs in any environment with a JavaScript runtime. It can be run in a browser or on a server. To operate, it is necessary to implement memory and storage primitives.

The framework supports versioning:

  • when redeployed, old sessions continue to run on the previous version of the agent;
  • new sessions start on the new version;
  • each workflow stores the version it was started with.

The author notes that the framework's minimalism and the use of a single language, TypeScript, make this version handling possible. Pi Durable contains about 15,000 lines of code. This makes it possible to hand the entire codebase to an agent and task it with extending the functionality.

Practical Example

The author deployed the Pi Durable service and named it Paidura (short for Pi Durable). The deployment was carried out with a single prompt sent to the Claude Opus 3.5 model. The prompt contained:

  • the task of building the Paidura service;
  • an instruction to deploy it on Cloudflare using the platform's primitives: Durable Objects, SQL, and others;
  • a link to the deployment description;
  • an instruction to use the DeepSeek model.

The second command was a request to deploy. The author then asked to add basic authentication (basic auth) to restrict access to the agent.

During the demonstration, the author:

  • opened a session in the web interface and named it;
  • sent the message "hello" and received a response;
  • stated that they live in London; the agent confirmed this;
  • asked about the weather; the agent called the get_weather function;
  • created a fork of the conversation and asked about the best pubs in the current city; the agent did not have a search tool, but it retained the context about London from the previous branch.

According to the interface, the cost of operation was $0.0005. The only paid component was the DeepSeek key. The service ran in the browser on Cloudflare's free tier.

The agent also connected the "get schedule" and "search history" tools. The author asked to send the current weather in five minutes. The agent created a task. Five minutes later the message arrived, even when all tabs were closed. The author also specified that the message should arrive in 30 seconds.

The agent can add its own MCP tools. The author suggests using it to create a tool that returns a list of pubs in London. The agent remembers the added tool.

Limitations

  • Pi Durable is an experimental project.
  • The framework is implemented in TypeScript.
  • Each process uses one storage unit, that is, one session.
  • Marking tools and MCP servers as replay-safe is the developer's responsibility. Unmarked tools are not protected from repeated execution.

Conclusions

Pi Durable allows you to deploy a persistent agent with state preservation, failure recovery, multi-client access, and versioning. The framework is suitable for building enterprise agents that can be invoked from messengers, mobile apps, and other clients. The reliability of execution depends on correctly marking tools as replay-safe.

Introduction

The author presents Pi Durable as a new version of the minimalist Pi agent, released in October, and explains why it is worth studying.

  • The episode covers how to build persistent agents using Pi Durable.
  • Pi is a minimalist JavaScript agent that the author uses; it ranks second on his list of favorite agents.
  • Pi Durable was released in October and is a harness for creating custom agent systems and integrating them into web applications.

What is Pi Durable

Pi Durable is a framework built on Pi for long-running agents that work unattended and recover on their own.

  • Regular Pi runs locally and sends requests to an LLM model.
  • Pi Durable can be deployed on a server and run around the clock (24/7).
  • The agent can be accessed from several places: a mobile app, a web app, and a terminal; sessions run in parallel and are unique.
  • The concept is similar to Temporal and Uber Cadence: persistent workflows with rollback and restart from the failed step.

Crash Recovery

Each step is saved to the database, so after a failure the agent continues work from the same place, and the tools decide whether the operation can be retried.

  • Example: model call, tool call request, compaction, then a failure.
  • A regular agent would have to be run from the beginning, whereas in Pi Durable the state is saved between steps to a small database (example — SQLite).
  • A new process continues work from the point of failure, even after a page refresh.
  • Tools marked as replay-safe (for example, reading) are retried on failure; commands (for example, deployment) are not retried.
  • Exactly-once delivery and idempotency are implemented via request ID: a repeated request is not sent.
  • Human confirmations (for example, “yes, deploy”) are saved between sessions and are not requested again; there is a “memo” feature.
  • Cancellation is implemented along the tree: a canceled operation cancels its parent operations.

Compaction, Forks, and Architecture

Compaction runs in the background, dialogues can be forked, the framework works in the browser and on the server, and agent versions are isolated.

  • Compaction happens in the background when the limit is reached; old messages are kept compressed in context, analogous to a garbage collector.
  • Dialogues can be forked and continued in another branch.
  • Pi Durable is written entirely in JavaScript/TypeScript and runs wherever a JavaScript runtime is available: in the browser or locally on a server.
  • To run it, you need to implement primitives: memory and storage, as well as a way to store sessions.
  • On redeploy, old sessions continue running on the previous agent version, while new sessions get the new version.
  • The framework is minimalistic: about 15,000 lines of code, so an agent can read and extend it on its own.
  • The framework is experimental; if there is a single process, it is one storage unit; marking tools and MCP servers as replayable is the developer's responsibility.

Example: Paidura on Cloudflare

The author deployed the Paidura agent on Cloudflare with a single Claude Opus prompt and demonstrated it in the browser: sessions, forks, weather, and scheduled tasks.

  • The service is named Paidura (short for Pi Durable) and is deployed on the .py domain.
  • The agent was created with a single prompt in Claude (Opus 3.5 version), then deployed with a deploy command; later, basic auth was requested to be added.
  • The Cloudflare deployment uses Durable Objects and SQL; the DeepSeek model is used.
  • The demo included a greeting, "I live in London", a weather request (get_weather function call), and a cost of about five ten-thousandths of a dollar.
  • The dialogue is forked after the assistant's last message; in the new branch the agent remembers that the user is in London but does not have a pub search tool.
  • The scheduled task "send the weather in five minutes" ran even when the chats were closed.
  • The agent can create MCP tools itself, for example, a list of pubs in London; Pi Durable remembers the added tools.