Skip to content

Use handle_stream.stream_output() in the CLI #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions pydantic_ai_slim/pydantic_ai/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from pydantic_ai.agent import Agent
from pydantic_ai.exceptions import UserError
from pydantic_ai.messages import ModelMessage, PartDeltaEvent, TextPartDelta
from pydantic_ai.messages import ModelMessage
from pydantic_ai.models import KnownModelName, infer_model

try:
Expand Down Expand Up @@ -222,10 +222,8 @@ async def ask_agent(
status.stop() # stopping multiple times is idempotent
stack.enter_context(live) # entering multiple times is idempotent

async for event in handle_stream:
if isinstance(event, PartDeltaEvent) and isinstance(event.delta, TextPartDelta):
content += event.delta.content_delta
live.update(Markdown(content, code_theme=code_theme))
async for content in handle_stream.stream_output():
live.update(Markdown(content, code_theme=code_theme))

assert agent_run.result is not None
return agent_run.result.all_messages()
Expand Down