cyberestro on X: a Codex subagent on a local Qwen server's Responses API (qwen, http://127.0.0.1:30010/v1) got "compaction: qwen (qwen, …) answered the summary request 400 Bad Request: qwen: Unsupported input item: agent_message". agent_message is the item Codex's MultiAgentV2 hands a subagent its task in (author, recipient, input_text content, as #5259's and plugins#61's requests carry it). Two gaps, both fixed: - The compaction's fallback for an input kind refused (inputKindRefused, #5181, #5259) read only "unsupported_input_item" and "unknown item type". inputKindWords now reads "unsupported input item" with spaces too, so the summary is asked again with the conversation as text, the agent_message as the user's turn (itemText), then compacted locally. - The normal path relayed every subagent turn to the same server with the agent_message as Codex sent it, and gave the 400 back. passthrough now treats that refusal, on a request carrying an item other than a message, function call, its output or reasoning (hasOtherItem), like a custom tool refused (#2656): the model is marked (inputKindsRefused) and the turn is translated on the same API, where agent_message is the user's turn and a custom tool call a function call; later such turns go translated at once. A native compaction or sealed task still gets the refusal, and magpie's own summary ask (inCompaction) keeps its text fallback. Run (mote, mica): - New tests on the old code (ae0a78368), red: TestUnsupportedInputItemTranslated (400 "qwen: Unsupported input item: agent_message", stream and not), TestInputItemRefusalWordings, TestCodexCompactQwenInputItemAsksAgainAsText (the reporter's compaction error, word for word). - Same tests green on the fix, with TestCodexCompact*, TestCustomTool*, AgentMessage, Sealed, Zed and Grok tests. - A first version also translated the summary ask; it broke TestCodexCompactUnsupportedInputItem* (asked 4 times, not 2), so the summary ask was left to its own fallback. - gofmt; go vet ./internal/gateway on darwin, GOOS=linux (nogui), GOOS=windows; go test -tags nogui -count=1 ./internal/gateway: ok (925s, this change on origin/mainc867a12c5). Not tried: a real Qwen server (the reporter's server and its exact JSON body are unknown; the fixture uses the words magpie showed), Codex end to end, and the full ./... suite (mote was running another session's).
52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// A Responses API that knows OpenAI's first input items alone — messages,
|
|
// function calls, their outputs and reasoning — turns away a request
|
|
// carrying any other: a local Qwen server answers a Codex subagent's turn
|
|
// 400 "Unsupported input item: agent_message" (cyberestro on X), the item
|
|
// MultiAgentV2 hands a subagent its task in, and Command Code's answers
|
|
// "unsupported_input_item" (#5181, #5259). A relay sends Codex's items as
|
|
// they came, so every such turn failed. The request is then translated
|
|
// on the same API, which reads an agent_message as the user's turn, a
|
|
// custom tool call as a function call, and leaves out what has no
|
|
// counterpart; and so from then on for that model, as a custom tool
|
|
// turned away is (custom_tool.go). The words are inputKindWords, which
|
|
// the compaction's summary ask reads too (inputKindRefused): that ask is
|
|
// left to its own way on, the conversation as text (inCompaction).
|
|
|
|
// inputKindsRefused is how unfit remembers model turning away input
|
|
// items other than the first ones.
|
|
func inputKindsRefused(model string) string { return "input kinds\x00" + model }
|
|
|
|
// hasOtherItem reports whether a Responses body's input carries an item
|
|
// other than a message, a function call, its output or reasoning.
|
|
func hasOtherItem(body []byte) bool {
|
|
if !bodyHas(body, `"input"`) {
|
|
return false
|
|
}
|
|
var q struct {
|
|
Input json.RawMessage `json:"input"`
|
|
}
|
|
if json.Unmarshal(body, &q) != nil {
|
|
return false
|
|
}
|
|
var items []struct {
|
|
Type string `json:"type"`
|
|
}
|
|
if json.Unmarshal(q.Input, &items) != nil {
|
|
return false
|
|
}
|
|
for _, it := range items {
|
|
switch it.Type {
|
|
case "", "message", "function_call", "function_call_output", "reasoning":
|
|
default:
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|