Overview
Stagehand agents support streaming execution, allowing you to receive real-time updates as the agent performs actions. This is particularly useful for:- Providing live feedback to users
- Monitoring long-running automation tasks
- Debugging agent behavior
- Building interactive UIs
Basic Streaming Example
Here’s how to create a streaming agent and consume its output:Streaming Full Events
You can also stream complete events including tool calls and messages:Stream Result Types
Whenstream: true is enabled, agent.execute() returns an AgentStreamResult object with:
textStream
Streams text deltas as they’re generated:fullStream
Streams complete events including:- Tool calls
- Messages
- Intermediate results
- Status updates
result
A promise that resolves to the final result:Streaming with Custom Tools
You can combine streaming with custom tools:Streaming with CUA
Streaming works with Computer Use Agents:Building a Progress UI
Here’s an example of using streaming to build a progress indicator:Error Handling with Streams
Handle errors when streaming:Key Concepts
Enable Streaming
Setstream: true in the agent configuration:
Async Iterators
BothtextStream and fullStream are async iterators:
Result Promise
Theresult property is a promise that resolves when execution completes:
Best Practices
- Use textStream for simple output - Best for displaying progress to users
- Use fullStream for detailed monitoring - Access all events for debugging
- Handle errors in streams - Wrap streaming logic in try/catch
- Await the result - Always await
resultto get the final output - Close resources - Call
stagehand.close()when done - Disable verbose logging - Set
verbose: 0to avoid cluttering stream output
Configuration Options
Next Steps
- Learn about agent with custom tools to extend capabilities
- See computer use example for advanced automation
- Explore MCP integration for external services