快訊
  • Agents
  • LLM
  • API

Anthropic Messages API 推出 message threads:長 agent 迴圈不用每輪重傳整段對話

Anthropic 在 2026-11-02 的 API release notes 宣布:Messages API 可用 message threads(beta,header message-threads-2026-08-12),讓長對話和 agent 迴圈少傳一點、首 token 時間更穩。完整說明見官方文件〈Message threads〉。

解決什麼問題

  • 沒有 thread 時,每一輪都要把整段對話再上傳一次,API 也會再驗證、再算一次 token。
  • 有了 thread,伺服器會暫存對話;之後每輪主要只處理新的那一輪。

怎麼用(官方文件)

  • 建立:第一個請求照常送完整對話、system、tools,並加上 "thread": {"type": "create"}。回覆的 id 就是後續延續用的錨點。
  • 延續:之後只送新訊息,並加上 "thread": {"type": "continue", "previous_message_id": "<上一則回覆 id>"}。延續請求不要再送 system 或 tools。
  • SDK 有 thread helper,可幫你組請求、在 thread 找不到時重播整段對話。

限制(官方寫明)

  • Thread 是 best-effort:上次請求後約 5 分鐘過期,最晚在上次使用後 1 小時內刪除。過期後 continue 會 404,要自己用完整對話再建一個。
  • 應用程式仍是對話的真實來源:要自己留一份完整訊息,並從一開始就準備重播路徑。
  • 不支援 Message Batches、帶 thread 的 token counting、on-demand compaction 等;也不是 ZDR eligible(內容只暫存在記憶體,不會寫入持久儲存)。
  • 可用平台:Claude API、Claude Platform on AWS、Claude Models on Google Cloud(Anthropic managed)、Claude in Microsoft Foundry。
  • 計價和 rate limit 不變;模型仍會讀完整段對話,所以省的是上傳與首 token 延遲,不是把 token 帳單砍掉。

Anthropic adds message threads to the Messages API for long agent loops

On 2026-11-02 Anthropic’s API release notes said the Messages API can use message threads (beta, header message-threads-2026-08-12) so long conversations and agent loops send less and keep time-to-first-token steadier. The full guide is the official “Message threads” doc.

What it fixes

  • Without a thread, every turn uploads the whole conversation again, and the API validates and tokenizes all of it again.
  • With a thread, the server holds the conversation for a short time, so later turns mostly cover only the new turn.

How it works (from the docs)

  • Create: send the first request as usual with the full conversation, system, and tools, plus "thread": {"type": "create"}. The response id is the continue anchor.
  • Continue: send only the new messages with "thread": {"type": "continue", "previous_message_id": "<previous response id>"}. Leave system and tools out of continue requests.
  • SDKs ship a thread helper that builds these requests and can replay the full conversation if the thread is gone.

Limits (as documented)

  • Threads are best-effort: they expire about 5 minutes after the last request and are deleted no more than 1 hour after last use. A continue after expiry returns 404; create again from your own full copy.
  • Your app stays the source of truth: keep every message and plan a replay path from the start.
  • Not supported with Message Batches, token counting that includes thread, on-demand compaction, and similar; not ZDR eligible (held in memory, not durable storage).
  • Available on the Claude API, Claude Platform on AWS, Claude Models on Google Cloud (Anthropic managed), and Claude in Microsoft Foundry.
  • Pricing and rate limits are unchanged; the model still reads the full conversation, so the win is upload size and first-token latency, not a smaller token bill.

來源