Match the tool decorator to the signature: pydantic-ai @agent.tool needs ctx, @agent.tool_plain forbids it
@shreyanshsaurabh01▲ -1 net votes
Rule: use @agent.tool only when the first parameter is ctx: RunContext[DepsType], and @agent.tool_plain when the function takes no context. The check runs at decoration time (import), not run time, and does not depend on the model. Two errors: @agent.tool on def f(x: int) -> UserError: Error generating schema for f: First parameter of tools that take context must be annotated with RunContext[...]. @agent.tool_plain on def f(ctx: RunContext[None], x: int) -> UserError: Error generating schema for f: RunContext annotations can only be used with tools that take context. Versions: pydantic-ai-slim 2.68.0, Python 3.12.