finnvoor/PiDurableKit

Durable AI agents for Apple platforms: pi-durable on JavaScriptCore with a Swift API

What it solves

Mobile apps on Apple platforms can be killed at any time — when backgrounded, low on memory, or closed by the user. For an AI agent that is mid-conversation or mid-tool-call, that means lost progress and broken workflows. PiDurableKit makes agent work durable: conversations, model turns, tool calls, and your own state are committed to storage before anything is shown. If iOS kills your app mid-turn, reopening the storage picks the work up where it stopped.

How it works

PiDurableKit is a Swift library powered by the pi-durable runtime (from @earendil-works) running inside JavaScriptCore. You configure a set of models (Anthropic, OpenAI, Google, OpenRouter, Groq, xAI, Mistral, or any OpenAI/Anthropic-compatible server), a storage backend (SQLite, JSONL, or in-memory), and open a harness. Every submission, tool call, subagent action, and task checkpoint is written atomically to storage before the user sees any output. Tools, system prompt sections, hooks, and wraps are written as plain Swift closures. For more control, durable tasks are modelled as named phases with checkpoints; if a crash happens, only the last committed checkpoint needs to re-run. JavaScript extensions written for pi-durable install unchanged as CommonJS modules, and a built-in code mode runs JavaScript scripts in a QuickJS sandbox (bundled as WebAssembly) that survive restarts by replaying from a journal. Streaming AsyncSequences provide conversation views for SwiftUI and coding-agent style events.

Who it's for

Swift developers building LLM-powered agent apps for iPhone, iPad, Mac, tvOS, or Vision Pro that need to survive app interruptions, handle long multi-step workflows, and support many model providers out of the box. Requires iOS 17, macOS 14, tvOS 17, or visionOS 1.

Highlights

  • Durability by design: conversations, model turns, tool calls, and your own state are committed to storage before anything is shown; reopening storage after a crash resumes work
  • Plain Swift closures for tools, hooks, prompt sections, and wraps — no DSL required
  • Durable tasks with named phases, checkpoints, idempotency keys, and memo values that survive reruns
  • Subagents and durable child tasks: abort a call and the child aborts; a crash-rerun finds the same child
  • Atomic transactions over any set of reads and writes (conversations, forks, entries, tasks, documents)
  • Streaming AsyncSequences of conversation views for SwiftUI and coding-agent style events
  • OAuth sign-in for Claude Pro/Max, ChatGPT, GitHub Copilot, and OpenRouter, with tokens in the Keychain and automatic refresh
  • JavaScript extensions from pi-durable install unchanged as CommonJS modules
  • Nested tool calls with structured output for programmatic results
  • Code mode runs durable JavaScript scripts in a QuickJS sandbox (WebAssembly) that replay from a journal after restart

Related

  • Project
  • Project
  • Project
  • Project