Skip to main content

Semarun

Durable execution replays your agent. Semarun remembers what it learned.

Python 3.11+ License: MIT PyPI

Semantic checkpointing runtime for long-running Python agents.
Pause for hours, survive crashes and deploys, resume under a different model or tool result — without redoing completed work or corrupting intent.


```python from semarun import SemarunRuntime, ContinuationPolicy

runtime = SemarunRuntime() run = runtime.create_run( intent="Complete onboarding outreach sequence", plan=["research lead", "draft email", "request approval", "send email"], continuation_policy=ContinuationPolicy( on_tool_drift="revalidate", on_model_change="resume_with_warning", on_user_change="replan", ), )

with run.step("tool_call", name="crm_lookup") as step: result = crm.lookup("lead_42") step.set_tool_result("crm_lookup", result, hash_exclude=["created_at", "request_id"])

with run.step("llm_call", model="gpt-4.1-2026-07"): run.state.working_memory["draft_email"] = llm.generate(...)

run.request_approval(action="send_email", payload={"draft": run.state.working_memory["draft_email"]})

... process exits, days pass ...

run = runtime.resume(run.id) report = run.detect_divergence(fresh_tool_results={"crm_lookup": fresh_crm_data}) action = run.apply_continuation(report)


Naive restart (step 7 crash): ████████ 8 LLM calls Semarun resume: █ 1 LLM call


## The Problem

- Agents crash, deploy, wait for humans, and change models — replay-first systems cannot handle semantic drift.
- Re-running from step 1 wastes tokens, time, and corrupts intent.
- You need **semantic resumption**, not transcript replay.

## Performance & Overhead

[Semarun Overhead Stats] • Checkpoint Snapshot Latency: ~1–8 ms (SQLite local write) • Memory Overhead: < 4 MB resident set size • Token Savings on Resume: Up to 98% of prior execution steps


*Measured locally on developer hardware. Benchmark scripts are not shipped in the public repo.*

LLM API calls take **1,000–3,000+ ms**. Semarun adds **<10 ms** per step boundary — zero noticeable lag to the agent loop.

In an **8-step agent run where step 7 fails**, Semarun resumes from the last checkpoint, saving **~75%** of execution cost and time versus a full restart.

## Where Semarun Sits in the Stack

### Layer 1 — Durable Execution Engines

| Tool | Role | Semarun contrast |
|------|------|-------------------|
| **Temporal** | Distributed workflow orchestration with replay | Requires separate workers/server daemons; replay-first, not semantic |
| **Restate** | Event-driven durable execution with journaled logs | Zero-infrastructure alternative: Semarun runs in-process, no external daemon |
| **Prefect / Dagster** | Python data orchestrators (ETL, caching, retries) | Pipeline-scale orchestration vs fine-grained agent turn state + semantic hashing |
| **Inngest** | Event-driven serverless step functions | Serverless workflow retries vs local-first semantic checkpointing |

> Unlike heavy distributed orchestrators (Temporal, Restate) that require separate workers or server daemons, Semarun is an **in-process, zero-dependency Python runtime** for local-first agent state.

### Layer 2 — Agent Frameworks & Orchestrators

| Tool | Role | Semarun contrast |
|------|------|-------------------|
| **LangGraph** | Graph checkpointing + memory savers | Flexible checkpoint/divergence kernel for custom Python loops |
| **PydanticAI** | Pydantic-native agent framework | Shared philosophy: strongly-typed state; Semarun is the durable runtime underneath |
| **CrewAI / AutoGen** | Multi-agent message orchestration | Deterministic state hashing + resumption beneath multi-agent conversations |
| **LlamaIndex Workflows** | Event-driven agent execution loops | Plugs in as semantic state + drift handler |

> Works alongside or inside your favorite agent loops (LangGraph, PydanticAI, CrewAI) to handle semantic replay, tool drift, and state resumption.

### Layer 3 — Storage, Memory, & Cache

| Tool | Role | Semarun contrast |
|------|------|-------------------|
| **SQLite / DuckDB** | Local embedded databases | Primary default backend — zero-infra snapshot persistence |
| **Mem0 / Zep** | Long-term semantic memory (RAG, chat history) | Mem0 = long-term user facts; Semarun = runtime execution state + tool checkpoints |
| **LMDB / RocksDB** | High-throughput KV stores | Future optional backend for ultra-fast filesystem persistence |
| **Redis** | Generic KV cache | Code-level execution checkpoints with semantic hashing, not generic KV |

> Semarun manages **runtime execution drift**—not long-term chat memory (like Mem0) or KV caching (like Redis). It bridges execution history directly to local disk (SQLite) or cloud stores.

### Layer 4 — Serving & Observability

| Tool | Role | Semarun contrast |
|------|------|-------------------|
| **SGLang / vLLM** | High-performance LLM serving (KV cache, RadixAttention) | Application-level equivalent: checkpoints Python code + tool states, not model KV tensors |
| **Arize Phoenix / OpenInference** | Agent tracing + evaluation | Audit events align with OpenInference-style traces for time-travel debugging |

### Landscape / Alternatives

| Category | Tool | How Semarun Differs |
|----------|------|----------------------|
| Durable Execution | Temporal / Restate | Zero daemon processes; runs entirely in-process inside Python. |
| Agent Frameworks | LangGraph / CrewAI | Framework-agnostic runtime kernel; focuses strictly on state & hashing logic. |
| State & Caching | Redis / Mem0 | Designed for code-level execution checkpoints and tool drift, not generic KV or facts. |
| Inference | vLLM / SGLang | Caches and checkpoints high-level Python code/tool states rather than model KV-tensors. |

## How It Works

```mermaid
flowchart LR
    Run[Run] --> Step[Step]
    Step --> Checkpoint[Checkpoint]
    Checkpoint --> Pause[Pause]
    Pause --> Divergence[Divergence Detect]
    Divergence --> Resume[Resume]
    Resume --> Transparent[Transparent]
    Resume --> Revalidated[Revalidated]
    Resume --> Replan[Semantic Replan]
