Durable execution replays your agent. Semarun remembers what it learned.
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
Metadata
Release files for semarun 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| semarun-0.1.0.tar.gz | 81.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| semarun-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 103.9 kB
Release files / semarun-0.1.0.tar.gz
| Download URL | semarun-0.1.0.tar.gz |
|---|---|
| Size | 81.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8fbc9c504f5c061707563ea9db395a89a81cda16a52f45ac3a42a1e2b0ea1171
|
|
BLAKE2b-256 checksum How to use checksums |
24b14f531b38dc006eb2abe8ac6f682890622646048643ea7f1cd5bac0a47c5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logRelease files / semarun-0.1.0-py3-none-any.whl
| Download URL | semarun-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
391b7e574a010c38a3860c88d65656be2fbb89e9168bb3dafd236ce20a8be87f
|
|
BLAKE2b-256 checksum How to use checksums |
798218af1b6327640ae56e8048da88f472d5984e57b03c39bf0b5ba46d782ccd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logSecurity for semarun 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for semarun-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.