You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Run the agent with a user prompt in sync streaming mode.
641
640
642
641
This is a convenience method that wraps [`self.run_stream`][pydantic_ai.agent.AbstractAgent.run_stream] with `loop.run_until_complete(...)`.
@@ -652,6 +651,18 @@ def run_stream_sync(
652
651
If you want to always run the agent graph to completion and stream events and output at the same time,
653
652
use [`agent.run()`][pydantic_ai.agent.AbstractAgent.run] with an `event_stream_handler` or [`agent.iter()`][pydantic_ai.agent.AbstractAgent.iter] instead.
654
653
654
+
Example:
655
+
```python
656
+
from pydantic_ai import Agent
657
+
658
+
agent = Agent('openai:gpt-4o')
659
+
660
+
def main():
661
+
response = agent.run_stream_sync('What is the capital of the UK?')
662
+
print(response.get_output_sync())
663
+
#> The capital of the UK is London.
664
+
```
665
+
655
666
Args:
656
667
user_prompt: User input to start/continue the conversation.
657
668
output_type: Custom output type to use for this run, `output_type` may only be used if the agent has no
This is a convenience method that wraps [`self.stream_output`][pydantic_ai.result.StreamedRunResult.stream_output] with `loop.run_until_complete(...)`.
428
+
This is a convenience method that wraps [`stream_output()`][pydantic_ai.result.StreamedRunResult.stream_output] with `loop.run_until_complete(...)`.
429
429
You therefore can't use this method inside async code or if there's an active event loop.
430
430
431
431
The pydantic validator for structured data will be called in
"""Stream the response as an iterable of Structured LLM Messages.
532
532
533
-
This is a convenience method that wraps [`self.stream_responses`][pydantic_ai.result.StreamedRunResult.stream_responses] with `loop.run_until_complete(...)`.
533
+
This is a convenience method that wraps [`stream_responses()`][pydantic_ai.result.StreamedRunResult.stream_responses] with `loop.run_until_complete(...)`.
534
534
You therefore can't use this method inside async code or if there's an active event loop.
0 commit comments