Message queuing lets users send multiple messages in rapid succession without waiting for the agent to finish processing the current one. Each message is accepted immediately, queued for the active thread, and processed sequentially, giving you full visibility and control over the pending work.Documentation Index
Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-cbuipl-1779916257-33d1bcf.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
This feature requires the LangGraph Agent Server. Run your agent locally with
langgraph dev or deploy it to LangSmith to use this pattern.Why message queues?
In a typical chat interface, users must wait for the agent to finish responding before sending another message. This creates friction in several scenarios:- Batch questions: a user wants to ask five related questions at once rather than waiting for each answer
- Follow-up chains: submitting clarifications or additional context while the agent is still working
- Automated testing sequences: programmatically sending a series of prompts to validate agent behavior
- Data entry workflows: feeding structured inputs one after another for processing
How it works
PassmultitaskStrategy: "enqueue" when you want a submission to wait behind
the currently running request. While the agent is processing, queued submissions
are added to the active thread’s queue. Once the current run completes, the
next queued message is dispatched automatically.
Read queue state with the companion queue helper for your framework:
| Property | Type | Description |
|---|---|---|
queue.entries | SubmissionQueueEntry[] | Array of all pending queue entries |
queue.size | number | Number of entries currently in the queue |
queue.cancel(id) | (id: string) => Promise<void> | Cancel a specific queued entry by ID |
queue.clear() | () => Promise<void> | Cancel all queued entries |
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for this queue entry |
values | object | The input values (including messages) that were submitted |
options | object | Any additional options passed with the submission |
createdAt | string | ISO timestamp of when the entry was created |
Setting up useStream
Connect useStream to your agent, then pair it with the submission queue
helper for your framework. Call stream.submit() to send messages while a run
is in progress; pass multitaskStrategy: "enqueue" on submissions that should
wait behind the active request. Read queue.entries and queue.size to render
pending work, and use queue.cancel() or queue.clear() to remove items before
they start processing.
The code examples use
useStream<typeof myAgent> for type-safe stream state. See Type inference for Python or JavaScript backends.Displaying the queue
Build aQueueList component that shows each pending message with a cancel button. This gives users visibility into what’s waiting and the ability to remove items they no longer need.
Cancelling queued messages
You have two levels of cancellation:Cancel a single entry
Remove a specific message from the queue by its ID. The agent will skip it and move to the next entry.Clear the entire queue
Remove all pending messages at once. Useful when the user changes context or wants to start over.Cancelling a queue entry only affects messages that have not yet started
processing. If the agent is already working on a message, cancelling it from
the queue has no effect. Use
stream.stop() to interrupt the current run.Chaining follow-up submissions with onCreated
The onCreated callback fires when a new run is created, giving you a hook to submit follow-up messages programmatically. This is useful for building multi-step workflows where the next question depends on the previous submission being accepted.
Starting a new thread
When a user wants to begin a fresh conversation, update the reactivethreadId
that you pass into the stream. Passing null clears the current thread binding;
the next submission creates a new thread.
Best practices
- Limit queue size: While there is no hard client-side limit on queue size, be mindful that very large queues can degrade user experience. Consider showing a warning when the queue exceeds a reasonable threshold (e.g., 10 items).
- Show queue position: Number each queued item so users know the processing order.
- Preserve input focus: Keep the input field focused after submission so users can type the next message immediately.
- Animate transitions: Smoothly move items from the queue panel into the message list as they start processing.
- Handle errors gracefully: If a queued message fails, surface the error without blocking subsequent queue entries.
- Debounce rapid submissions: For automated or programmatic submissions, add a small delay between messages to avoid overwhelming the server.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

