Skip to content

feat(core): subagent registry + useSubagent hook - #5873

Closed
mme wants to merge 6 commits into
mainfrom
mme/subagents
Closed

mme wants to merge 6 commits into
mainfrom
mme/subagents

Conversation

@mme

@mme mme commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Draft. Adds subagent lifecycle tracking to CopilotKit core and a useSubagent hook.

  • SubagentRegistry delegate on CopilotKitCore — tracks SUBAGENT_STARTED/FINISHED/ERROR per owning agent (modeled on SuggestionEngine; owns its own per-agent agent.subscribe like StateManager). Exposed via getSubagents(agentId) + an onSubagentsChanged subscription.
  • useSubagent({ subagentRunId | subagentName, agentId? }) (react-core v2) — resolves a message's subagentRunId to a friendly name, description, and running status. Warns once (dev) when a subagentName is ambiguous.

Field name: subagentRunId (renamed from subagentId)

AG-UI renamed the attribution field because the old name implied a reusable subagent definition when the value identifies one invocation — two runs of the same subagent get two different values. See ag-ui-protocol/ag-ui#2350.

subagentId       -> subagentRunId
parentSubagentId -> parentSubagentRunId

Both sides of this package moved:

  • Reading the wire. SubagentRegistry consumes event.subagentRunId. This part had to move: the events are typed as SubagentStartedEvent etc. from @ag-ui/core, so against the renamed protocol the old field is simply absent and the registry would silently stay empty — every lookup returning undefined, with no error.
  • This package's own API. useSubagent({ subagentRunId }) and SubagentState.subagentRunId. This is a breaking change to the hook, taken now because it has never shipped — it exists only on this branch, so there is no released consumer to migrate and no alias to maintain. It also makes the API self-consistent: the hook already distinguishes subagentRunId (exact, one invocation) from subagentName (the declared subagent_type, not unique), which is precisely the split the old name blurred.

Dependency: consumed via pkg.pr.new (no @Ag-ui release needed)

