from pydantic import BaseModel, Field
from pydantic_ai import Agent, RunContext
from pydantic_ai.models.openai import OpenAIModel
from typing import List
import httpx
class WeatherInfo(BaseModel):
location: str
temperature: float = Field(description="Temperature in Celsius")
condition: str
humidity: int = Field(description="Humidity percentage")
# Create an agent with system prompts and tools
weather_agent = Agent(
model=OpenAIModel("gpt-4"),
output_type=WeatherInfo,
system_prompt="You are a helpful weather assistant. Always provide accurate weather information.",
instrument=True
)
@weather_agent.tool
async def get_weather_data(ctx: RunContext[None], location: str) -> str:
"""Get current weather data for a location."""
# Mock weather API call - replace with actual weather service
async with httpx.AsyncClient() as client:
# This is a placeholder - use a real weather API
mock_data = {
"temperature": 22.5,
"condition": "partly cloudy",
"humidity": 65
}
return f"Weather in {location}: {mock_data}"
# Run the agent with tool usage
result = weather_agent.run_sync("What's the weather like in Paris?")
print(result)