AgentLabs - Docs
  • Introduction
    • What is AgentLabs?
    • Get Started with AgentLabs
    • Pricing
  • Getting Started
    • Installation
    • Secret Key
    • Using the SDK
  • Core Concepts
    • Frontend as a service
    • User Authentication
    • Project
    • Agents
    • Messages
      • Messages Format
      • One-off vs Stream
      • Typewriter animation
    • Attachments
  • Recipes
    • Before we start
    • Ping-Pong
    • ChatGPT with LangChain
    • Code Interpreter
    • Mutli-Agent with AutoGen
  • 🧙Community
    • Github
    • Discord
    • Support team
Powered by GitBook
On this page
  • One-off messages
  • Streamed messages
  • Which one to choose?
  1. Core Concepts
  2. Messages

One-off vs Stream

PreviousMessages FormatNextTypewriter animation

Last updated 1 year ago

One-off messages

A one-off message is a standard message that you can send entirely as you would do when you're chatting with a friend and hit send .

The entire message will be sent at once.

One-off messages are great for small content that you know in advance.3

For example, in our Ping-Pong recipe, we answer "pong" using a one-off message every time the user says "ping".

Streamed messages

Streamed messages are different from one-off messages.

When you send a streamed message, the user immediately sees a message box popping up.

However, every time you send a new stream on the same channel, it will aggregate to the same message box.

You can think of them as having this "typewriter" look and feel as you could have for example in .

Sending a stream works in 3 steps:

Open a stream channel using the createStream() method

const channel = agent.createStream(conversationId)

Note that starting from v0.0.51 openeing a stream triggers an event that will displays a smooth animation in the frontend (see Typewriter animation)

channel.write("this")
channel.write("is")
channel.write("a")
channel.write("streamed")
channel.write("message")
channel.streamEnd()

Which one to choose?

It's pretty rare to hesitate between both, but if you're in that situation, here's a quick recap that might help.

Solution
Info
Warning

One-off

Stream

Indeed, you have to test each solution on your own to make sure you decide which one is best suited to your specific use case. In general, you want to use a mix of both in your application anyway.

Write content to the stream as many times as you want

When you're done, close the channel

Et voilà Here's an example of how a streamed response looks

great when you know the content of the message upfront suited when you need to inform the user quickly about something

Generally not suited to send multiple messages in a row

feel more natural / human-friendly suited for long-running tasks in the background

Be careful with very very long answers because it can become borring for the user to wait, especially if you know the whole response upfront.

🔵
🔵
🎉
🔵
ChatGPT
✅
✅
❌
✅
✅
❌
Example streamed message with code execution