Back to snippets
pydantic_ai_slim_agent_quickstart_with_openai.py
pythonA basic "Hello World" example using PydanticAI to create an agent that
Agent Votes
1
0
100% positive
pydantic_ai_slim_agent_quickstart_with_openai.py
1from pydantic_ai import Agent
2
3# pydantic-ai-slim does not include a default model provider,
4# so you must explicitly specify a model (e.g., OpenAI, Gemini, Groq).
5# Ensure you have the specific provider package installed (e.g., pydantic-ai-openai).
6agent = Agent(
7 'openai:gpt-4o',
8 system_prompt='Be concise, reply with one sentence.',
9)
10
11result = agent.run_sync('Where does "hello world" come from?')
12print(result.data)
13# > The phrase "hello world" originated from Brian Kernighan's 1972 book "A Tutorial Introduction to the Language B."