Overview
What you’ll build:
A simple LangChain-powered AI Agent that uses OpenAI’s language models and a custom tool, with all agent activities logged and monitored in Galileo.What you’ll learn:
- How to configure a LangChain Agent
- How to integrate Galileo for observability and monitoring
- How to structure tools and environment for scalable development
Requirements
- Python package manager + some familiarity with Python (for the sake of this cookbook, we’ll use uv)
- A Galileo Developer Account. If you don’t have one, [sign up for free]](https://app.galileo.ai).
- OpenAI Key to assist get one here
Environment setup
Ingredients:
- git
- Python environment tools
- Package manager (pip or uv)
Steps:
-
Clone the repository:
-
Create a virtual environment:
on Windows
on Mac Using a standard virtual environmentOr using uv (faster)
-
Install dependencies:
Using pip
OR using uv
-
Set up your environment variables:
Copy the existing
.env.example
file, and rename it to.env
in your project directory. Set your Galileo and OpenAI environment variables:.env- Replace the values with your actual keys. This keeps your credentials secure and out of your code.
Understanding the agent architecture
🧠 Agent core (main.py
)
A single script defines:
- Loading of secrets
- Tool declaration
- Agent instantiation
- Galileo observability
🛠️ Tools
Simple@tool
functions that the agent can call, such as:
🔍 Instrumentation (galileo_context
+ GalileoCallback
)
The galileo_context
tags all logs under a project and stream.
The GalileoCallback
automatically traces agent behavior in Galileo.
Main agent workflow
Key ingredients:
- LangChain agent
- OpenAI model
- Galileo integration
How it works:
- Load
.env
variables. - Declare tools.
- Wrap agent execution in
galileo_context
. - Use
GalileoCallback
to trace the run. - Print the agent’s response.
Running the agent
Run your script using:Expected output:
Viewing traces in Galileo
Steps:
- Log into Galileo.
-
Open the
langchain-docs
project andmy_log_stream
. -
Inspect:
- Prompts
- Reasoning steps
- Tool invocations
- Outputs
Extending the agent
Add new tools
Define more@tool
-decorated functions and include them in the agent.
Change models
Swap outgpt-4
for another supported OpenAI model in ChatOpenAI
.
Update context
Change theproject
and log_stream
in galileo_context
for better trace organization.
Conclusion
Key takeaways:
- LangChain + Galileo makes AI agents traceable and observable
- Using tools and context managers helps modularize and organize agent behavior
- Monitoring enables better debugging and optimization
Next steps:
- Check out the Galileo YouTube Channel to see what you can build!
- Star the Galileo SDK-examples repoto bookmark more ways to get started with the Galileo SDK.
- Follow Galileo on LinkedIn to stay in touch with the latest news and resources.
Common issues and solutions
API key issues
Problem: “Invalid API key” errors Solution:- Double-check your
.env
file
Galileo connection issues
Problem: Traces aren’t showing up in Galileo Solution:- Confirm your API key is valid
- Check internet connectivity
- Ensure
flush()
is being called at the end of execution