mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-09-21 10:26:25 +00:00
docs(streaming): fix streaming output docstring examples (#7286)
* docs(streaming): fix streaming output docstring examples CrewStreamingOutput's example called crew.kickoff() without setting stream=True on the Crew, so the snippet returned a CrewOutput and did not stream anything. FlowStreamingOutput's example called flow.kickoff_streaming() and flow.kickoff_streaming_async(); neither method exists. Flow-level streaming is exposed through Flow.kickoff with stream=True and returns a StreamSession, not a FlowStreamingOutput. Refs #7285 * docs(streaming): clarify Flow.kickoff does not take stream param Flow.kickoff() has no stream parameter; the runtime returns a StreamSession when self.stream is True. Reword the FlowStreamingOutput note so callers know to configure the Flow with stream=True before calling kickoff(). Addresses CodeRabbit review on #7286. * docs(streaming): restore FlowStreamingOutput example Add back an Example block showing valid usage of FlowStreamingOutput. The class is only ever constructed directly with a chunk-producing iterator (see lib/crewai/tests/test_streaming.py), so the example mirrors that pattern instead of the original snippet that referenced non-existent Flow.kickoff_streaming methods. Addresses review feedback on #7286. * docs(streaming): swap FlowStreamingOutput example for public Flow streaming path Replace the test-only FlowStreamingOutput(sync_iterator=...) example with the actual public flow-streaming path: Flow.stream=True followed by kickoff() / kickoff_async(), which return StreamSession / AsyncStreamSession. The example is labeled explicitly to make clear that Flow.kickoff() does not return a FlowStreamingOutput, and points readers at the streaming-flow-execution guide. Addresses review feedback on #7286. --------- Co-authored-by: Vidit Ostwal <110953813+Vidit-Ostwal@users.noreply.github.com>
This commit is contained in:
@@ -504,13 +504,15 @@ class CrewStreamingOutput(StreamingOutputBase["CrewOutput"]):
|
||||
|
||||
Example:
|
||||
```python
|
||||
# Single crew
|
||||
# Single crew — the crew must be constructed with stream=True
|
||||
crew = Crew(agents=[...], tasks=[...], stream=True)
|
||||
streaming = crew.kickoff(inputs={"topic": "AI"})
|
||||
for chunk in streaming:
|
||||
print(chunk.content, end="", flush=True)
|
||||
result = streaming.result
|
||||
|
||||
# Multiple crews (kickoff_for_each_async)
|
||||
# Multiple crews (kickoff_for_each_async) — also requires stream=True
|
||||
crew = Crew(agents=[...], tasks=[...], stream=True)
|
||||
streaming = await crew.kickoff_for_each_async(
|
||||
[{"topic": "AI"}, {"topic": "ML"}]
|
||||
)
|
||||
@@ -580,22 +582,35 @@ class FlowStreamingOutput(StreamingOutputBase[Any]):
|
||||
"""Streaming output wrapper for flow execution.
|
||||
|
||||
Provides both sync and async iteration over stream chunks,
|
||||
with access to the final flow output via the .result property.
|
||||
with access to the final flow output via the ``.result`` property.
|
||||
|
||||
Example:
|
||||
```python
|
||||
# Sync usage
|
||||
streaming = flow.kickoff_streaming()
|
||||
for chunk in streaming:
|
||||
print(chunk.content, end="", flush=True)
|
||||
# Flow-level streaming returns a StreamSession from Flow.kickoff() —
|
||||
# NOT a FlowStreamingOutput. See
|
||||
# docs/edge/en/learn/streaming-flow-execution.mdx for the full guide.
|
||||
flow = MyFlow()
|
||||
flow.stream = True
|
||||
streaming = flow.kickoff() # -> StreamSession
|
||||
for frame in streaming:
|
||||
print(frame.content, end="", flush=True)
|
||||
result = streaming.result
|
||||
|
||||
# Async usage
|
||||
streaming = await flow.kickoff_streaming_async()
|
||||
async for chunk in streaming:
|
||||
print(chunk.content, end="", flush=True)
|
||||
# Async variant:
|
||||
flow = MyFlow()
|
||||
flow.stream = True
|
||||
streaming = await flow.kickoff_async() # -> AsyncStreamSession
|
||||
async for frame in streaming:
|
||||
print(frame.content, end="", flush=True)
|
||||
result = streaming.result
|
||||
```
|
||||
|
||||
Note:
|
||||
Flow-level streaming is exposed to users through
|
||||
:class:`StreamSession`; configure the Flow with ``stream=True``
|
||||
before calling ``Flow.kickoff()``. ``FlowStreamingOutput`` is
|
||||
retained for consumers that build a streaming wrapper directly
|
||||
from an existing iterator.
|
||||
"""
|
||||
|
||||
def _set_result(self, result: Any) -> None:
|
||||
|
||||
Reference in New Issue
Block a user