Skip to content

feat: subagent-as-tool v2 — streaming nested deltas #179

@rdwj

Description

@rdwj

Summary

v1 of subagent-as-tool (#165, PR #173) ships with buffered subagent execution: the
parent waits for the subagent to finish and emits a single tool result. v2 streams
the subagent's events as nested SubagentDelta events on the parent's stream so
the UI can render delegation in real time.

The forward-compat plumbing already exists. PR #173 reserved a SubagentDelta
StreamEvent variant with no emitter; this issue is to wire it up end-to-end.

What lands

  • SubagentTransport.execute_streaming() (or equivalent) returns an async
    iterator of child StreamEvents instead of a buffered SubagentResult
  • The delegate_to_agent tool re-emits child events as
    SubagentDelta(agent_name, delta) on the parent's stream
  • The parent's astep_stream consumer treats SubagentDelta as informational
    (does not feed it back to the model)
  • Cost roll-up still happens at completion — _persist_cost_data continues to
    drain _subagent_token_usage once the subagent finishes
  • UI rendering coordinated with fips-agents/ui-template (separate issue there)

Open design questions

  1. Backpressure / dropping. If the parent's consumer is slow and the
    subagent is fast, do we buffer, drop, or apply backpressure? Design doc
    suggests a SubagentDeltaDropped warning event; pick one and document it.
  2. Mid-stream subagent failure. When the subagent crashes after emitting
    partial deltas, what does the parent see? Likely a terminal SubagentFailed
    following the partial deltas, but spec the contract.
  3. Nested delegation. A subagent that itself delegates — do we flatten the
    delta stream or wrap it twice? Flattening with agent_name chains is
    probably right; verify against trace structure.

Out of scope

  • kagenti-driven discovery (separate issue)
  • Remote-side depth enforcement (separate issue)

Dependencies

  • Requires UI work in fips-agents/ui-template to render delegation visibly.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions