OpenAI DevDay 2026 後 AI Agent 需要哪些 JSON 資料結構?2026 從 Request、Tool Call 到 Agent State 完整解析
DevDay 把路由(Decisions)和執行(Responses / Agents)拆開,但宿主仍要維護同一條鏈:模型產出 call,你寫回 result,再把 response_id 與 facts 存進 state,決定下一跳請求長什麼樣。本文只拆這五段 JSON,不講 workflow 怎麼搭、也不復述 Agents API 的 session 欄位表。
閱讀前速覽
| 階段 | 典型 JSON 形狀(Responses 為主) | 誰寫入 |
|---|---|---|
| Request | POST /v1/responses:model、input、tools;續聊用 previous_response_id | 你的 orchestrator 在 state.next 為 submit_request 時組裝 |
| Tool Call | 輸出項 type function_call;call_id + name + arguments 字串 | 模型;宿主解析 arguments 後執行 |
| Tool Result | 輸入項 function_call_output;同一 call_id;output 為字串化 JSON | 宿主執行完副作用後寫回 |
| Agent State | run_id、phase、ids、facts、raw_tool_outputs、next(宿主自定義) | 僅宿主持久化;Decisions 的 answers 可對映進 facts |
| Next Action | 下一請求:僅 function_call_output,或新 user 訊息 + previous_response_id | 宿主按 state.next.kind 選擇,不是模型自由文字 |
事實截至 2026-10-28:Responses function_call 指南、Decisions GA input_json、DevDay 2026 recap。A-1042、call_3c91、run_demo_7c 為虛構。
至少五份 JSON:請求、呼叫、結果、狀態、下一跳
DevDay 之後,多數自研 Agent 仍用 Responses 工具循環 跑副作用:Decisions 只返回 answers,不會替你執行 lookup。你要在記憶體或資料庫裡維護一份 Agent State,把「最後一次 response_id」「pending call_id」「已確認事實(order_id、route)」與「下一動作列舉」分開存。Agents API 託管長任務時,Call/Result 會換成 session 事件流裡的 turn_id——那是另一條鏈,見專門一篇。
- Request:帶 tools 與 optional previous_response_id;不要把整段 state stringify 進 prompt。
- Call / Result:arguments 與 output 都是字串;執行前過 Schema,寫回必須同一 call_id。
- State + Next:facts 是已驗證欄位;next 告訴 orchestrator 發 Result 還是新開 Request。
三層 workflow 分工見 Workflow 實測;Agents API 的 turn_id / required_actions 見 Agents API 資料結構;舊欄位遷移見 API 遷移。
Request → Call → Result → State → Next
1. Request。 當 state 裡已有 route_choice=lookup,發起帶工具的 Responses 請求,並掛上上一輪 response_id:
{
"model": "gpt-6-luna",
"previous_response_id": "resp_8k1a",
"input": [{
"role": "user",
"content": [{
"type": "input_text",
"text": "Order A-1042 was routed to lookup. Call the tool if needed."
}]
}],
"tools": [{
"type": "function",
"name": "lookup_order",
"strict": true,
"parameters": {
"type": "object",
"properties": {
"order_id": { "type": "string", "pattern": "^[A-Z]-\\d{4}$" }
},
"required": ["order_id"],
"additionalProperties": false
}
}]
}
2. Tool Call。 響應 output 裡出現待執行的 function_call;先更新 state.phase=awaiting_tool 與 pending_call_id:
{
"type": "function_call",
"call_id": "call_3c91",
"name": "lookup_order",
"arguments": "{\"order_id\":\"A-1042\"}"
}
3. Tool Result。 宿主執行 lookup_order 後,構造寫回項(仍是 JSON,但放在下一請求的 input 陣列裡):
{
"type": "function_call_output",
"call_id": "call_3c91",
"output": "{\"order_id\":\"A-1042\",\"status\":\"paid\",\"amount\":99.00}"
}
4. Agent State。 官方 API 不替你存這份物件;它把 response_id 與業務 facts 綁在一起,並宣告下一動作:
{
"run_id": "run_demo_7c",
"phase": "awaiting_tool",
"ids": {
"last_response_id": "resp_9f2b",
"pending_call_id": "call_3c91"
},
"facts": {
"order_id": "A-1042",
"route_choice": "lookup"
},
"raw_tool_outputs": {},
"next": { "kind": "submit_tool_output", "call_id": "call_3c91" }
}
5. Next Action。 當 next.kind 為 submit_tool_output,下一跳請求往往只有 function_call_output + previous_response_id:
{
"model": "gpt-6-luna",
"previous_response_id": "resp_9f2b",
"input": [{
"type": "function_call_output",
"call_id": "call_3c91",
"output": "{\"order_id\":\"A-1042\",\"status\":\"paid\",\"amount\":99.00}"
}]
}
五段 JSON 靠 call_id 與 response_id 對齊
DevDay 後常見錯位是:Decisions 的 choice 寫進 facts,卻忘了更新 phase,導致重複發同名 function_call。用下表核對:
| 段 | 必須穩定的鍵 | 連到誰 |
|---|---|---|
| Request | previous_response_id、tools[].name | state.ids.last_response_id |
| Tool Call | call_id、arguments | state.ids.pending_call_id |
| Tool Result | call_id、output 字串 | 與 Call 同一 call_id |
| Agent State | facts.*、phase、next.kind | Decisions answers → facts;Response id → ids |
| Next Action | input[] 僅 output 或新 user 內容 | state.next 驅動,不是模型 prose |
Decisions GA 後可在 input 裡帶 conversation history(含 function_call_output)。那是證據,不是 state 替代品——facts 仍應由宿主在寫回 tool 後更新。
五步走通一條可審計循環
在 staging 用虛構 order_id 跑通後再接 Decisions 路由:
- 初始化 state。run_id、空 facts、next=submit_request。
- 收 Decisions answers。把 route choice 寫入 facts,phase=ready_for_tool_request。
- 發 Request,收 Call。儲存 response_id 到 ids;校驗 arguments 再執行。
- 寫 Result,更新 state。raw_tool_outputs 存全量;facts 只留允許下游用的欄位。
- 按 next 發下一跳。需要摘要時再開一輪 Responses structured output,不要與 raw 混物件。
Agents API 路徑把 Call/Result 換成 session 事件,但「宿主 state 存 facts + next」不變。
除錯時攤開 Request 與 State 各一份
90% 的「Agent 失憶」是 response_id 或 call_id 漂了,不是模型不會推理。
- 用 格式化 展開 arguments;用 Schema 校驗 校驗 tool 參數與 facts 子集 schema。
- 用 JSON Diff 對比兩次 state、或 Call arguments 與 facts.order_id。
- 用 JSONPath 從 raw_tool_outputs 抽欄位,確認 facts 沒漏複製。
- 小步更新 state 時用 JSON Patch 看 RFC 6902 是否符合你的 phase 列舉。
- JSONSort 本地處理;不要上傳生產 ticket 或金鑰。
五段 JSON 都能按 ID 重建,你才真正擁有 Agent State,而不是把歷史 messages 當資料庫。
常見誤區
- 把 messages 陣列當 state。官方 history 不含你的 phase / next 列舉。
- arguments 當物件直接執行。必須先 JSON.parse,再過 Schema。
- 換新 call_id 寫 Result。Harness 會卡住;async 工具也要原 call_id。
- facts 與 raw_tool_outputs 混寫。下游只讀 facts,審計才讀 raw。
- 忽略 previous_response_id。續聊丟 reasoning 項或重複 tool 定義。
- Decisions choice 當成已執行 tool。choice 只進 facts,Call 仍要單獨一輪。
FAQ
Agent State 必須是 JSON 檔案嗎?
形狀建議是 JSON 物件,便於 Schema 校驗與 Diff;存 Redis/SQL 時仍是同一欄位合約。
function_call 裡的 id 和 call_id 用哪個?
2026 Responses 寫回以 call_id 對齊 function_call_output;遷移文列出了舊欄位對照。
Decisions answers 要進 Request 嗎?
不必 stringify 全部 answers;把結論寫入 state.facts,Request 裡只帶必要 user 文字或 input_json 證據。
和 Agents API JSON 資料結構一文有何區別?
那篇講 session / turn_id / required_actions;本篇講 DevDay 後最常見的 Responses 宿主循環。
next.kind 要標準化嗎?
建議在團隊內固定列舉(submit_tool_output、submit_request、wait_human),便於日誌與重放。
結論
DevDay 2026 之後,AI Agent 開發的核心 JSON 不是「更大 prompt」,而是五段職責清晰的結構:Request 發起、Call 宣告副作用、Result 寫回、State 由宿主擁有、Next 由 state 驅動。Decisions 隻影響 facts,不替代 Call/Result。
先定 state schema,再對接 API 欄位。模型仍只產 Call;是否執行、下一步發什麼,永遠是宿主的 JSON 決策。
延伸閱讀
- DevDay 後 Agent Workflow 實測 Decisions / Responses / Agents 三層分工
- Agents API JSON 資料結構 turn_id、required_actions 與 session 鏈
- API 遷移 call_id 與寫回形狀
- JSON Patch 小步更新 state.phase 與 facts
- 全部文章 更多 JSON 與 AI 開發筆記
更新記錄: 首次發布