# queue()

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

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

ترسل رسالة بينما يعمل الوكيل. تنتظر الأدوات الجارية، ثم تذهب إلى النموذج قبل دوره التالي — ويجيب عنها التشغيل نفسه. 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}

قبل دور النموذج التالي، بعد أن تجيب أدوات الدور الحالي. لا تُقاطَع من أجلها أي أداة قيد التشغيل. والتشغيل الذي كان على وشك الانتهاء — إذ أنهى النموذج إجابته — يستمر دورًا إضافيًا، فلا تضيع رسالة كُتبت في الثانية الأخيرة.

## عندما لا يعمل شيء {#not-running}

ترد بـ `{ queued: false, reason: "not_running" }` ولا تحتفظ بشيء: قبل `run()`، أو بعد انتهائه، أو بعد `stop()`. أرسل النص كرسالة جديدة باستخدام `run()`.

## ما لم يُقرأ {#what-is-left}

إذا انتهى التشغيل قبل قراءتها — أُوقف، أو نفدت الميزانية، أو نفدت الخطوات، أو فشل — تعود الرسالة في `result.unsent` بالشكل `[{ id, text }]`. أعدها إلى حقل الكتابة، أو أرسلها كرسالة تالية.

## صورة {#images}

`{ message, inputs: [{ type: "image", content, mime }] }` يضع صورًا في الطابور مع النص. وتدخل المحادثة مع الرسالة، مثل مدخلات `run()`.

## في Python {#python}

`agent.run()` يحجب التنفيذ، لذا يُستدعى `agent.queue()` من خيط آخر — واجهة، أو دالة رد نداء `on_event`. وهو آمن بين الخيوط. SDK Python 0.2.0+.

- [unqueue()](/ar/sdk/ref/local-agent/unqueue): استرجاع رسالة.
- [user_message](/ar/sdk/agent/events/user-message): الحدث عند قراءتها.
- [stop()](/ar/sdk/ref/local-agent/stop): ما يحدث للطابور.

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