-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
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 example in the docs works fine (see below), but if you want to deploy an agent that requires dependency injection, I'm not seeing a way for this to be done, given the deps arg is not passed into the AgentWorker.run_task method here
Given example - works ✅:
from pydantic_ai import Agent
agent = Agent('openai:gpt-4.1', instructions='Be fun!')
app = agent.to_a2a()Example Code
from pydantic import BaseModel
from pydantic_ai import Agent, RunContext
class Deps(BaseModel):
name: str
agent = Agent('openai:gpt-4.1', instructions='Be fun and greet the user by name', deps_type=Deps)
@agent.instructions
def inject_name(ctx: RunContext[Deps]) -> str:
return f"The user's name is {ctx.deps.name}"
app = agent.to_a2a()Python, Pydantic AI & LLM client version
python: 3.12
pydantic: 2.11.9
LLM client: any/all
alexwilcoxson-rel