Skip to main content
Stream agent responses word-by-word for instant feedback — no waiting for the full response.

Quick Start

1

Simple Usage

Streaming is on by default — just create an agent and chat.
import { Agent } from 'praisonai';

const agent = new Agent({
  instructions: 'You are a helpful assistant'
});

await agent.chat('Tell me a story about a robot');
// Response streams to the console word by word
2

With Configuration

Turn off streaming when you need the complete response at once.
import { Agent } from 'praisonai';

const agent = new Agent({
  instructions: 'Summarize text',
  stream: false
});

const response = await agent.chat('Summarize this article...');
console.log(response);  // Complete response returned all at once
3

Streaming with Tools

Tool calls are handled automatically — the stream continues after tool execution.
import { Agent } from 'praisonai';

function getWeather(city: string): string {
  return `Weather in ${city}: 22°C, sunny`;
}

const agent = new Agent({
  instructions: 'You are a weather assistant',
  stream: true,
  tools: [getWeather]
});

await agent.chat('What is the weather in Paris?');
// Tool executes, then response streams

How It Works


Configuration Options

OptionTypeDefaultDescription
streambooleantrueEnable streaming responses
verbosebooleanfalseShow formatted output while streaming

Common Patterns

Interactive Chat Application

import { Agent } from 'praisonai';
import * as readline from 'readline';

const agent = new Agent({
  instructions: 'You are a helpful assistant',
  stream: true,
  verbose: true
});

const rl = readline.createInterface({ input: process.stdin, output: process.stdout });

async function chat() {
  rl.question('You: ', async (input) => {
    if (input === 'exit') { rl.close(); return; }
    await agent.chat(input);
    chat();
  });
}

chat();

Long-Form Content Generation

import { Agent } from 'praisonai';

const writer = new Agent({
  instructions: 'You are a creative writer',
  stream: true
});

// See the story unfold as it is written
await writer.chat('Write a 500-word story about a time-traveling chef');

Batch Processing (Disable Streaming)

import { Agent } from 'praisonai';

const agent = new Agent({
  instructions: 'Classify the sentiment of the text as positive, neutral, or negative',
  stream: false  // Faster for batch jobs
});

const texts = ['Great product!', 'It is okay', 'Very disappointed'];
const results = await Promise.all(texts.map(t => agent.chat(t)));
console.log(results);

Best Practices

Streaming dramatically improves perceived performance. Users see responses immediately rather than waiting. Keep it enabled for any chat or interactive application.
When processing many documents or requests without a live user, stream: false is faster and simpler — you get back the complete string directly from chat().
Set verbose: true during development to see formatted streaming output in the console. Disable it in production API endpoints where you only need the return value.
Every supported LLM provider (OpenAI, Anthropic, Google, Groq, etc.) supports streaming. You do not need to change the provider to enable it.

Agent

Full agent configuration

Providers

LLM provider setup