Skip to content

feat: [2/2] Execute multi-agent HTTP Responses and verify recorded contracts - #373

Merged
franciscojavierarceo merged 20 commits into
mainfrom
multi-agent-http-support-pr-2
Sep 29, 2026
Merged

franciscojavierarceo merged 20 commits into
mainfrom
multi-agent-http-support-pr-2

Conversation

@maralbahari

@maralbahari maralbahari commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

issue: #229

PR 1 teaches the gateway to represent multi-agent Responses items, but does not run agents. This PR adds the HTTP runtime: a stored request with multi_agent.enabled: true can spawn and coordinate subagents, return their work in one Responses result or SSE stream, and resume the tree through previous_response_id. The multi_agent option belongs to the gateway; it is not forwarded as a provider option. The gateway exposes collaboration actions to the model as gateway-owned function tools while retaining ordinary client tools such as web search, MCP, and local shell. This is separate from parallel_tool_calls, which controls tool-call parallelism within a model turn rather than agent lifecycles.

Request admission requires store: true, rejects a zero concurrency limit, and rejects reasoning summaries and explicit compaction triggers with multi-agent enabled. An omitted max_concurrent_subagents uses three active descendant slots; the root is separate from that limit. The gateway validates continuation against the stored tree, rather than trusting client-supplied collaboration transcript items to recreate an agent.

Implementation and review boundary

  • EngineOrchestration selects the existing single-agent path or a MultiAgentRun. The response coordinator owns the agent registry, task ownership, mailboxes, pending client calls, shared response budget, completion, and persistence. Each agent has its own AgentPipeline, tool registry, context, and round progress. This split lets agent tasks run concurrently without creating an independent public response per child. Collaboration functions implement spawning, messaging, follow-up, waiting, interruption, and listing; per-agent guidance narrows the assigned job and discourages unnecessary delegation and waits.
  • Each upstream agent round is identified separately. A bounded agent-frame channel feeds one public response assembler, which assigns public output positions and SSE sequence numbers and emits a single terminal response. Streaming delivery acknowledges accepted frames and cancels outstanding work when the client stream is dropped. The merge with current main keeps its execution and inference-round telemetry in this path. Nonstreaming uses the same agent results and response assembly.
  • A versioned StoredTreeSnapshot records the canonical agent tree, histories, and pending-call relationships. Checkpoint loading validates references and limits before constructing live tasks. Typed commit_tree methods on the existing response and conversation handlers persist the tree with the public result; storage serialization remains at that boundary. Continuations match client outputs to their owning agent and call ID. Public encrypted agent-message content remains separate from gateway-owned canonical mail.
  • Automatic compaction works on an immutable resolved prefix for one agent. CompactionPlan carries the agent identity and context generation; CompactionCommit::{Applied, Stale} replaces that prefix only if the generation still matches. This preserves intervening mail, pending calls, and appended history. Discovery items and prompt-cache settings are retained through the compaction request. The existing single-agent compaction path is still available when multi-agent is disabled.

