Quickstart: add memory to a LangGraph agent
Install the retrack-ai connector, switch it on with one line, recall playbooks before each task and report outcomes. Five minutes, Python 3.10+.
Updated
This guide adds Retrack to an existing LangGraph or LangChain agent. By the end, every run is recorded, your agent receives playbooks before similar tasks, and Retrack knows which runs worked.
1. Get an API key
Sign in at retrack-ai.online with GitHub, create a project and copy its key. Keys start with rtk_live_.
2. Install the connector
pip install retrack-ai
export RETRACK_API_KEY="rtk_live_..."The package is retrack-ai on PyPI; you import it as retrack. It needs Python 3.10 or newer.
3. Switch Retrack on
Add one line at the top of the file where your agent starts:
import retrack
retrack.init(agent="support-agent") # one name per agent; reads RETRACK_API_KEYFrom then on every run of your LangGraph or LangChain agent is recorded, with no change to how you call it: the task, each tool call and its result, the final answer, tokens and the model. Obvious secrets (API keys, tokens, passwords) are stripped on your machine before anything is sent, and the server redacts again.
Only agent runs are recorded: a run that called a tool, or followed retrack.recall. A one-off prompt-and-model call elsewhere in your app is not.
4. Give your agent its memory
Just before the agent starts a task, recall memory for it and put it in the prompt:
memory = retrack.recall(task) # never raises; empty memory on any problem
result = graph.invoke({"messages": [("system", memory.as_prompt()), ("user", task)]})The recall is linked to that run, so Retrack learns which playbooks helped.
5. Tell Retrack what worked
Playbooks are only trusted when there is real evidence. Send a result whenever you know it, such as a passing test, a resolved ticket or a user's thumbs-up:
retrack.feedback(outcome="success", source="test") # the latest run; or source="event" / "feedback"With runs in parallel, pass the run: retrack.feedback(outcome="success", run_id=...). Without a signal, Retrack's AI judge scores the run.
6. Approve your first playbook
Successful runs become playbooks, which appear in the dashboard under Memory. A new playbook is a candidate: your agent does not use it until you open it and click Approve. That is the memory firewall at work: nothing an outsider could have influenced reaches your agent unchecked.
To let playbooks switch on by themselves after 3 confirmed successes of the same kind of task, Retrack must trust the runs. In your project's Settings, mark the tools whose output you control as trusted and, if task text never comes from end users, trust the task text too. See the memory firewall.
Expect your first playbook after a handful of successful runs of the same kind of task.
Prefer explicit control?
The same features are available per run. Choose the run id yourself and pass it everywhere, so the recall, the run and the feedback are linked:
import uuid
from retrack import Retrack
rt = Retrack("support-agent")
run_id = uuid.uuid4()
memory = rt.recall(task, run_id=run_id)
graph.invoke(
{"messages": [("system", memory.as_prompt()), ("user", task)]},
config={"callbacks": [rt.callback()], "run_id": run_id},
)
rt.feedback(run_id, outcome="success", source="test")LangGraph users can also add recall as a node: rt.recall_node(task_key="task", into="retrack_memory") reads state["task"] and writes the prompt text to state["retrack_memory"].
Configuration
| Setting | Default |
|---|---|
RETRACK_API_KEY | required (without it, capture and recall are off) |
RETRACK_BASE_URL | https://api.retrack-ai.online |
retrack.init(agent="agent", model_id="...", tool_versions={"stripe": "2026-09"}) records the model and tool versions; memory is matched to them, and a breaking tool version change stops old playbooks from being recalled.