api_debug
Input:
[
{
"type": "message",
"role": "user",
"content": "What tools do you have now?"
},
{
"id": "rs_0fdd74348bc35ef30068f737e4176c8193a80e94c4ec936852",
"summary": [],
"type": "reasoning",
"content": null,
"encrypted_content": null
},
{
"id": "msg_0fdd74348bc35ef30068f737e448448193839077101c450ab6",
"content": [
{
"annotations": [],
"text": "I have access to a tool called \u201cget_weather,\u201d which lets me look up the current weather for a specified city. If you give me a city name, I can retrieve its current weather conditions for you.",
"type": "output_text",
"logprobs": []
}
],
"role": "assistant",
"type": "message"
},
{
"type": "message",
"role": "user",
"content": "What's the time in Shanghai right now? call the tool please"
}
]
Response:
Item with id 'rs_0fdd74348bc35ef30068f737e4176c8193a80e94c4ec936852' not found.
Input
[
{
"type": "message",
"role": "user",
"content": "What tools do you have now?"
},
{
"id": "msg_000d06e3ba7d8b460068f739af967c819097e8d97431e34655",
"content": [
{
"annotations": [],
"text": "Here\u2019s what I can use:\n\n1. Image input \u2013 I can receive and reason about images you provide.\n2. A \u201cget_weather\u201d tool \u2013 allows me to look up the current weather for a city you specify.",
"type": "output_text",
"logprobs": []
}
],
"role": "assistant",
"type": "message"
},
{
"type": "message",
"role": "user",
"content": "What's the time in Shanghai right now? call the tool please"
}
]
Response:
Item 'msg_000d06e3ba7d8b460068f739af967c819097e8d97431e34655' of type 'message' was provided without its required 'reasoning' item: 'rs_000d06e3ba7d8b460068f739aefd8c8190959e03354167b214'.
解决方案:丢弃上一轮的 reasoning item;且删除或替换 reasoning item 后的 FunctionCallItem 或 Assistant Message Item 的 id(只用删除 id 或者把 id 改成另外一个 id,只要不是之前的 id 就行,不需要删除整个 item)。
首先,这类错误只会在多轮场景下触发,原因是 openai 在接口内就对上一轮的 reasoning item 做了丢弃 (https://platform.openai.com/docs/guides/conversation-state?api-mode=responses),导致上一轮的 reasoning item id 找不到。如果手动丢弃上一轮的 reasoning item,但 openai 接口侧还是会缓存 assistant message item 的 id 和 reasoning item 的 id 的匹配,也会报错。继续把上一轮的 assistant message item 的 id 也删除掉,就不会再报错了。另一个场景是 reasoning 然后 function call 时也会触发类似的错误,解决方案也是删除上一轮的 reasoning item 和 function call item 的 id。当然,function call item 和 assistant message item 的 id 还是有作用的,更好的做法是替换为另外一个 id,而不是直接删除掉 id。
关于 openai 接口侧会缓存 assistant message item 的 id 和 reasoning item 的 id 的匹配,是因为推理引擎里需要做 prefix cache 和 kv cache,而 openai 的 reasoning item 的原始内容是不给你的,只给你 summary 的结果,它需要通过 reasoning item id 来找到对应的原始 kv cache 以便命中缓存。
