Repository navigation
Conversation
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]>
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.
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.
…review bump Removes SubagentRegistry, useSubagent and their core wiring from the mme/subagents branch, leaving only the dependency work: the @ag-ui/* overrides pinned to pkg.pr.new previews of ag-ui-protocol/ag-ui#2350, whose bundled @ag-ui/client carries the subagent event types (SUBAGENT_STARTED/FINISHED/ ERROR), the AgentSubscriber dispatch and subagentRunId message attribution. The AG-UI dojo demo now consumes those subscriber callbacks directly and no longer imports useSubagent, so this minimal bump is all the dojo needs from CopilotKit. The registry/hook (untested, no other consumer) can return as its own PR if user demand for a first-class hook materializes.
This was referenced Aug 28, 2026
Contributor
Author
|
Not needed after all: #6756 already bumps the CopilotKit packages to the released |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft, preview-build vehicle. This is CopilotKit PR #5873 minus the SubagentRegistry and useSubagent hook (331 lines removed) — only the dependency work remains:
@ag-ui/*overrides pinned to the pkg.pr.new previews of feat(subagents): add subagent support to the protocol and SDKs ag-ui-protocol/ag-ui#2350, whose bundled@ag-ui/clientcarries the subagent event types (SUBAGENT_STARTED/FINISHED/ERROR), theAgentSubscriberdispatch (onSubagentStartedEventetc.) andsubagentRunIdmessage attribution.pnpm install --frozen-lockfilesucceeds withblock-exotic-subdeps=trueleft on; see the reviewer notes on feat(core): subagent registry + useSubagent hook #5873 for the .npmrc details, which carry over unchanged).Why the hook was dropped
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 actual subagent UI work (grouping, anchoring, hiding attributed messages) lived in the demo readingmessage.subagentRunIddirectly. The demo now tracks the lifecycle itself via theAgentSubscribercallbacks (~60 lines), so the dojo only needs a CopilotKit build that bundles the new@ag-ui/client— this PR.The registry/hook (untested, no other consumer) can return as its own PR if demand for a first-class hook materializes; the removed code lives on
mme/subagents/ #5873 for salvage.Lifecycle
Like the pins it replaces, this is temporary: swap the overrides for released
@ag-uiversions once ag-ui#2350 merges and ships. The dojo pins this PR's preview builds by commit sha (tracked in PNI-275).Verified:
@copilotkit/coreand@copilotkit/react-corecheck-types + test green via nx after the removal, with no remaining references to the registry, hook, oronSubagentsChanged.