AgentBasis integrates with LangChain via callbacks, providing full visibility into your chains’ execution steps.
Setup
Unlike OpenAI/Anthropic instrumentation which patches globally, LangChain requires explicitly passing the callback handler to your components.
Basic Usage
Pass the handler to your LangChain calls via the config parameter:
Using get_callback_config
For convenience, use get_callback_config() to get a pre-configured dict:
Using instrument (Singleton)
Use instrument() to get a global singleton handler:
Chains
Trace entire chain executions with parent-child relationships:
Tool invocations are automatically traced:
Retrievers
RAG retriever operations are traced:
Trace Structure
The callback handler creates nested spans showing the full execution tree:
Captured Data
The integration traces:
With User Context
Combine with AgentBasis context for per-user tracing: