from braintrust.wrappers.pydantic_ai import setup_pydantic_ai
from pydantic_ai import Agent, ModelSettings
setup_pydantic_ai(project_name="my-pydantic-project")
agent = Agent(
"openai:gpt-4o",
model_settings=ModelSettings(max_tokens=500),
)
@agent.tool_plain
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"22°C and sunny in {city}"
# Streaming is fully traced, including time-to-first-token
async with agent.run_stream("What's the weather in Paris?") as result:
async for text in result.stream_text(delta=True):
print(text, end="", flush=True)