Framework Adapters
One-line instrumentation for LangChain/LangGraph, CrewAI, Vercel AI SDK, and more.
Framework Adapters
retrace.init() auto-patches the OpenAI / Anthropic / Gemini SDKs, so any framework that calls them
under the hood is already captured. Adapters add the framework-specific structured spans
(tool / retrieval / chain / agent) the detectors rely on.
One-line init
import retrace
retrace.init() # reads RETRACE_API_KEY, auto-patches installed providers, auto-starts a traceimport { init } from "retrace-sdk";
init(); // same, for NodeNo @record / startSpan boilerplate needed for the common case.
LangChain & LangGraph
import retrace
from retrace.adapters.langchain import RetraceCallbackHandler
retrace.init()
agent.invoke(input, config={"callbacks": [RetraceCallbackHandler()]}) # works for LangGraph tooimport { init } from "retrace-sdk";
import { createLangChainHandler } from "retrace-sdk/adapters/langchain";
init();
const cb = await createLangChainHandler();
await app.invoke(input, { callbacks: [cb] });CrewAI
import retrace
from retrace.adapters.crewai import instrument_crew
retrace.init()
crew = instrument_crew(Crew(agents=[...], tasks=[...]))
crew.kickoff()Vercel AI SDK (and Mastra)
The AI SDK talks to providers through its own packages, so use the step adapter (it records the LLM step and the tool calls/results):
import { init } from "retrace-sdk";
import { retraceOnStepFinish } from "retrace-sdk/adapters/vercel-ai";
init();
await generateText({ model, prompt, tools, onStepFinish: retraceOnStepFinish() });OpenAI Agents SDK
No adapter needed — the Agents SDK calls the OpenAI SDK, which init() already patches. Just call
retrace.init() before running your agent.
Span shapes align with the detectors
Adapters emit tool_call (args → schema validation), verbatim tool_result (→ tool-output
hallucination + loop detection), action/retrieval (→ replay divergence), and reasoning spans —
so error detection works on framework traces with no extra wiring.