LocalAgent

queue()

agent.queue(message | { message?, inputs? }) → { queued: true, id, position } | { queued: false, reason }

Sends a message while the agent is working. It waits for the tools in progress and goes to the model before its next turn — the same run answers it. SDK 0.5.4+.

synchronousread before the next turnnever lost
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

const running = agent.run({ message: "Clean up the Notes folder" });

// Later, while a tool is still running:
agent.queue("Also keep a copy of plan.md");
// { queued: true, id: "u1", position: 1 }

const result = await running;   // the copy was made in the same run
import threading

results = []
worker = threading.Thread(target=lambda: results.append(agent.run(message="Clean up the Notes folder")))
worker.start()

# From another thread, while a tool is still running:
agent.queue("Also keep a copy of plan.md")
# {"queued": True, "id": "u1", "position": 1}

worker.join()   # the copy was made in the same run

When the message is read

Before the next model turn, after the tools of the current turn have answered. A tool already running is never interrupted for it. A run that was about to end — the model had finished answering — continues for one more turn instead, so a message written at the last second is not dropped.

When nothing is running

It answers { queued: false, reason: "not_running" } and keeps nothing: before run(), after it ends, or after stop(). Send the text as a new message with run().

What was not read

If the run ends before reading it — stopped, out of budget, out of steps, or failed — the message comes back in result.unsent as [{ id, text }]. Put it back in the input box, or send it as the next message.

Images

{ message, inputs: [{ type: "image", content, mime }] } queues images with the text. They travel with the message into the conversation, like the inputs of run().

In Python

agent.run() blocks, so agent.queue() is called from another thread — an interface, an on_event callback. It is thread-safe. SDK Python 0.2.0+.