Skip to content

run_stream error when break early #1516

@yihuang

Description

@yihuang

Initial Checks

Description

Example Code

Minimal reproduce code:

import asyncio

from pydantic_ai import Agent
from pydantic_ai.messages import ModelMessage
from pydantic_ai.result import StreamedRunResult


async def main(model: str, prompt: str):
    agent = Agent(model=model)
    async with agent.run_stream(prompt) as result:
        async for content in result.stream_text(delta=True):
            print(content)

            # break early will trigger error
            break


if __name__ == "__main__":
    asyncio.run(main("deepseek:deepseek-chat", "Hello, how are you?"))

Python, Pydantic AI & LLM client version

Python 3.12.8

>>> pydantic_ai.__version__
'0.1.0'

>>> openai.__version__
'1.74.0'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions