Skip to content

Agents with dependencies are incompatible with a2aΒ #2910

@kc123100

Description

@kc123100

Initial Checks

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions