Skip to main content
Streaming allows you to receive agent responses incrementally as they’re generated, rather than waiting for the complete response. This provides real-time feedback to users and creates a more responsive experience. Since language models can take time to generate complete responses, streaming lets users see output as it’s produced, making applications feel faster and more interactive.

Basic Usage

Use the stream() method for synchronous calls or astream() for asynchronous calls:
from hypertic.agents import Agent
from hypertic.tools import tool
from hypertic.models import OpenAIChat

@tool
def get_date() -> str:
    """Get today's date."""
    from datetime import date
    return str(date.today())

model = OpenAIChat(model="gpt-5.2")

agent = Agent(
    model=model,
    tools=[get_date]
)

# Stream responses synchronously
for event in agent.stream("What is today's date?"):
    if event.type == "content":
        print(event.content, end="", flush=True)
Output:
Today's date is **January 3, 2026**.

Accessing Event Attributes

Access individual attributes of streaming events:
from hypertic.agents import Agent
from hypertic.tools import tool
from hypertic.models import OpenAIChat

@tool
def get_date() -> str:
    """Get today's date."""
    from datetime import date
    return str(date.today())

model = OpenAIChat(model="gpt-5.2")
agent = Agent(
    model=model,
    tools=[get_date],
)

# Stream with event handling
for event in agent.stream("What is today's date?"):
    if event.type == "content":
        print(event.content, end="", flush=True)
    elif event.type == "tool_calls":
        print(f"\nTool Calls: {event.tool_calls}")
    elif event.type == "tool_outputs":
        print(f"\nTool Outputs: {event.tool_outputs}")
    elif event.type == "metadata":
        print(f"\nMetadata: {event.metadata}")
Output:
Tool Calls: [{'id': 'call_Qu159KQcXuBOFx9S8VyXRFQf', 'type': 'function', 'function': {'name': 'get_date', 'arguments': '{"day":"today"}'}}]
Tool Outputs: {'get_date': '2026-01-03'}
Today's date is **January 3, 2026**.
Metadata: {'model': 'gpt-5.2', 'params': {}, 'finish_reason': 'stop', 'input_tokens': 349, 'output_tokens': 17}

Event Types

When streaming, events have different types that you can handle:
Event TypeDescriptionData TypeWhen It Appears
contentText content chunks as they’re generatedstrContinuously as the model generates text
tool_callsTool calls made during executionlist[dict]When the agent decides to use a tool
tool_outputsResults from tool executiondict[str, Any]After tools complete execution
metadataModel information and token usagedictAt the end of the response