Skip to main content

iter_stream

Method
This is a method of the Agent class in the agent module.
Stream agent response as an iterator of chunks. App-friendly streaming. Yields response chunks without terminal display. Use this for building custom UIs or processing streams programmatically.

Signature

def iter_stream(prompt: str) -> Any

Parameters

prompt
str
required
The input prompt to process **kwargs: Additional arguments: - display (bool): Show terminal output. Default: False - output (str): Output preset override

Returns

Returns
Any
The result of the operation.

Usage

agent = Agent(instructions="You are helpful")

    # Process stream programmatically
    full_response = ""
    for chunk in agent.iter_stream("Tell me a story"):
        full_response += chunk
        # Custom processing here

    # Or collect all at once
    response = "".join(agent.iter_stream("Hello"))