← Back to Pull requests

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

Closed
unknown closed this pull request without merging on Sep 29, 2026 20:15 UTC
View on GitHub
unknown unknown commented on Sep 25, 2026 05:35 UTC
Author

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
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: franciscojavierarceo Review duration: 6639m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #373"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%