Skip to main content
Prerequisites: Completed Deploy Your First Agent tutorial and understand Core Concepts

Overview

Streaming responses allow you to receive agent output in real-time as it’s generated, rather than waiting for the complete response. This provides better user experience for long-running operations, chat interfaces, and interactive applications.

Key Concepts

Streaming vs Synchronous

Entrypoint Naming Convention

Streaming entrypoints must end with _stream:

Using CLI for Streaming

Basic Streaming Command

Command Options

Examples

Example 1: Basic Streaming

Example 2: Using Input File

Create input.json:

Example 3: Local Agent Streaming

Example 4: With Host and Port

Using SDKs for Streaming

Python SDK

JavaScript/TypeScript SDK

Go SDK

Rust SDK

Creating Streaming Entrypoints

Python Streaming Function

Configuration

Add to runagent.config.json:
Important: The entrypoint tag must end with _stream for streaming to work. The CLI command run-stream validates this requirement.

Best Practices

1. Use Streaming for Long Operations

Streaming is ideal for:
  • Long text generation (stories, articles, explanations)
  • Interactive chat (real-time conversation)
  • Progress updates (status messages during processing)
  • Large data processing (streaming results as they’re computed)

2. Chunk Size Considerations

3. Error Handling in Streaming

4. Client-Side Error Handling

Troubleshooting

Error: Tag must end with _stream

Problem:
Solution:
  • Ensure your entrypoint tag ends with _stream
  • Check your runagent.config.json configuration
  • Use the correct tag: chat_stream instead of chat

Error: Connection timeout

Problem: WebSocket connection times out during streaming Solution:

Streaming stops unexpectedly

Problem: Stream ends without completing Possible causes:
  • Agent function raised an exception
  • Network connection interrupted
  • Agent timeout exceeded
Solution:
  • Check agent logs: runagent db logs --agent-id <id>
  • Verify agent function handles errors gracefully
  • Test with shorter inputs first

No output appears

Problem: Command runs but no output Solution:
  • Verify entrypoint is actually streaming (yields chunks)
  • Check agent is running: runagent db status --agent-id <id>
  • Test with synchronous version first to verify agent works

Performance Considerations

WebSocket Overhead

Streaming uses WebSocket connections which have:
  • Lower latency for real-time updates
  • Persistent connection overhead
  • Better for long-running operations

When to Use Streaming

Use streaming when:
  • Response time > 2 seconds
  • User needs real-time feedback
  • Generating long-form content
  • Interactive applications
Avoid streaming when:
  • Quick responses (< 1 second)
  • Simple data retrieval
  • Batch processing (use async instead)

Advanced Patterns

Progressive Response Building

Conditional Streaming

Next Steps

SDK Documentation

Learn more about SDK streaming capabilities

Core Concepts

Understand entrypoints and streaming architecture

Production Considerations

Best practices for production streaming

CLI Reference

Complete CLI command reference

Still have a question?