LangChain Agent
File: examples/langchain_agent.py
Demonstrates the LangChain integration. Attaches TraceAgentLangChainCallback to a LangChain agent so chain steps, LLM calls, tool usage, and retriever activity are traced automatically.
Run
uv run examples/langchain_agent.py
Environment Variables
This example expects an OpenAI-compatible endpoint such as LM Studio:
| Variable | Description |
|---|---|
TRACE_AGENT_BASE_URL | TraceAgent server URL |
OPENAI_BASE_URL | OpenAI-compatible endpoint |
OPENAI_API_KEY | API key for the model provider |
What It Does
- Initializes the TraceAgent client and starts a run
- Creates a LangChain agent with tools
- Attaches
TraceAgentLangChainCallbackas a callback - Executes the agent — all steps are traced automatically
- Finishes the run