# queue()

Canonical URL: https://developers.iagenify.com/sdk/ref/local-agent/queue/
Language: en

`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+.

Status: synchronous · read before the next turn · never lost

```javascript
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
```

## When the message is read {#when}

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 {#not-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 {#what-is-left}

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 {#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 {#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+.

- [unqueue()](/sdk/ref/local-agent/unqueue): Taking a message back.
- [user_message](/sdk/agent/events/user-message): The event when it is read.
- [stop()](/sdk/ref/local-agent/stop): What happens to the queue.

```python
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
```