The runtime code is divided across engine/agent_turn.rs, engine/multi_agent/*, executor/multi_agent/*, and pipeline delivery/projection modules so the coordinator, per-agent execution, registry, collaboration actions, streaming, checkpoint validation, and compaction each have a clear owner. The resulting file-size baseline change removes the old oversized engine.rs entry; a narrow documented allowance covers the expanded request-admission module.

Recorded scenario comparison

Gateway: Qwen/Qwen3.6-35B-A3B-FP8. OpenAI reference: gpt-5.6-sol. Counts represent unique calls across each complete session, including client-tool continuations, rather than repeated SSE appearances. Model-generated text, reasoning, names, and action counts are not expected to match exactly.

Proposals

Prompt: Delegate retrieval and assessment of proposals alpha and beta, then recommend one using the returned data. Tests parallel delegation and client-owned function-call continuation.

Metric OpenAI nonstream Gateway nonstream OpenAI stream Gateway stream
Successful spawns 2 2 2 2
Collaboration calls 17 6 18 9
Waits / timeouts 4 / 4 4 / 2 7 / 5 1 / 0
Function calls / returned outputs 6 / 6 4 / 4 4 / 4 2 / 2
Completed Yes Yes Yes Yes

Gateway streaming recovered from six invalid list_agents requests containing timeout_ms.

Review

Prompt: Delegate correctness, security, and test-coverage review of a Python cache using pickle.loads on unauthenticated input, then consolidate findings. Tests agent creation, messaging, and completion without external tools.

Metric OpenAI nonstream Gateway nonstream OpenAI stream Gateway stream
Successful spawns 3 3 3 3
Collaboration calls 6 9 7 7
Waits / timeouts 3 / 0 4 / 0 3 / 1 4 / 1
Agent messages 6 6 6 6
Completed Yes Yes Yes Yes

Gateway nonstreaming rejected one extra spawn at the concurrency limit.

Mixed tools

Prompt: Delegate Python CSV web research, tiktoken research through the remote GitMCP server, and the local-shell calculation python3 -c 'print(sum(range(1, 11)))', then combine the findings. Tests mixed tool ownership and continuation with mocked client shell outputs.

Metric OpenAI nonstream Gateway nonstream OpenAI stream Gateway stream
Successful spawns 3 3 4 3
Collaboration calls 18 16 24 13
Waits / timeouts 7 / 4 9 / 5 11 / 6 6 / 0
Web / MCP calls 2 / 2 1 / 2 2 / 2 2 / 4
Shell calls / returned outputs 3 / 3 2 / 2 4 / 4 2 / 2
Completed Yes Yes Yes Yes

OpenAI streaming created a replacement fourth agent over the session; the limit applies to concurrent subagents. Gateway repeated some shell work. Shell outputs are scripted fixtures, not actual shell executions.

All twelve recordings reached completed responses. Collaboration calls have matching outputs, and streaming sequence and item-identity checks passed. Successful gateway list_agents results use agent_name and agent_status, including completed answer text. The Rust cassette comparison tests passed: 7 passed, 0 failed, 1 optional test ignored (cargo test -p agentic-server-core --test multi_agent_contract_test --offline -- --test-threads=2).

Client-owned tools OpenAI nonstream Gateway nonstream OpenAI stream Gateway stream
Successful spawns 3 3 3 3
Collaboration calls 8 5 15 5
Waits / timeouts 2 / 1 2 / 0 4 / 3 2 / 0
Tool-search calls / returned outputs 6 / 6 2 / 2 6 / 6 2 / 2
Discovered function calls / returned outputs 2 / 2 2 / 2 4 / 4 2 / 2
Custom calls / returned outputs 1 / 1 1 / 1 1 / 1 1 / 1
Completed Yes Yes Yes Yes

Stack and scope

This is PR 2 of 2, branch multi-agent-http-support-pr-2 at 96494f8, targeting PR 1 multi-agent-http-support-pr-1 at b8e71e6.

Test Plan

  • cargo test
  • recoded cassettes

@maralbahari
maralbahari added this pull request to stack #374 September 25, 2026 05:35
@maralbahari maralbahari changed the title Multi agent http support pr 2 [2/2] Execute multi-agent HTTP Responses and verify recorded contracts Sep 25, 2026
@maralbahari maralbahari changed the title [2/2] Execute multi-agent HTTP Responses and verify recorded contracts feat: [2/2] Execute multi-agent HTTP Responses and verify recorded contracts Sep 25, 2026
@maralbahari
maralbahari force-pushed the multi-agent-http-support-pr-2 branch from 96494f8 to 86be78b Compare September 25, 2026 06:12
@franciscojavierarceo

franciscojavierarceo commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

the PR says multi-agent WebSocket support is separate work, but the WebSocket handler accepts this request shape and sends it through the executor. generate:false takes the local completion path, so a socket client can receive a successful multi-agent response without the durable tree needed for continuation. we should reject multi_agent.enabled on WebSocket until that lifecycle is covered, or add end-to-end coverage and treat it as supported.

@maralbahari

Copy link
Copy Markdown
Collaborator Author

the PR says multi-agent WebSocket support is separate work, but the WebSocket handler accepts this request shape and sends it through the executor. generate:false takes the local completion path, so a socket client can receive a successful multi-agent response without the durable tree needed for continuation. we should reject multi_agent.enabled on WebSocket until that lifecycle is covered, or add end-to-end coverage and treat it as supported.

Added a guard in the shared response-session rehydration path used by WebSocket execution and generate:false. It rejects multi-agent requests before inference or local completion, checking both explicit configuration and settings inherited from a stored agent tree. HTTP multi-agent support remains available. A TODO tracks WebSocket support and lifecycle tests as follow-up work.

@maralbahari

Copy link
Copy Markdown
Collaborator Author

@franciscojavierarceo Thanks for the review! The changes are ready for another review. I’ve addressed the comments and added OpenAI reference and gateway cassette recordings covering tool search, discovered function calls, and custom tool calls in multi-agent runs, for both streaming and non-streaming. These recordings and the corresponding Rust integration tests account for the additional files in the PR.

Base automatically changed from multi-agent-http-support-pr-1 to main September 29, 2026 10:59
@maralbahari

Copy link
Copy Markdown
Collaborator Author

Addressed the remaining compatibility gaps and refreshed the gateway recordings:

  • Root completion now leaves active children running until they finish or pause for client tool outputs.
  • max_tool_calls is explicitly rejected with multi-agent enabled, including inherited configurations.
  • list_agents tolerates extra model-generated argument fields, avoiding the repeated validation-error loop.

All eight gateway recordings across review, proposals, mixed-tools, and client-owned tools pass the Rust contract comparisons against OpenAI references. These validate lifecycle and call/output relationships while allowing model-dependent differences.

@franciscojavierarceo
franciscojavierarceo merged commit 240cb1d into main Sep 29, 2026
22 checks passed
haoshan98 added a commit that referenced this pull request Sep 30, 2026
## Summary

Several user-facing docs had fallen behind `main` or contradicted each
other and the code. This PR brings them in line with what has shipped.
It changes documentation only.


**Corrected claims**
- README listed the Messages API as "🚧 Planned" while another README
section documents `/v1/messages`. It is now listed as shipped; only
stateful Messages stays planned.
- README and `docs/index.md` advertised "Background execution" and
gateway-executed file search. Neither exists yet: background mode is
#357, and `file_search` declarations parse but are dropped before
inference (`tool/normalize.rs`). Both claims are removed.
- `docs/api/index.md` quoted fixed WebSocket and executor limits (256
KiB SSE lines, 1 MiB events and response budget). These now come from
the configurable `[responses]` settings, which default to 16 MiB and 8
MiB.
- `docs/api/index.md` listed only some of the conditions that route a
Responses request through the executor. The list now also includes
non-function tools, `multi_agent.enabled`, and tool-search state,
matching `handler/http/responses.rs`.
- CHANGELOG listed Tavily under 0.8.0, but it merged on Sep 28, after
the Sep 19 release. The two Tavily entries move to `[Unreleased]`.

**Newly documented features**
- README: a multi-agent Responses section with an example and the
gateway's limits (`store: true`, HTTP/SSE only, default of 3 concurrent
subagents, no `max_tool_calls` or reasoning summaries). Also new rows in
the API table for `/v1/responses/compact`, the full Conversations
routes, `/v1/messages` with `/v1/messages/count_tokens`, and
Swagger/OpenAPI (`ENABLE_OPENAPI_DOCS`). The features list, diagram, and
tool ownership table now include MCP, the code interpreter, Claude Code,
compaction, and OpenTelemetry.
- `docs/api/index.md`: new sections for `GET
/v1/responses/{response_id}`, multi-agent, Conversations, and Messages.
- CHANGELOG `[Unreleased]` was empty. It now has entries for #345, #347,
#349, #351/#370, #354, #368, #369, #372/#373, #380, and #387.

**Roadmap**
- ROADMAP.md marks multi-agent HTTP execution as shipped, with WebSocket
injection (#300) and stateless requests (#393) still open. It adds a
status note for Messages, a code interpreter entry, and a file search
item linking #34 and #356.
- README "Roadmap at a Glance" checks off Messages and Conversations and
adds unchecked items for multi-agent, file search, and stateful
Messages.

**Smaller fixes**
- The repository layout in README and AGENTS.md now lists
`agentic-llm-d`, `agentic-cli-docs`, and `python/agentic_api/`.
- ARCHITECTURE.md's list of multi-agent rejections now includes
`max_tool_calls`, matching `executor/rehydrate.rs`.
- `mkdocs.yaml` adds the existing but unlinked `design/shell-tool.md` to
the nav.

**Not changed:** the README's "Rust 1.85+" badge is wrong (1.85 cannot
build the lockfile, see #377), but #379 already updates it to 1.88 along
with `rust-version` and a CI check, so this PR leaves it alone to avoid
a conflict.

Signed-off-by: haoshan98 <[email protected]>
@maralbahari
maralbahari deleted the multi-agent-http-support-pr-2 branch October 1, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants