Show HN: Agentfork – Replay an LLM agent from any step and test fixes A developer released agentfork, a local CLI tool that records every LLM and tool call in an agent run, replays earlier steps from cache, and sweeps many variants of a single step to produce pass rates instead of single-run anecdotes. In the tool's refund-agent example, a $49.99 order read from an API in cents ("amount": 4999) was refunded as $4,999 by the original prompt and by gpt-4o-mini and gpt-4o across 3 repeats each (0/3 pass), while adding one system-prompt sentence to divide cents by 100 fixed it at 3/3 pass for about $0.0001 per run. The tool installs via `pip install "agentfork-cli[openai]"` (or `agentfork-cli[anthropic]`), stores runs in `.agentfork/traces.db`, and supports LangGraph agents through `agentfork.wrap_langchain`; streaming models and the OpenAI Responses API are not yet recorded. Fork your LLM agent at any step, then sweep prompts, models or tool results to find what actually fixes it. When an agent misbehaves at step 3, the usual loop is: tweak the prompt, re-run everything, eyeball one output, repeat. That is slow, costs tokens on steps that didn't change, and one lucky run proves nothing. agentfork records every LLM and tool call, replays earlier steps from cache, and runs many variants of one step, several times each , so you get pass rates instead of anecdotes. Everything runs locally. No account, no server, no data leaves your machine. A refund agent reads "amount": 4999, "currency": "USD" from an order API. The amount is in cents, and the agent refunds $4,999 for a $49.99 laptop examples/refund agent cents.py https://github.com/bimal1023/agentfork/blob/main/examples/refund agent cents.py . Is the fix a better model or a better prompt? bash $ agentfork sweep 543da612 --step 3 --repeat 3 --expect "49.99" --model gpt-4o-mini,gpt-4o Estimated cost: about $0.0050 variant ok pass tokens time cost sample output original 1/1 0/1 446 1.7s $0.0001 I have processed a refund of $4,999.00... model=gpt-4o-mini 3/3 0/3 446 1.4s $0.0001 I have processed a refund of $4,999.00... model=gpt-4o 3/3 0/3 394 1.2s $0.0015 The full amount of $4,999.00 for order A123... A bigger model costs 15x more per run and doesn't fix it. One sentence in the prompt does: bash $ agentfork sweep 543da612 --step 3 --repeat 3 --expect "49.99" \ --system "You are a support agent. Look up the order, then refund the full order amount in USD." \ --system "... Order amounts from the API are in cents; divide by 100 before refunding." Estimated cost: about $0.0006 variant ok pass tokens time cost sample output original 1/1 0/1 446 1.7s $0.0001 I have processed a refund of $4,999.00... system 1 3/3 0/3 445 1.2s $0.0001 I've successfully refunded you $4,999.00... system 2 3/3 3/3 457 1.2s $0.0001 I have processed a refund of $49.99... Steps 1 and 2 replayed from cache in every run, so only the step that mattered was paid for, and the runs went 4 at a time. pip install "agentfork-cli openai " or agentfork-cli anthropic Add three things to your agent: python from openai import OpenAI from agentfork import trace, tool, wrap openai client = wrap openai OpenAI records every LLM call wrap anthropic for Claude @tool records every tool call def lookup order order id : ... @trace one run = one call of your agent def run agent question : ... Run your agent as usual. Each run is saved to .agentfork/traces.db . Wrap the chat model and put @agentfork.tool under LangChain's @tool . Forks and sweeps then work on the graph like on any other agent examples/langgraph refund agent.py https://github.com/bimal1023/agentfork/blob/main/examples/langgraph refund agent.py : python import agentfork from langchain core.tools import tool from langchain openai import ChatOpenAI from langgraph.prebuilt import create react agent llm = agentfork.wrap langchain ChatOpenAI model="gpt-4o-mini" or ChatAnthropic @tool @agentfork.tool def lookup order order id: str - str: """Look up an order by id.""" ... graph = create react agent llm, lookup order @agentfork.trace def run agent question : return graph.invoke {"messages": "user", question } "messages" -1 .content Streaming models streaming=True and the OpenAI Responses API aren't recorded yet. | Command | What it does | |---|---| | agentfork list | Recent runs with steps, tokens, duration and fork lineage | | agentfork show