Skip to content

Commit 4f0d2ad

Browse files
committed
update docs
1 parent e1765d3 commit 4f0d2ad

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

docs/agents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ There are five ways to run an agent:
6565

6666
1. [`agent.run()`][pydantic_ai.agent.AbstractAgent.run] — an async function which returns a [`RunResult`][pydantic_ai.agent.AgentRunResult] containing a completed response.
6767
2. [`agent.run_sync()`][pydantic_ai.agent.AbstractAgent.run_sync] — a plain, synchronous function which returns a [`RunResult`][pydantic_ai.agent.AgentRunResult] containing a completed response (internally, this just calls `loop.run_until_complete(self.run())`).
68-
3. [`agent.run_stream()`][pydantic_ai.agent.AbstractAgent.run_stream] — an async context manager which returns a [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult], which contains methods to stream text and structured output as an async iterable.
68+
3. [`agent.run_stream()`][pydantic_ai.agent.AbstractAgent.run_stream] — an async context manager which returns a [`StreamedRunResult`][pydantic_ai.result.StreamedRunResult], which contains methods to stream text and structured output as an async iterable. [`agent.run_stream_sync()`][pydantic_ai.agent.AbstractAgent.run_stream_sync] is a synchronous context manager variation with the same return type.
6969
4. [`agent.run_stream_events()`][pydantic_ai.agent.AbstractAgent.run_stream_events] — a function which returns an async iterable of [`AgentStreamEvent`s][pydantic_ai.messages.AgentStreamEvent] and a [`AgentRunResultEvent`][pydantic_ai.run.AgentRunResultEvent] containing the final run result.
7070
5. [`agent.iter()`][pydantic_ai.Agent.iter] — a context manager which returns an [`AgentRun`][pydantic_ai.agent.AgentRun], an async iterable over the nodes of the agent's underlying [`Graph`][pydantic_graph.graph.Graph].
7171

pydantic_ai_slim/pydantic_ai/agent/abstract.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import inspect
55
from abc import ABC, abstractmethod
66
from collections.abc import AsyncIterable, AsyncIterator, Awaitable, Callable, Iterator, Mapping, Sequence
7-
from contextlib import AbstractAsyncContextManager, asynccontextmanager, contextmanager
7+
from contextlib import AbstractAsyncContextManager, AbstractContextManager, asynccontextmanager, contextmanager
88
from types import FrameType
99
from typing import TYPE_CHECKING, Any, Generic, TypeAlias, cast, overload
1010

@@ -581,6 +581,44 @@ async def on_complete() -> None:
581581
if not yielded:
582582
raise exceptions.AgentRunError('Agent run finished without producing a final result') # pragma: no cover
583583

584+
@overload
585+
def run_stream_sync(
586+
self,
587+
user_prompt: str | Sequence[_messages.UserContent] | None = None,
588+
*,
589+
output_type: None = None,
590+
message_history: Sequence[_messages.ModelMessage] | None = None,
591+
deferred_tool_results: DeferredToolResults | None = None,
592+
model: models.Model | models.KnownModelName | str | None = None,
593+
deps: AgentDepsT = None,
594+
model_settings: ModelSettings | None = None,
595+
usage_limits: _usage.UsageLimits | None = None,
596+
usage: _usage.RunUsage | None = None,
597+
infer_name: bool = True,
598+
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
599+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
600+
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
601+
) -> AbstractContextManager[result.StreamedRunResult[AgentDepsT, OutputDataT]]: ...
602+
603+
@overload
604+
def run_stream_sync(
605+
self,
606+
user_prompt: str | Sequence[_messages.UserContent] | None = None,
607+
*,
608+
output_type: OutputSpec[RunOutputDataT],
609+
message_history: Sequence[_messages.ModelMessage] | None = None,
610+
deferred_tool_results: DeferredToolResults | None = None,
611+
model: models.Model | models.KnownModelName | str | None = None,
612+
deps: AgentDepsT = None,
613+
model_settings: ModelSettings | None = None,
614+
usage_limits: _usage.UsageLimits | None = None,
615+
usage: _usage.RunUsage | None = None,
616+
infer_name: bool = True,
617+
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
618+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
619+
event_stream_handler: EventStreamHandler[AgentDepsT] | None = None,
620+
) -> AbstractContextManager[result.StreamedRunResult[AgentDepsT, RunOutputDataT]]: ...
621+
584622
@contextmanager
585623
def run_stream_sync(
586624
self,

0 commit comments

Comments
 (0)