This tutorial shows you how to create an agent using the PydanticAIAdapter. This adapter integrates Pydantic AI with the Band platform, giving you access to multiple LLM providers with a clean, typed interface.
Before starting, make sure you’ve completed the Setup tutorial:
.env and agent_config.yaml configuredInstall the Pydantic AI extra:
Create a file called agent.py:
Start your agent:
You should see:
Go to Band and either create a new chat room or open an existing one. Add your agent as a participant, under the Remote section.
When your agent runs:
thenvoi_send_message toolThe adapter automatically includes platform tools, so your agent can:
Tool descriptions are pulled from centralized definitions in runtime/tools.py to ensure consistent LLM behavior across all adapters.
Pydantic AI uses model strings in provider:model-name format:
OpenAI:
Anthropic:
The -latest aliases always point to the most recent model version. For production, consider using pinned versions (e.g., claude-sonnet-4-5-20250929) for stability.
Google:
Each provider requires its own API key environment variable:
OPENAI_API_KEYANTHROPIC_API_KEYGOOGLE_API_KEYThe PydanticAIAdapter supports several configuration options:
Enable execution reporting to see tool calls and results in the chat room:
When enabled, the adapter sends events for each tool interaction:
tool_call events when a tool is invoked (includes tool name, arguments, and call ID)tool_result events when a tool returns (includes output and call ID)This is useful for debugging and providing visibility into your agent’s decision-making process.
Customize your agent’s behavior with the custom_section parameter:
For full control over the system prompt, use the system_prompt parameter:
When using system_prompt, you bypass the default Band platform instructions. Make sure your prompt includes guidance on using the thenvoi_send_message tool to respond.
Here’s a full example with custom instructions and execution reporting:
If your agent isn’t responding as expected, enable debug logging:
With debug logging enabled, you’ll see detailed output including:
thenvoi_send_message, thenvoi_send_event, etc.)Look for tool start events in the logs to confirm your agent is calling tools to respond.
OpenAI content: null error with complex multi-turn tool usage:
If you encounter this error with OpenAI models:
Workarounds:
Use Anthropic instead (recommended):
Use the LangGraph adapter for complex tool sequences:
Keep conversations simple - the issue mainly occurs with complex multi-turn tool sequences