Support AG-UI projection for Agent-as-Tool / nested agent runs #1335
duohelingdukele
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Proposal: Support AG-UI projection for Agent-as-Tool / nested agent runs
I’d like to discuss whether TanStack AI should provide a first-class way for an Agent used as a Tool to stream its internal state back to the outer AG-UI stream.
The use case is hierarchical / delegated agents:
From the UI perspective, I’d like to render this as a nested execution tree rather than flattening all inner tool calls into the outer conversation.
For example:
Current situation
Today this can be implemented manually with nested
chat()calls.A parent server tool can:
chat()emitCustomEvent()Conceptually:
This works, but the difficult part is preserving the nested ownership relationship.
For a first-level child agent, the outer
onCustomEvent(..., context.toolCallId)can associate the child trace with the parent tool call.For recursive agents, however:
events from
browser_agentmay still be transported through the outerresearch_agenttool execution context.So the client-visible transport
toolCallIdmay still becall_A, while the actual parent of the browser run iscall_C.That means nested agent execution needs an explicit relationship such as:
or an equivalent built-in representation.
What I’d like to see
Something similar to an Agent-as-Tool API that preserves nested AG-UI events automatically.
For example, conceptually:
Then the outer stream could expose the child run with enough context to reconstruct:
I don’t think this necessarily requires inventing new variants of every AG-UI event.
A small envelope may be enough:
The important part is that the parent relationship is attached by the runtime, rather than reconstructed from event ordering on the client.
Relationship with
@tanstack/ai-orchestrationThe current Workflow-backed orchestration direction looks very promising because an agent call already has a stable Workflow step identity.
Internally, the current experimental implementation already emits something conceptually like:
for chunks produced by an agent step.
That seems very close to what is needed for UI ownership.
However, Workflow-managed agent steps and Agent-as-Tool delegation are slightly different use cases.
Workflow orchestration naturally represents:
while Agent-as-Tool needs to represent:
For autonomous hierarchical agents, the second relationship is important because the LLM itself chooses when to delegate.
Persistence / replay
If nested agent events are projected as normal AG-UI events, it would also simplify persistence considerably.
Ideally:
Then applications would not need a second custom trace event log just to rebuild the sub-agent tree after reconnect.
For longer-term history, applications could still persist a projected execution snapshot rather than every reasoning/text delta.
Questions
Would the TanStack AI maintainers be open to first-class support for:
I think this would complement the Workflow-backed orchestration work rather than compete with it:
For applications building a full agent execution UI, having this relationship represented by the runtime would remove a significant amount of custom middleware,
CUSTOMevent bridging, and client-side trace reconstruction.All reactions