Resume Mode When Behavior
Transparent No divergence Continue exactly where you left off
Revalidated Tool drift, stale evidence, model change Re-run flagged tools/facts before proceeding
Semantic replan Intent/plan conflict, rejected approval Preserve goal and facts; rebuild path

Checkpoint example

{
  "run_id": "run_abc123",
  "intent": "Complete onboarding outreach sequence",
  "status": "paused",
  "plan": ["research lead", "draft email", "request approval", "send email"],
  "working_memory": { "draft_email": "Hi Jane..." },
  "established_facts": [
    { "fact": "Lead is at Company X", "source": "crm", "confidence": 0.94 }
  ],
  "pending_actions": [{ "type": "human_approval", "action": "send_email" }],
  "tool_state": {
    "crm_lookup": { "status": "success", "result_hash": "abc123...", "hash_exclude": ["created_at"] }
  },
  "continuation_policy": {
    "on_tool_drift": "revalidate",
    "on_model_change": "resume_with_warning",
    "on_user_change": "replan"
  }
}

API Reference

Method Purpose
SemarunRuntime() Create runtime (SQLite default)
runtime.create_run(...) Start a new agent run
runtime.resume(run_id) Load latest checkpoint and resume
run.step(type, name=...) Context manager for step boundaries
step.set_tool_result(name, result, hash_exclude=[...]) Record tool output with semantic hash
run.checkpoint() Force a semantic snapshot
run.pause() Pause run and checkpoint
run.request_approval(action, payload) Human approval gate
run.detect_divergence(...) Compare environment vs checkpoint assumptions
run.apply_continuation(report) Apply continuation policy
run.replan(preserve_intent=True) Semantic replan mode
run.export_checkpoint_json(path) Export raw checkpoint JSON for debugging

Examples

python examples/outreach_agent.py

End-to-end demo: CRM lookup → LLM draft → approval gate → resume with tool drift detection.

Install & Development

pip install semarun
# or from source:
pip install -e ".[dev]"
pytest

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semarun-0.1.0.tar.gz (81.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semarun-0.1.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file semarun-0.1.0.tar.gz.

File metadata

  • Download URL: semarun-0.1.0.tar.gz
  • Upload date:
  • Size: 81.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for semarun-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8fbc9c504f5c061707563ea9db395a89a81cda16a52f45ac3a42a1e2b0ea1171
MD5 0394587162de336f95d1078ba182772d
BLAKE2b-256 24b14f531b38dc006eb2abe8ac6f682890622646048643ea7f1cd5bac0a47c5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for semarun-0.1.0.tar.gz:

Publisher: publish.yml on rockybalboan19/SemaRun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file semarun-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: semarun-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for semarun-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 391b7e574a010c38a3860c88d65656be2fbb89e9168bb3dafd236ce20a8be87f
MD5 14687c92ffb90bc294d780cd872f9cf4
BLAKE2b-256 798218af1b6327640ae56e8048da88f472d5984e57b03c39bf0b5ba46d782ccd

See more details on using hashes here.

Provenance

The following attestation bundles were made for semarun-0.1.0-py3-none-any.whl:

Publisher: publish.yml on rockybalboan19/SemaRun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page