replay-rag
Reasoning-trace memory for o1 / R1-style agents. Cuts output tokens 40-70% on repeated patterns.
What it is
Reasoning-trace memory for o1 / R1-style agents. Stores (problem → reasoning trace → answer) tuples; on a new problem, retrieves top-k similar past traces and splices the winning subtree into the new prompt as scaffolding.
Why it's needed
Reasoning models (o1, R1, Claude with extended thinking) burn 10-100× more output tokens than fast models. Most agentic workflows hit the same kinds of problems repeatedly - variations on the same arithmetic, the same retrieval strategy, the same debugging pattern. Every R1-style agent today re-derives reasoning it has already done. Memory systems in 2026 store answers - nobody has a memory system for the reasoning traces themselves.
What it does
replay-rag captures every reasoning call's trace + answer without side effects, then segments the raw text into typed segments (SETUP, EXPLORE, DECISION, BACKTRACK, VERIFY, ANSWER) using the markers reasoning models actually emit ('wait', 'actually', 'let me re-read') plus structural cues. Segments form a DAG with next and backtrack edges; decision points are extracted as the strategic skeleton. The crucial design choice - the embedding key is problem + decision-point summaries, not the raw trace - strips away surface form and keeps the strategic shape that should generalise across problems. On a new problem, the closest past traces' winning paths get spliced into the new prompt under a token budget.
How to use it
Install it:
git clone https://github.com/asmitdash/replay-ragThen call it:
from replay_rag import ReplayPipeline
pipe = ReplayPipeline() # captures, indexes, splices automatically
pipe.solve("Sum the first 100 primes.")
# next time, a similar problem retrieves the prior winning subtree:
pipe.solve("Sum the first 200 primes.") # spliced scaffolding cuts tokens 40-70%Links
- GitHub: github.com/asmitdash/replay-rag