# One-off vs Stream

## 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](/recipes/ping-pong.md) 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.&#x20;

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.

{% hint style="info" %}
You can think of them as having this "typewriter" look and feel as you could have for example in [ChatGPT](https://chat.openai.com/).
{% endhint %}

Sending a stream works in 3 steps:

:blue\_circle: **Open a stream channel using the** `createStream()` **method**

```typescript
const channel = agent.createStream(conversationId)
```

{% hint style="info" %}
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](/core-concepts/messages/typewriter-animation.md))
{% endhint %}

:blue\_circle: **Write content to the stream as many times as you want**

```typescript
channel.write("this")
channel.write("is")
channel.write("a")
channel.write("streamed")
channel.write("message")
```

:blue\_circle: **When you're done, close the channel**

```typescript
channel.streamEnd()
```

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

{% embed url="<https://youtu.be/1pCXNfhPtJY>" %}
Example streamed message with code execution
{% endembed %}

## 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  | <p><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span> great when you know the content of the message upfront<br><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span> suited when you need to inform the user quickly about something</p> | :x:Generally not suited to send multiple messages in a row                                                                                       |
| Stream   | <p><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span> feel more natural / human-friendly<br><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span> suited for long-running tasks in the background<br></p>                                 | :x: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. |

{% hint style="info" %}
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.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.agentlabs.dev/core-concepts/messages/one-off-vs-stream.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
