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 runimport 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消息何时被读取
在模型的下一轮之前、当前轮次的工具都已返回之后。已在运行的工具绝不会因此被中断。即将结束的运行(模型已经答完)会再多进行一轮,因此最后一秒写下的消息也不会丢失。
当没有运行时
它返回 { queued: false, reason: "not_running" },且不保留任何内容:在 run() 之前、运行结束之后,或在 stop() 之后。请用 run() 将文本作为新消息发送。
未被读取的内容
如果运行在读取之前结束——被停止、预算用尽、步数用尽或失败——消息会出现在 result.unsent 中,形式为 [{ id, text }]。可以把它放回输入框,或作为下一条消息发送。
图像图像
{ message, inputs: [{ type: "image", content, mime }] } 会把图片与文本一起加入队列。它们随消息进入对话,就像 run() 的输入一样。
在 Python 中
agent.run() 会阻塞,因此 agent.queue() 要从另一个线程调用——例如界面或 on_event 回调。它是线程安全的。SDK Python 0.2.0+。