What this thread does
Do first: Register a context-aware function with @agent.tool, annotate its first argument as RunContext[YourDeps], and supply deps when running the agent.
Short answer
Pass a dependency type to Agent(deps_type=...) and a matching instance to the run's deps parameter. Read it from ctx.deps. The type declaration supports static checking; it does not perform runtime dependency validation.
What to do
The documentation's string-dependency pattern, shortened to registration:
from pydantic_ai import Agent, RunContext
agent = Agent('google:gemini-3.8-flash', deps_type=str)
@agent.tool
def get_player_name(ctx: RunContext[str]) -> str:
return ctx.deps
This uses the documentation's google:gemini-3.8-flash example model. Pass deps='Anne' to agent.run_sync(...); asynchronous application code can use await agent.run(..., deps=deps).
| Need | API / rule |
|---|---|
| Tool with run context | @agent.tool; first parameter RunContext[YourDeps] |
| Tool without run context | @agent.tool_plain |
| Existing reusable functions | Agent(..., tools=[...]); signatures determine whether RunContext is needed |
| Explicit context selection | Tool(get_player_name, takes_ctx=True); context-free example Tool(roll_dice, takes_ctx=False) |
| Model-facing schema | Function parameters except RunContext; dependency context is supplied by the agent |
| Tool result | Anything Pydantic can serialize to JSON |
| I/O dependencies | Prefer async def; synchronous def functions run via run_in_executor in a thread pool |
| Docstring parsing | Inferred by default; docstring_format can specify google, numpy, or sphinx |
| Require parameter documentation | require_parameter_descriptions=True; a missing description raises UserError |
Put model-relevant guidance in the leading docstring, parameter descriptions (including Keyword Args / Other Parameters), or the first returns entry. Sections such as Raises, Examples, Notes, Warnings, and Yields are dropped from the model-facing description.
Limits and open questions
run_sync wraps run; that choice is independent of whether dependencies use synchronous or asynchronous functions. Registration makes a tool available; it does not require the model to call it. The pages give no fixed tool-count limit.
Not for: LangChain tool decorators or PydanticAI output functions that end a run.
Sources
- Function Tools (input URL), pydantic.
- Function Tools (redirect destination), pydantic.
- Dependencies, pydantic.
Checked
2026-11-17; read Function Tools (input URL); Function Tools (redirect destination); Dependencies; no command was run.
Started from a post by @pydantic, packaged by the editor. Original post