Skip to content

Sub-agent dispatch via database queue — durable parallelism across sessions

Use RedDB's native queue to distribute agent tasks across workers and plan for retries and recovery.

On this page

Give each worker a task

A queue can hold work independently of the agent session that created it. Workers in the same consumer group can read tasks, run them, and acknowledge successful deliveries. This example uses RedDB’s native queue commands; it does not depend on PostgreSQL, triggers, or LISTEN/NOTIFY.

For a complete walkthrough of setup and recovery considerations, see cross-session task queues with RedDB.

Start RedDB locally

bash
red server --http-bind 127.0.0.1:5000 --path ./agent-tasks.rdb --dev

The --dev flag disables authentication. Use it only for local development on a trusted machine. In a second terminal, define a helper for the HTTP query endpoint; this example requires curl and jq:

bash
query() {
  curl -fsS http://127.0.0.1:5000/query \
    -H 'content-type: application/json' \
    --data "$(jq -cn --arg query "$1" '{query: $query}')"
}

Dispatch and read tasks

Create a queue, configure its dead-letter queue and make a consumer group:

bash
query 'CREATE QUEUE agent_tasks WITH DLQ agent_tasks_failed MAX_ATTEMPTS 3'
query 'QUEUE GROUP CREATE agent_tasks workers'
query "QUEUE PUSH agent_tasks 'review-issue-145'"
query "QUEUE PUSH agent_tasks 'review-issue-146'"

Each worker can read from the same group with its own consumer name:

bash
query 'QUEUE READ agent_tasks GROUP workers CONSUMER worker1 COUNT 1'
query 'QUEUE READ agent_tasks GROUP workers CONSUMER worker2 COUNT 1'

The response contains the message ID and payload. The payload can identify work described in your application. Run the agent using your own worker process and save any results and checkpoints in storage you have tested for your deployment.

Acknowledge after saving the result

Once processing and required side effects are complete, acknowledge the delivery with the message ID returned by the read:

bash
# Replace 1028 with the message_id from QUEUE READ.
query "QUEUE ACK agent_tasks GROUP workers '1028'"

This tuple-based acknowledgement works in the tested RedDB 1.26.8 release, but the engine warns that it is deprecated in favor of a delivery ID. The tested HTTP read response did not expose that ID. Check the queue contract of your deployed release before relying on this example in production.

A worker can fail after an external action and before acknowledging a message. Expect retries and make side effects idempotent or reconcile them in your application. Results and completion notification require application code; the queue commands above do not create a notification channel or a result store.

Before production, test a worker crash, redelivery, checkpoint recovery, and the dead-letter path with your actual storage configuration. The queue documentation covers the available operations.

Get the next dispatch.

New essays on multi-model storage, RAG, agents, security. No spam.

No spam. Unsubscribe anytime.