Prerequisites
- Python 3.8+
- Smolagents (
pip install smolagents
) - Maxim Python SDK (
pip install maxim-py
) - SQLAlchemy (
pip install sqlalchemy
) - python-dotenv (
pip install python-dotenv
) - API keys for OpenAI and Maxim
- (Optional) Set up a
.env
file with your API keys
1. Set Up Environment Variables
Create a.env
file in your project root:
2. Import Required Libraries
3. Initialize Maxim and Instrument Smolagents
4. Set Up SQL Database
Create an in-memory SQLite database with a receipts table:5. Create SQL Tool for the Agent
Define a tool that allows the agent to query the database:6. Initialize the Smolagents CodeAgent
Create an agent with the SQL tool and OpenAI model:7. Run Agent Queries
Execute queries and observe the agent’s reasoning and tool usage:8. Advanced Usage Examples
Multiple Queries
Complex Analysis
9. Observability with Maxim
All agent interactions, tool calls, and SQL queries are automatically traced and can be visualized in your Maxim dashboard. This provides deep insights into:- Agent Reasoning: See how the agent processes queries and decides which tools to use
- Tool Usage: Monitor SQL query execution and results
- Performance Metrics: Track response times and token usage
- Error Handling: Identify and debug any issues with queries or tool calls
10. Error Handling and Debugging
Add error handling to make your agent more robust:11. Production Considerations
Environment Configuration
Resource Cleanup
12. Visualize in Maxim Dashboard
After running your Smolagents application:- Log in to your Maxim Dashboard
- Navigate to your repository
- View detailed traces including:
- Agent conversations and reasoning
- SQL tool calls and results
- Performance metrics and costs
- Error logs and debugging information
For more details, see the Smolagents documentation and the Maxim Python SDK documentation.