This example demonstrates how to use GalileoMiddleware to automatically log LangChain agent executions without manual callback setup.
GalileoMiddleware provides drop-in logging for LangGraph agents. It automatically captures:
- Agent lifecycle events (start/completion)
- Model calls with prompts, responses, and metadata
- Tool calls with function names, arguments, and outputs
- Install dependencies:
pip install -r requirements.txt- Configure environment variables:
cp .env.example .env
# Edit .env with your API keyspython main.pyThe agent will:
- Create a LangChain agent with two tools (weather and stock price)
- Invoke the agent with a question requiring both tools. Specifically, ""What's the weather like in San Francisco and what's the current stock price of Apple?"
- Automatically log all interactions to Galileo using middleware
The middleware creates a hierarchical trace with:
- Agent node: Tracks overall execution with input/output state
- LLM nodes: Logs each model call with prompts, responses, and timing
- Tool nodes: Records tool invocations with arguments and outputs
- Zero configuration: Add middleware to your agent and it works automatically
- Async support: Works seamlessly with both sync and async execution
- Flexible: Can use custom loggers and control trace management
- Comprehensive: Captures all relevant execution details
| Feature | GalileoMiddleware | GalileoCallback |
|---|---|---|
| Setup | Add to middleware list | Pass to each component |
| Complexity | Simple | Manual setup required |
| Best for | LangGraph agents | Complex LangChain apps |
For more details, see the middleware documentation.