Requires the AG-UI subagent event schemas + AgentSubscriber callbacks. The @ag-ui/* overrides point at the pkg.pr.new preview of ag-ui-protocol/ag-ui#2350 (https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/*@2350), which carries the rename — verified before pinning: that build's @ag-ui/core has 584 occurrences of subagentRunId and zero of subagentId.

All five overrides move together on purpose. @ag-ui/langgraph depends on @ag-ui/client, so leaving it on the old canary while client moves would resolve two incompatible copies of the same package.

Reviewer notes:

  • .npmrc keeps block-exotic-subdeps=true. An earlier revision of this description said it was set to false; that is no longer the case and the guard does not need weakening. pnpm install --frozen-lockfile succeeds against the committed lockfile with the guard on; only a fresh re-resolution of the five @ag-ui packages needs npm_config_block_exotic_subdeps=false for that single run, because @ag-ui/encoder declares @ag-ui/proto and that now resolves via url.
  • These are preview URLs from an unmerged PR, not durable artifacts, and the @2350 tag tracks that PR's latest build — only the committed lockfile holds this to one specific artifact. Swap for a released version once ag-ui#2350 merges and ships.
  • The registry and hook still have no tests of their own; the only subagent assertions live downstream in the AG-UI dojo demo. Worth adding before this leaves draft.
  • This branch is ~1750 commits behind main and will need a rebase before merge.

Verified: @copilotkit/core and @copilotkit/react-core typecheck against the renamed protocol, and react-core's 1424 tests pass. The typecheck is load-bearing rather than incidental — injecting a deliberately wrong field name produces 5 TS errors, so a green check really does prove the field matches @ag-ui/core's types.

🤖 Generated with Claude Code

Track subagent lifecycle (SUBAGENT_STARTED/FINISHED/ERROR) per owning agent
in a new SubagentRegistry delegate on CopilotKitCore, exposed via
getSubagents(agentId) and an onSubagentsChanged subscription. Add a
useSubagent({ subagentId | subagentName, agentId? }) hook to resolve a
message's subagentId to a name, description, and running status, warning
once (dev) when a subagentName is ambiguous.

Requires @ag-ui/client + @ag-ui/core >= 0.0.58; bumps the pins accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@mme
mme force-pushed the mme/subagents branch from 1fbf370 to 2a6b0ee Compare July 8, 2026 15:20
@linear

linear Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

FOR-197

PNI-275

@pkg-pr-new

pkg-pr-new Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/a2ui-renderer@5873

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/agentcore-runner@5873

@copilotkit/angular

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/angular@5873

@copilotkit/bot

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/bot@5873

@copilotkit/bot-discord

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/bot-discord@5873

@copilotkit/bot-slack

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/bot-slack@5873

@copilotkit/bot-teams

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/bot-teams@5873

@copilotkit/bot-telegram

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/bot-telegram@5873

@copilotkit/bot-ui

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/bot-ui@5873

@copilotkit/bot-whatsapp

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/bot-whatsapp@5873

@copilotkit/core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/core@5873

@copilotkit/react-core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-core@5873

@copilotkit/react-native

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-native@5873

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-textarea@5873

@copilotkit/react-ui

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-ui@5873

@copilotkit/runtime

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime@5873

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime-client-gql@5873

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/sdk-js@5873

@copilotkit/shared

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/shared@5873

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/sqlite-runner@5873

@copilotkit/voice

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/voice@5873

@copilotkit/vue

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/vue@5873

@copilotkit/web-components

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/web-components@5873

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/web-inspector@5873

commit: 40205f3

AG-UI renamed the subagent attribution field because the old name implied
a reusable subagent DEFINITION when the value identifies one INVOCATION --
two runs of the same subagent get two different values. See
ag-ui-protocol/ag-ui#2350.

  subagentId       -> subagentRunId
  parentSubagentId -> parentSubagentRunId

Applied to both sides of this package's surface:

- Reading the wire. SubagentRegistry consumes `event.subagentRunId` from
  SUBAGENT_STARTED / FINISHED / ERROR. This is the part that MUST move: the
  events are typed as SubagentStartedEvent etc. from @ag-ui/core, so
  against the renamed protocol the old field simply is not there and the
  registry would silently stay empty -- every subagent lookup returning
  undefined, with no error.
- CopilotKit's own API. `useSubagent({ subagentRunId })` and
  `SubagentState.subagentRunId`. Renaming these is what makes the API
  self-consistent: the hook already distinguishes `subagentRunId` (exact,
  one invocation) from `subagentName` (the declared `subagent_type`, not
  unique), which is precisely the definition-vs-invocation split the old
  name blurred.

This is a breaking change to `useSubagent`, taken now because the hook has
never shipped -- it exists only on this unmerged branch, so there is no
released consumer to migrate and no alias to maintain.

The @Ag-ui override repin is in the same commit rather than a separate
`chore(deps)` one because the two are atomically coupled: the rename cannot
typecheck against the old canaries, and the repin alone would leave the
registry reading a field the stream no longer emits. Splitting them would
mean one commit that is definitely broken either way.

Verified: @copilotkit/core and @copilotkit/react-core typecheck against the
renamed protocol, and react-core's 1424 tests pass. The typecheck is
load-bearing here, not incidental -- injecting a deliberately wrong field
name produces 5 TS errors, so a green check really does prove the field
matches @ag-ui/core's types.

Note: the registry and hook still have no test coverage of their own; the
only subagent assertions live downstream in the AG-UI dojo demo.
mme added a commit to ag-ui-protocol/ag-ui that referenced this pull request Aug 10, 2026
CopilotKit adopted the rename (CopilotKit/CopilotKit#5873, commit c2fca03),
so `useSubagent` now takes `subagentRunId`. The temporary
`{ subagentId: subagentRunId }` mapping is gone and the call site is plain
shorthand again.

With this, NO occurrence of the old name remains anywhere in this repo.

Repins the six @CopilotKit previews from the moving `@5873` tag to commit
`@c2fca03`, which is also a fix rather than a detail. The tag tracks the
PR's latest build, and pnpm caches a tarball against the URL STRING -- so
once the PR was rebuilt, the tag-pinned URL kept serving the stale cached
build even through `pnpm install --force` and after deleting the store
directories. Confirmed directly: the URL served a tarball with 86
occurrences of subagentRunId while the installed copy still had 86 of
subagentId. A commit-pinned URL is a new string, so it always resolves
fresh. Bump the sha to take a newer CopilotKit build.

The same trap applies to the @Ag-ui pins on the CopilotKit side, which
still use the moving `@2350` tag; worth commit-pinning there too before
that PR is rebuilt.

Verified: `demo-viewer:build` compiles against the renamed CopilotKit, and
the dojo resolves the commit-pinned preview (86 subagentRunId, 0
subagentId). files.json regenerated from source.
mme added a commit to ag-ui-protocol/ag-ui that referenced this pull request Aug 10, 2026
CopilotKit adopted the rename (CopilotKit/CopilotKit#5873, commit c2fca03),
so `useSubagent` now takes `subagentRunId`. The temporary
`{ subagentId: subagentRunId }` mapping is gone and the call site is plain
shorthand again.

With this, NO occurrence of the old name remains anywhere in this repo.

Repins the six @CopilotKit previews from the moving `@5873` tag to commit
`@c2fca03`, which is also a fix rather than a detail. The tag tracks the
PR's latest build, and pnpm caches a tarball against the URL STRING -- so
once the PR was rebuilt, the tag-pinned URL kept serving the stale cached
build even through `pnpm install --force` and after deleting the store
directories. Confirmed directly: the URL served a tarball with 86
occurrences of subagentRunId while the installed copy still had 86 of
subagentId. A commit-pinned URL is a new string, so it always resolves
fresh. Bump the sha to take a newer CopilotKit build.

The same trap applies to the @Ag-ui pins on the CopilotKit side, which
still use the moving `@2350` tag; worth commit-pinning there too before
that PR is rebuilt.

Verified: `demo-viewer:build` compiles against the renamed CopilotKit, and
the dojo resolves the commit-pinned preview (86 subagentRunId, 0
subagentId). files.json regenerated from source.
mme added a commit to ag-ui-protocol/ag-ui that referenced this pull request Aug 10, 2026
CopilotKit adopted the rename (CopilotKit/CopilotKit#5873, commit c2fca03),
so `useSubagent` now takes `subagentRunId`. The temporary
`{ subagentId: subagentRunId }` mapping is gone and the call site is plain
shorthand again.

With this, NO occurrence of the old name remains anywhere in this repo.

Repins the six @CopilotKit previews from the moving `@5873` tag to commit
`@c2fca03`, which is also a fix rather than a detail. The tag tracks the
PR's latest build, and pnpm caches a tarball against the URL STRING -- so
once the PR was rebuilt, the tag-pinned URL kept serving the stale cached
build even through `pnpm install --force` and after deleting the store
directories. Confirmed directly: the URL served a tarball with 86
occurrences of subagentRunId while the installed copy still had 86 of
subagentId. A commit-pinned URL is a new string, so it always resolves
fresh. Bump the sha to take a newer CopilotKit build.

The same trap applies to the @Ag-ui pins on the CopilotKit side, which
still use the moving `@2350` tag; worth commit-pinning there too before
that PR is rebuilt.

Verified: `demo-viewer:build` compiles against the renamed CopilotKit, and
the dojo resolves the commit-pinned preview (86 subagentRunId, 0
subagentId). files.json regenerated from source.
mme added a commit to ag-ui-protocol/ag-ui that referenced this pull request Aug 10, 2026
CopilotKit adopted the rename (CopilotKit/CopilotKit#5873, commit c2fca03),
so `useSubagent` now takes `subagentRunId`. The temporary
`{ subagentId: subagentRunId }` mapping is gone and the call site is plain
shorthand again.

With this, NO occurrence of the old name remains anywhere in this repo.

Repins the six @CopilotKit previews from the moving `@5873` tag to commit
`@c2fca03`, which is also a fix rather than a detail. The tag tracks the
PR's latest build, and pnpm caches a tarball against the URL STRING -- so
once the PR was rebuilt, the tag-pinned URL kept serving the stale cached
build even through `pnpm install --force` and after deleting the store
directories. Confirmed directly: the URL served a tarball with 86
occurrences of subagentRunId while the installed copy still had 86 of
subagentId. A commit-pinned URL is a new string, so it always resolves
fresh. Bump the sha to take a newer CopilotKit build.

The same trap applies to the @Ag-ui pins on the CopilotKit side, which
still use the moving `@2350` tag; worth commit-pinning there too before
that PR is rebuilt.

Verified: `demo-viewer:build` compiles against the renamed CopilotKit, and
the dojo resolves the commit-pinned preview (86 subagentRunId, 0
subagentId). files.json regenerated from source.
The lockfile installed TWO incompatible copies of the protocol: the PR-2350
preview carrying `subagentRunId`, and the old `0.0.59-canary.1785518626.0`
carrying `subagentId`. Any subagent-attributed event passing through a package
bound to the canary copy lost its attribution silently -- the registry would read
a field the stream no longer emits, so every lookup returned undefined with no
error. Reported in review of the rename commit.

The cause is peer auto-install, which took a while to find. `pnpm.overrides`
governs DECLARED dependencies. `@ag-ui/langgraph`, `@ag-ui/a2a` and
`@ag-ui/mcp-apps-middleware` declare `@ag-ui/core` / `@ag-ui/client` as PEERS,
and four workspace packages depended on them without declaring those peers
themselves -- so pnpm auto-installed the peers straight from the registry,
resolving to the canary and bypassing the overrides. That is why the overrides
looked ignored: they were never consulted for those edges.

Fixed the conventional way, by declaring the peers so they resolve from the graph
instead of being fetched:

- `packages/sdk-js` -- @ag-ui/core, @ag-ui/client
- `examples/v2/angular/demo-server` -- @ag-ui/core, @ag-ui/client
- `examples/showcases/generative-ui-playground` -- @ag-ui/core
- `examples/v2/vue/demo` -- @ag-ui/client (it declared mcp-apps-middleware but no
  client, which was the last remaining edge)

Result: zero references to the canary in the lockfile, and exactly ONE
@ag-ui/core installed -- the renamed preview. Verified by deleting the stale
store directories and reinstalling from the committed lockfile alone: they are
not recreated, so nothing can reach the old copy.

Things that did NOT work, recorded so they are not retried: plain install,
`--force`, `pnpm dedupe`, `>`-scoped overrides (`@ag-ui/a2a>@ag-ui/core`),
version-specific overrides, and deleting the lockfile to regenerate from scratch
-- which reproduced it byte-identically, since the resolution was correct given
the package.json files rather than stale.

These four declarations are TEMPORARY, like the overrides they support, and come
out with them when @Ag-ui publishes the rename.

Verified: @copilotkit/core, react-core and sdk-js typecheck; react-core 1424
tests and vue 1071 tests pass.
mme added a commit to ag-ui-protocol/ag-ui that referenced this pull request Aug 10, 2026
A demo page that renders each subagent's output as its own collapsible,
reasoning-style group: name and description from useSubagent, tool-call cards
inside the owning group, a checkmark when the subagent finishes, and an interrupt
handled inside a subagent.

Grouping is driven by `subagentRunId` on the messages via renderCustomMessages,
which is the consumer-side proof that attribution survives the whole path --
LangGraph's derived namespaces, the protocol events, the client's apply step, and
CopilotKit's rendering. Scoped to the Python-backed integrations, since the agent
is a LangGraph graph.

`useSubagent({ subagentRunId })` is plain shorthand: CopilotKit adopted the same
field name (CopilotKit/CopilotKit#5873), so no mapping is needed at the boundary.
If it ever needs an explicit mapping again, the two names have diverged.
@mme

mme commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #6757, which is this branch minus the registry and hook.

The AG-UI dojo demo (ag-ui-protocol/ag-ui#2351) was useSubagent's only consumer, and it turned out to need almost nothing from it: the hook supplied a label, a tooltip, and a status dot, while all the real subagent UI work (grouping messages by subagentRunId, anchoring groups, hiding attributed messages from the main flow) already lived in the demo. The demo now tracks the lifecycle itself in ~60 lines via the AgentSubscriber callbacks the AG-UI client exposes (onSubagentStartedEvent / onSubagentFinishedEvent / onSubagentErrorEvent), with identical semantics — verified by the dojo's deepagents e2e passing against the hook-free build.

What survives: the @ag-ui #2350 preview bump (types, subscriber dispatch, subagentRunId attribution) moved to #6757, which the dojo now pins. What's parked: SubagentRegistry + useSubagent (331 lines, untested, no consumer left) stay on this branch (mme/subagents) for salvage if demand for a first-class hook materializes — the dojo demo is the reference implementation to build it against.

@mme mme closed this Aug 28, 2026
@mme

mme commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Correction to the close note: the surviving dependency work is #6756 (bump to the released @Ag-ui 0.0.59), not #6757 — #6757 was closed as redundant once it became clear 0.0.59 already ships the subagent surface. The AG-UI dojo pins #6756's previews.

tylerslaton added a commit that referenced this pull request Aug 31, 2026
Bumps the published packages from `@ag-ui/*` **0.0.57 → 0.0.59** — 27
declarations across 18 packages in `packages/**`.

0.0.59 is the first AG-UI release carrying the subagent protocol surface
(`SUBAGENT_STARTED` / `SUBAGENT_FINISHED` / `SUBAGENT_ERROR`,
`subagentRunId`) together with the null-omission cleanup, so it is the
dependency the subagent work needs. Landing the bump on its own keeps
that review separate from the feature work in #5873, which currently
pins `pkg.pr.new` previews of the (now released) ag-ui PR.

### Scope

`packages/**` only — the shipped libraries, which were uniformly on
0.0.57. Examples and showcases are deliberately untouched: they sit on a
spread of pins from 0.0.40 to 0.0.58 and bumping them would bury this
diff. `@ag-ui/langgraph` (0.0.42) and the mcp middlewares are separate
packages and also left alone.

### One behavioural change worth reviewing

`channels-core` ships `sanitizeAgentEventStream` because `@ag-ui/client`
used to **reject** a `TOOL_CALL_START` carrying `parentMessageId: null`
— the shape `@ag-ui/langgraph` emits for the tool call that triggers an
interrupt. As of 0.0.59 the client **accepts** that null and treats it
as absent (it is one of a small set of receive tolerances kept for
producers that still emit it).

That invalidates the two tests asserting the run dies *without* the
sanitizer:

- `aborts that same run when the sanitizer is not applied` → now
`survives that same run without the sanitizer, since 0.0.59 tolerates
the null`. It asserts the tool call actually arrives, not merely that
nothing throws, so it cannot pass vacuously.
- `lets the run abort when sanitizing is disabled` → `no longer aborts
the turn when sanitizing is disabled`.

**The sanitizer itself is untouched** and its coercion tests are
unchanged — it still rewrites the byte on the wire. It is simply no
longer the thing keeping such a run alive. Whether to keep it as
belt-and-braces or retire it is a follow-up decision, not part of this
bump.

### Verification

- All `packages/**` build against 0.0.59.
- `check-types` clean for `core`, `shared`, `react-core`, `runtime`.
- Tests pass: core 786, shared 304, runtime 2084, react-core 1514,
channels-core 267.
- The full `test,publint,attw` pre-commit gate passes across the 26
affected projects.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved handling of tool calls with missing parent message
identifiers, preventing unnecessary turn failures—even when event
sanitization is disabled.
* Ensured Angular validation uses the matching AG UI client version,
improving compatibility during package verification.

* **Chores**
* Updated AG UI client, core, and encoder packages to version 0.0.59
across supported integrations and runtimes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants