Features
- Real-time weather information using web search
- DuckDuckGo search tool integration
- Type-safe agent configuration
- Custom model provider setup
- Simple command-line interface
Prerequisites
- Python 3.8 or higher
- Nebius API key from Nebius Token Factory
Installation
Implementation
Model Configuration
Set up PydanticAI with a custom OpenAI-compatible provider:main.py
Agent Setup
Create the agent with search capabilities:main.py
Running the Agent
main.py
Usage
Run the weather bot:Customize the City
Modify thecity variable to check weather for different locations:
Example Queries
- “What is the weather forecast for New York today?”
- “What’s the temperature in London right now?”
- “Will it rain in Tokyo tomorrow?”
- “What’s the weather like in Sydney?”
- “Show me the forecast for Paris”
Technical Details
Architecture
PydanticAI
Type-safe agent framework
Nebius AI
Meta-Llama-3.1-70B-Instruct model
DuckDuckGo
Web search tool for real-time data
OpenAI Provider
Compatible API integration
Model Provider
PydanticAI uses OpenAI-compatible providers:Tool Integration
The agent uses PydanticAI’s built-in DuckDuckGo search tool:Extending the Agent
Add Custom Tools
Add Structured Output
Make it Interactive
Use Different Models
Best Practices
Model Selection
Model Selection
- Use larger models (70B+) for complex reasoning
- Use smaller models (8B-30B) for faster responses
- Test different models for your use case
- Consider cost vs. performance tradeoffs
System Prompts
System Prompts
- Be specific about the agent’s role
- Mention available tools explicitly
- Define expected output format
- Include examples if needed
Tool Usage
Tool Usage
- Use built-in tools when available
- Keep custom tools focused and simple
- Provide clear tool descriptions
- Handle errors gracefully
Error Handling
Environment Variables
| Variable | Description | Required |
|---|---|---|
NEBIUS_API_KEY | Your Nebius API key | Yes |
Next Steps
Advanced Agents
Build more complex PydanticAI agents
Structured Output
Work with structured data