DEV Community

hhhfs9s7y9-code
hhhfs9s7y9-code

Posted on

We Open-Sourced a 500-Line Python Module That Solves Agent Crash Recovery

We Open-Sourced Our Agent Checkpoint Module

Problem: Your 12-step agent crashes at Step 11 → you restart from Step 1, burning API calls and time.

Solution: 500 lines of Python, zero dependencies.

The Core Implementation

from nb_checkpoint import Checkpoint

cp = Checkpoint("research-agent")
result = cp.pipeline([
    ("search",   lambda ctx: client.chat("Search quantum papers").text),
    ("extract",  lambda ctx: client.chat(f"Extract from: {ctx[x27searchx27]}").text),
    ("summarize", lambda ctx: client.chat(f"Summarize: {ctx[x27extractx27]}").text),
])
Enter fullscreen mode Exit fullscreen mode

Crash at "extract"? Next run auto-resumes from Step 2. Zero wasted calls.

How It Saves Money

Assuming ¥0.01/DeepSeek call, 10-step agent:

Scenario Calls wasted/day Monthly cost
Without Checkpoint (1 crash/day) 10 extra calls ¥300/month
With Checkpoint ~0 ¥0 extra

For teams running 100+ agents daily, this is real money.

Three APIs

Step API (most flexible):

cp = Checkpoint("research-agent")
papers = cp.step("search", lambda: client.chat("Search quantum").text)
analysis = cp.step("analyze", lambda: client.chat(f"Analyze: {papers}").text)
Enter fullscreen mode Exit fullscreen mode

Pipeline API (simplest):

result = cp.pipeline([
    ("search",   lambda ctx: client.chat("Search quantum").text),
    ("analyze", lambda ctx: client.chat(f"Analyze: {ctx[x27searchx27]}").text),
    ("report",  lambda ctx: client.chat(f"Report: {ctx[x27analyzex27]}").text),
])
Enter fullscreen mode Exit fullscreen mode

AgentSession (ready to use):

from nb_checkpoint import AgentSession

session = AgentSession(
    "research-agent",
    llm_call=lambda prompt: openai.ChatCompletion.create(
        model="gpt-4", messages=[{"role": "user", "content": prompt}]
    )["choices"][0]["message"]["content"]
)
Enter fullscreen mode Exit fullscreen mode

vs LangChain Checkpoint

NB Checkpoint LangChain
Dependencies Zero LangChain required
API Step / Pipeline / AgentSession StateGraph only
Lines of code ~500 ~5000+

Install Now

pip install nb-checkpoint
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/neuralbridge-sdk/nb-checkpoint

Top comments (0)