LangChain Integration
Lucidic integrates seamlessly with LangChain agents and chains — no need to rewrite your code or restructure your logic.How It Works
When you useproviders=["langchain"]
with Lucidic:
- LangChain LLM calls are automatically instrumented using OpenTelemetry
- Events are automatically created for every LLM call - no manual event creation needed
- No need to manually attach handlers in most cases
- All LLM usage is captured as Lucidic Events, grouped under the correct Step
- If no step exists when an LLM call occurs, one is automatically created
Example
Streaming Example
Explicit Step Management
What Gets Captured
For every LangChain LLM call, we automatically capture:- Input: your messages/prompt to the LLM
- Model: the LLM model used (e.g.
gpt-4
,claude-3
) - Output: the LLM response (including streaming)
- Token usage: input and output tokens
- Cost: calculated based on token usage and model pricing
- Chain context: which chain or agent made the call
- Tool usage: any tools invoked by the agent
Agent Example
Complex Agent Handler (Optional)
For some complex agent setups, you may need to manually attach a handler:Notes
- Requires LangChain packages installed (
langchain
,langchain-openai
, etc.) - Works with all LangChain LLMs, chains, and agents
- Automatic instrumentation handles most use cases
- If no step exists when an LLM call is made, Lucidic automatically creates one
- Both sync and async operations are supported
- Tool calls and chain execution are tracked as separate events