> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Realtime

> Stream agent responses in real-time

Agents can stream responses - see results word-by-word as they're generated.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    User([User]) --> Agent[Agent]
    Agent --> Stream([Stream])

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff

    class Agent agent
    class User,Stream tool
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    import { Agent } from 'praisonai';

    const agent = new Agent({
      instructions: 'You tell engaging stories'
    });

    // Stream word by word
    for await (const chunk of agent.stream('Tell me a story')) {
      process.stdout.write(chunk);
    }
    ```
  </Step>

  <Step title="With Configuration">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    await agent.chat('Explain quantum physics', {
      stream: true,
      onChunk: (chunk) => {
        displayInUI(chunk);
      }
    });
    ```
  </Step>
</Steps>

***

## User Interaction Flow

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant UI
    
    User->>Agent: "Tell me a story"
    loop Streaming
        Agent-->>UI: "Once"
        Agent-->>UI: "upon"
        Agent-->>UI: "a"
        Agent-->>UI: "time..."
    end
    Agent-->>User: [Complete]
```

***

## Configuration Levels

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
// Level 1: Bool - Enable streaming
const response = await agent.chat('Hello', {
  stream: true
});

// Level 2: Method - Use stream iterator
for await (const chunk of agent.stream('Hello')) {
  console.log(chunk);
}

// Level 3: Dict - With callbacks
await agent.chat('Hello', {
  stream: true,
  onChunk: (chunk) => console.log(chunk),
  onComplete: (full) => console.log('Done:', full)
});
```

***

## When to Stream

| Scenario        | Use Streaming?              |
| --------------- | --------------------------- |
| Long responses  | ✅ Yes - better UX           |
| Short answers   | ❌ No - wait for complete    |
| Real-time chat  | ✅ Yes - feels natural       |
| Data extraction | ❌ No - need complete output |

***

## API Reference

<Card title="RealtimeConfig" icon="code" href="/docs/sdk/reference/typescript/classes/RealtimeConfig">
  Complete configuration options
</Card>

<Card title="RealtimeAgent" icon="robot" href="/docs/sdk/reference/typescript/classes/RealtimeAgent">
  Full class documentation
</Card>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Use for long content">
    Streaming helps most with responses over a few seconds.
  </Accordion>

  <Accordion title="Handle interruptions">
    Users may cancel mid-stream - handle gracefully.
  </Accordion>

  <Accordion title="Buffer for structured output">
    When parsing JSON, wait for complete output.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Agent" icon="user" href="/docs/js/agent">
    Create agents
  </Card>

  <Card title="Voice" icon="microphone" href="/docs/js/voice">
    Voice interactions
  </Card>
</CardGroup>
