Skip to main content

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:

VariableDescription
TRACE_AGENT_BASE_URLTraceAgent server URL
OPENAI_BASE_URLOpenAI-compatible endpoint
OPENAI_API_KEYAPI key for the model provider

What It Does

  1. Initializes the TraceAgent client and starts a run
  2. Creates a LangChain agent with tools
  3. Attaches TraceAgentLangChainCallback as a callback
  4. Executes the agent — all steps are traced automatically
  5. Finishes the run

💬 Comments