-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
The object passed into the tool function is a dict instead of an instance of the annotated type:
File "/home/DouweM/pydantic-ai/scratch/scratchpads/9c8b872dabe381702d009fe29745ee89/scratch9.py", line 21, in weather
return f'The weather in {f.city} is sunny'
^^^^^^
AttributeError: 'dict' object has no attribute 'city'
Example Code
import asyncio
import uuid
from pydantic import BaseModel
from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker
from pydantic_ai import Agent
from pydantic_ai.durable_exec.temporal import AgentPlugin, PydanticAIPlugin, TemporalAgent
agent = Agent('openai:gpt-4.1', name='test-tool')
class WeatherInput(BaseModel):
city: str
@agent.tool_plain
def weather(f: WeatherInput) -> str:
return f'The weather in {f.city} is sunny'
temporal_agent = TemporalAgent(agent)
@workflow.defn
class PydanticWorkflow:
@workflow.run
async def run(self, prompt: str) -> str:
result = await temporal_agent.run(prompt)
return result.output
async def main():
client = await Client.connect(
'localhost:7233',
plugins=[PydanticAIPlugin()],
)
async with Worker(
client,
task_queue='pydantic-ai-task-queue',
workflows=[PydanticWorkflow],
plugins=[AgentPlugin(temporal_agent)],
):
result = await client.execute_workflow(
PydanticWorkflow.run,
args=['What is the weather in Tokyo?'],
id=f'pydantic-hello-world-workflow-{uuid.uuid4()}',
task_queue='pydantic-ai-task-queue',
)
print(f'Result: {result}')
if __name__ == '__main__':
asyncio.run(main())Python, Pydantic AI & LLM client version
latest