What you’ll need
- OpenAI API key
- Galileo API key
- Python environment with required packages
- Basic understanding of agentic AI concepts
Setup instructions
1
Set Up Your Environment
Create a
.env
file with your API keys:2
Install Dependencies
Install required dependencies:
requirements.txt
3
Create Tool Definitions
Create a
tools.json
file with tool definitions:tools.json
4
Running and Monitoring
Execute the application:Use Galileo to monitor:
- Tool usage patterns
- Query processing performance
- Error rates and types
- System performance metrics
Implementation guide
Let’s break down the implementation into manageable sections:1. setting up the environment
First, we’ll set up our imports and initialize our environment:app.py
- Imports necessary libraries including Galileo components
- Loads environment variables
- Sets up rich console output
- Initializes the OpenAI client with Galileo integration
2. defining Pydantic models for structured output
app.py
- Uses Pydantic for data validation
- Defines clear models for structured outputs
- Loads tool definitions from external JSON file
3. implementing agent tools
The agent has two main tools, each decorated with Galileo’s logging:app.py
- Uses
@log
decorator with thetool
span type for Galileo observability - Implements text-to-number conversion using LLM
- Implements a calculator for arithmetic operations
- Includes robust error handling and fallback mechanisms
4. query processing logic
The core agent functionality:app.py
- Loads tool definitions
- Constructs a clear system prompt with instructions
- Provides examples for the LLM to follow
- Makes the initial API call with tools
5. processing tool calls
The agent processes tool calls and manages the conversation flow:app.py
- Processes tool calls from the LLM
- Maintains conversation history
- Executes the appropriate tool functions
- Tracks the state of the conversation
6. handling incomplete sequences
The agent ensures that calculations are completed:app.py
- Detects incomplete calculation sequences
- Prompts the LLM to complete the calculation
- Processes additional tool calls
- Handles error cases
7. main application loop
The interactive interface:app.py
- User-friendly terminal interface
- Galileo context for request tracking
- Interactive question-answer loop
- Error handling and graceful exits
Key features
- Tool-Based Architecture: Modular design with specialized tools
- Galileo Observability: Track tool usage and performance
- Robust Error Handling: Graceful handling of API and runtime errors
- Conversation Management: Proper tracking of conversation state
- Interactive Experience: User-friendly terminal interface
Next steps
- Add more sophisticated tools for complex operations
- Implement memory for multi-turn conversations
- Add evaluation metrics for agent performance
- Integrate advanced Galileo logging features
- Implement parallel tool execution for efficiency