-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed as duplicate of#19142
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
See sample code. The mypy typechecker is not able to infer the correct output type. I am unsure if it's even possible to do anything about it due to the runtime (probably) required to infer agent.output_type, so it might just be a case where a type ignore is required. I also tried the union operator instead of list elements, but then I encountered another bug (No overload variant of "run_stream" of "AbstractAgent" matches argument type "UnionType")
The code below results in error: Need type annotation for "result" [var-annotated].
Example Code
from pydantic_ai import Agent, DeferredToolRequests
async def run() -> None:
agent = Agent(
name="Chat Agent",
)
async with agent.run_stream(
output_type=[agent.output_type, DeferredToolRequests]
) as result:
async for _response in result.stream_output():
pass
if __name__ == "__main__":
import asyncio
asyncio.run(run())Python, Pydantic AI & LLM client version
Python 3.12
pydantic-ai-slim 1.14.1
mypy 1.18.2