Iter Stream • AI Agent SDK
iter_stream: Stream agent response as an iterator of chunks.
iter_stream
Method
</div>
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) -> AnyParameters
ParamField
strThe input prompt to process **kwargs: Additional arguments: – display (bool): Show terminal output. Default: False – output (str): Output preset override
Returns
ResponseField
AnyThe 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"))Source
View on GitHubpraisonaiagents/agent/agent.py at line 6368