mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5244] [Engine] serve: accept Codex multi_agent_v2 agent_message and multi_agent_call(_output) items on /v1/responses #5361
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5361
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/5244
Author: @bsorensen110
Created: 11/4/2026
Status: 🔄 Open
Base:
main← Head:pr/responses-multi-agent-v2📝 Commits (2)
33155a0serve: accept Codex multi_agent_v2 agent_message and multi_agent_call(_output) items on /v1/responses245f203serve: preserve parent namespace tools on fork_turns=all subagent turns for KV prefix reuse📊 Changes
4 files changed (+313 additions, -23 deletions)
View changed files
📝
docs/DETAILS.md(+1 -1)📝
serve/responses.py(+118 -19)📝
serve/server.py(+2 -3)📝
serve/test_responses.py(+192 -0)📄 Description
Problem and result
Codex CLI
0.121.0+withfeatures.multi_agent_v2enabled (and the OpenAI Responses multi-agent API) sends inter-agent hops asagent_messageitems onPOST /v1/responses(codex-rs/core/src/tasks/regular.rs,codex-rs/protocol/src/models.rs), splitting each hop into aninput_textenvelope header (Message Type: ... / Task name: ... / Sender: ... / Payload:\n) and anencrypted_contentpayload part, alongside optionalmulti_agent_callandmulti_agent_call_outputreplay items (developers.openai.com/api/docs/guides/responses-multi-agent).On
main(ffa80d731),serve/responses.py:input_messages()only handlesmessage,reasoning,function_call,function_call_output,custom_tool_call,custom_tool_call_output,additional_tools, anditem_reference. Anyagent_messageormulti_agent_call(_output)item falls through to the unsupported-type branch and fails the request with HTTP 400:Additionally, when a subagent is spawned with the default
fork_turns="all"(full-history fork), Codex'scollab_tools_enabled()(codex-rs/core/src/tools/spec_plan.rs) includes thecollaborationtool namespace (spawn_agent,wait_agent,followup_task,send_message,interrupt_agent,list_agents) on/root(get_agent_path().is_none() == true), but omitscollaborationfromtoolson spawned subagents (get_agent_path().is_some()) whenever a custom model's metadata does not setmulti_agent_version = "v2". Because the chat template renders<tools>near the beginning of the system message (~token 1,500, before the first conversation-cache checkpoint at token ~13,517), droppingcollaborationfromtoolsshifts the entire remaining ~53,000 chars of inherited prompt and causes a 0-token KV prefix cache miss (0 reused + 12,974 read in 13,037 ms) on the first turn of every spawned subagent.Related upstream work: open draft PR #4210 (
Anemone95:responses-agent-message,a00a4be7c) also addressesagent_messageitems by rewritingencrypted_contentparts intoinput_textand passing the list to_content(). This branch (33155a053+245f20314, split into two atomic commits onffa80d731) is offered as a fuller alternative (or can be folded into #4210) that additionally:authorandrecipient(orsender/agent.agent_namefallback per the Responses API reference) in a leading[agent_message from <author> to <recipient>]routing line, and joins parts without doubling trailing newlines afterPayload:\n.strata.r1:encrypted_contentboxes whenbox["text"]is astr(matchingreasoningitem handling ininput_messages()), passes plaintext or foreign string tokens through verbatim, and degrades damaged/non-stringencrypted_content, non-stringtextparts, or unknown part types to[encrypted payload unavailable]/[payload part not rendered]without failing the whole multi-agent turn._order_tool_results()to scan back to the nearest precedingassistantmessage when anagent_message(which is ausermessage) arrives between parallel tool calls and theirfunction_call_outputitems, so tool results are still sorted by the assistant turn'scall_idorder.multi_agent_callandmulti_agent_call_outputreplay items (action/nametool call +call_id-paired tool output).(session_id, parent_thread_id)) omitted namespace tool definitions inprompt_tools()(_fork_prompt_tools) for prompt rendering only (keepingrequest_tools()'s callable parser tools andnamesmap restricted to the child request's declared tools, and leaving requests unchanged when parent ownership is not established) — turning a first-turnfork_turns="all"subagent KV prefix cache miss (0 reused + 12,974 read in 13.04s) into a 99.8% prefix cache hit (13,517 reused + 808 read in 1.78s, saving 11.25s of prefill per spawned subagent).Approach
33155a053—serve: accept Codex multi_agent_v2 agent_message and multi_agent_call(_output) items on /v1/responses):_agent_message_parts(item, author, recipient)inserve/responses.py: prepends[agent_message from {author} to {recipient}], acceptscontentas alistof parts, a plainstr, orNone, rendersinput_text/output_text/textwhentextisstrorNone(degrading non-stringtextto[payload part not rendered]),input_imageas[image], andencrypted_contentby decoding validstrata.r1:boxes whosetextis astr, passing non-prefixed strings through, and degrading non-string or damaged boxes to[encrypted payload unavailable], joining without doubling trailing newlines.kind == "agent_message"ininput_messages(), closingopen_turnand clearingthinking, and update_order_tool_results()to locate the nearest precedingassistantturn (next((messages[k] for k in range(i - 1, -1, -1) if messages[k]["role"] == "assistant"), {})).function_call(_output)/custom_tool_call(_output)branches ininput_messages()to includemulti_agent_call(readingactionwhennameis absent) andmulti_agent_call_output, and updatedocs/DETAILS.md.245f20314—serve: preserve parent namespace tools on fork_turns=all subagent turns for KV prefix reuse):_fork_prompt_tools[(session_id, thread_id)](capped at 16 entries) insideprompt_made().multi_agent_v2turn (agent_messageininput) identifies a recorded parent conversation via(session_id, parent_thread_id)inx-codex-turn-metadata(_codex_parent()) and carries an inheritedfunction_callin anamespaceomitted fromtools,prompt_tools()splices that parent conversation'snamespace.*tool definitions into the returnedshownprompt tool list after their recorded predecessor, while keepingrequest_tools()(toolsandnames) restricted to the request's declared tools.Validation
Passed:
origin/mainatffa80d731):input_messages({"input": [AM_TASK]})raisedResponsesError("input items of type 'agent_message' are not supported", "input[0].type")(RED).33155a053+245f20314, rebased onorigin/mainffa80d731/ Strata0.2.10on Linux x86_64):serve.test_responses: 49 tests, OK (1 skipped) — includes 6 new tests inMultiAgentV2(test_agent_message_item_parses,test_agent_message_encrypted_ciphertext_degrades,test_agent_message_prompt_golden,test_agent_message_between_turns_keeps_tool_pairing,test_multi_agent_call_and_output_items_parse,test_fork_turns_subagent_restores_namespace_tools_for_prefix_cache).serve.test_responses+serve.test_frontend+serve.test_server: 434 tests, OK (1 skipped).0.166.0(features.multi_agent_v2 = true) end-to-end runs onqwen3.8-flash-next-iq3_s(gfx1201, AMD Radeon AI PRO R9700, 64 GB RAM, Linux,--batch 2+STRATA_BATCH_DF2=1):spawn_agent->wait_agent->followup_task->wait_agent) and 2-way parallel subagents (fork_turns="none"+fork_turns="all",send_message,list_agents,wait_agent): all 25/v1/responsesHTTP requests returned200 OK(status: "completed").fork_turns="all"subagent prefill A/B (codex execspawning/root/arithafter/rootTurn 1 parked13,522prompt +86generated tokens):33155a053):strata serve: prompt 12974 tokens = 0 reused + 12974 read in 13037 ms (995.2 tok/s)(0 tokens reused, 13.04s prefill).245f20314):strata batch: slot 1 takes 14325 tokens (copied in 3.8 ms)/strata serve: prompt 14325 tokens = 13517 reused + 808 read in 1783 ms (453.1 tok/s)(13,517 tokens reused in 3.8 ms, 1.78s prefill — 7.3x faster, saving 11.25s per spawned subagent).Failed:
Not run:
serve/).Limits
spawn_agent/send_message/followup_task/wait_agenttool calls and replay the resultingagent_messageandmulti_agent_call(_output)items on subsequent/v1/responsesturns.encrypted_contentciphertexts encrypted with another provider's key cannot be decrypted locally and are rendered as their opaque string token.fork_turns="none"subagents intentionally start without inherited parent turns (so they do not carry a historicalcollaboration.*function_callininput); to keepcollaborationintoolsonfork_turns="none"subagents as well, set"multi_agent_version": "v2"on the model entry in Codex'smodel_catalog_json.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.