feat(ai, ai-client, ai-persistence): continue a child by sessionId, and a typed part.subagent.input #1731
feat/agent-limits-keys-step fromrefs/pull/1731/head·merged by AlemTuzlak View on GitHubThe model can now send a follow-up to a child that already answered. With withPersistence on the parent chat(), it calls the same agent tool again with sessionId. A host can also start a child in the background with background: true. The card also keeps the brief: part.subagent.input is the checked input of an agent with inputSchema, typed on the client. Existing apps do not change: the agent tool still takes the agent's own fields.
This piece is split out of #1555 and is a prerequisite for the harness work there. It stacks on #1727 (feat/agent-limits-keys-step).
🎯 Changes#
- Agent tool fields. An agent tool takes the fields of its
inputSchema(as before), or apromptfor an agent without one. Apromptbecomes the last user message of the child. sessionIdcontinues a stored child through the newLoadChildcapability (LoadChildCapability,getLoadChild,provideLoadChild). The field is there only when a middleware listsLoadChildCapabilityinprovides(withPersistencedoes). A result then carries the child'ssubagentRunId.background: truecalls the host'ssubagents.binding.startand counts against the tree budget. The field is there only when the host setsbinding.start.- Reserved names. When the run uses
sessionIdorbackground, that name is reserved, andchat()throws if aninputSchemauses it. A wrapper schema checks the agent's fields in the tool loop, before middleware, as for any tool. part.subagent.input.SUBAGENT_STARTEDcarries the checked input inmetadata.tanstack.subagentInput.ChatClientputs it on the card handle. AddinputSchemato the agent declaration you pass touseChat({ subagents })to type it. It survives reload through the card metadata.@tanstack/ai-persistence.withPersistenceprovidesLoadChild. The recorder stores the task of each child's first call, the follow-up prompt of each continue call, and the thread that started it. It loads only the children of the calling thread.
Wrong calls (an unknown sessionId, a child of another agent or thread, a field that fails the schema) are tool errors, and the run goes on. Agent tools also support ToolExecutionContext.detach.
Docs: chat/subagents.md (Continue a child, The tool input, Wrong calls, Show the brief on a card).
Left out on purpose: session index entries for children (the sessions store is not on main) and the routed-host selection changes in reconstruct.ts.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm run test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
- Docs: I updated
docs/for this change, or this change is not user-facing. - Changeset: I added a changeset (
pnpm changeset), or this PR does not change a published package.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Testing#
Commands run. All of these passed. I did not run the full pnpm test:pr.
nx run-many -t test:types,test:lib,test:oxlint -p @tanstack/ai @tanstack/ai-persistence @tanstack/ai-client @tanstack/ai-react @tanstack/ai-e2e ts-react-chatnx run-many -t build,test:build -p @tanstack/ai @tanstack/ai-persistence @tanstack/ai-client @tanstack/ai-reactnx run-many -t test:types --projects='examples/**,testing/**'(27 projects)pnpm test:docs,pnpm test:kiira,pnpm test:knippnpm --filter @tanstack/ai-e2e test:e2e --grep 'subagents|mcp input'(11 passed)
Manual test.
- Run
pnpm --filter @tanstack/ai-e2e test:e2e --grep "subagents". - Check that
an agent tool continues a child by its sessionIdpasses. Oneresearchercard shows bothSquids have three hearts.andSquids also have blue blood. - Check that
the parent model writes the brief the child runs onpasses. The card shows the input{"task":"[subagent-brief-task] List two squid facts."}frompart.subagent.input.
How this PR makes testing easy.
- Unit:
packages/ai/tests/subagent-tool-input.test.ts(schemas, reserved names, validation before middleware, continue, background, tool errors),packages/ai-client/tests/chat-client-subagents.test.ts(handleinput),packages/ai-react/tests/use-chat-subagent-types.test.ts(typedinput), andpackages/ai-persistence/tests/subagent-persistence-cards.test.ts. - E2E: the
sessionandbriefscenarios intesting/e2e/tests/subagents.spec.ts. - Example:
examples/ts-react-chat/src/routes/subagent-brief.tsxreadspart.subagent.input?.task.
Risk / rollback#
Low for existing apps: the tool input keeps its shape, and the new fields appear only with persistence or a background host. With persistence on, an agent whose inputSchema has a sessionId field now makes chat() throw. withPersistence adds a tanstack:subagentChild marker to the head of each stored child transcript.
Known limits: two parallel calls with the same sessionId in one turn run on the same child id. After detach wins, the child's later chunks do not reach the parent stream. A schema with a top-level transform to a non-object loses the reserved fields. Revert the PR to undo.
Public API change#
Before
// Server
chat({ adapter, messages, subagents: { agents: [researcher, writer] } })
// Client: the brief is in the parent tool call, `unknown`
const input = toolCallPart.input
After
// Server
chat({
adapter,
messages,
middleware: [withPersistence(persistence)],
subagents: { agents: [researcher, writer] },
})
// The model calls: writer { "sessionId": "subagent-...", "prompt": "Make it shorter" }
// Client: typed from the declaration's inputSchema
const chat = useChat({ connection, subagents: [researcher] })
part.subagent.input?.task
🤖 Generated with Claude Code
- 1
Important
Review skipped#
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
-
- Configuration used: Repository: TanStack/ai/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
79e4ba3c-642e-43c0-a29c-89723dd3ecd7
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit aa2b97cfbdeeaa868439e37826ce5c4fb3eddf0c
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 10m 43s View ↗ nx run-many --targets=test:coverage --projects=...✅ Succeeded 2s View ↗ nx run-many --targets=build --exclude=examples/...✅ Succeeded 2m 20s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-13 17:38:04UTC@tanstack/ai
npm i https://pkg.pr.new/@tanstack/ai@1731@tanstack/ai-acp
npm i https://pkg.pr.new/@tanstack/ai-acp@1731@tanstack/ai-angular
npm i https://pkg.pr.new/@tanstack/ai-angular@1731@tanstack/ai-anthropic
npm i https://pkg.pr.new/@tanstack/ai-anthropic@1731@tanstack/ai-bedrock
npm i https://pkg.pr.new/@tanstack/ai-bedrock@1731@tanstack/ai-byteplus
npm i https://pkg.pr.new/@tanstack/ai-byteplus@1731@tanstack/ai-claude-code
npm i https://pkg.pr.new/@tanstack/ai-claude-code@1731@tanstack/ai-client
npm i https://pkg.pr.new/@tanstack/ai-client@1731@tanstack/ai-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-cloudflare@1731@tanstack/ai-code-mode
npm i https://pkg.pr.new/@tanstack/ai-code-mode@1731@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/@tanstack/ai-code-mode-snippets@1731@tanstack/ai-codex
npm i https://pkg.pr.new/@tanstack/ai-codex@1731@tanstack/ai-cohere
npm i https://pkg.pr.new/@tanstack/ai-cohere@1731@tanstack/ai-compaction
npm i https://pkg.pr.new/@tanstack/ai-compaction@1731@tanstack/ai-devtools-core
npm i https://pkg.pr.new/@tanstack/ai-devtools-core@1731@tanstack/ai-durable-stream
npm i https://pkg.pr.new/@tanstack/ai-durable-stream@1731@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@1731@tanstack/ai-event-client
npm i https://pkg.pr.new/@tanstack/ai-event-client@1731@tanstack/ai-fal
npm i https://pkg.pr.new/@tanstack/ai-fal@1731@tanstack/ai-gemini
npm i https://pkg.pr.new/@tanstack/ai-gemini@1731@tanstack/ai-grok
npm i https://pkg.pr.new/@tanstack/ai-grok@1731@tanstack/ai-grok-build
npm i https://pkg.pr.new/@tanstack/ai-grok-build@1731@tanstack/ai-groq
npm i https://pkg.pr.new/@tanstack/ai-groq@1731@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@1731@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@1731@tanstack/ai-isolate-e2b
npm i https://pkg.pr.new/@tanstack/ai-isolate-e2b@1731@tanstack/ai-isolate-node
npm i https://pkg.pr.new/@tanstack/ai-isolate-node@1731@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@1731@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@1731@tanstack/ai-llmgateway
npm i https://pkg.pr.new/@tanstack/ai-llmgateway@1731@tanstack/ai-lovable
npm i https://pkg.pr.new/@tanstack/ai-lovable@1731@tanstack/ai-mcp
npm i https://pkg.pr.new/@tanstack/ai-mcp@1731@tanstack/ai-memory
npm i https://pkg.pr.new/@tanstack/ai-memory@1731@tanstack/ai-mistral
npm i https://pkg.pr.new/@tanstack/ai-mistral@1731@tanstack/ai-octane
npm i https://pkg.pr.new/@tanstack/ai-octane@1731@tanstack/ai-ollama
npm i https://pkg.pr.new/@tanstack/ai-ollama@1731@tanstack/ai-ollaya
npm i https://pkg.pr.new/@tanstack/ai-ollaya@1731@tanstack/ai-openai
npm i https://pkg.pr.new/@tanstack/ai-openai@1731@tanstack/ai-opencode
npm i https://pkg.pr.new/@tanstack/ai-opencode@1731@tanstack/ai-openrouter
npm i https://pkg.pr.new/@tanstack/ai-openrouter@1731@tanstack/ai-perplexity
npm i https://pkg.pr.new/@tanstack/ai-perplexity@1731@tanstack/ai-persistence
npm i https://pkg.pr.new/@tanstack/ai-persistence@1731@tanstack/ai-preact
npm i https://pkg.pr.new/@tanstack/ai-preact@1731@tanstack/ai-react
npm i https://pkg.pr.new/@tanstack/ai-react@1731@tanstack/ai-react-ui
npm i https://pkg.pr.new/@tanstack/ai-react-ui@1731@tanstack/ai-reactor
npm i https://pkg.pr.new/@tanstack/ai-reactor@1731@tanstack/ai-remix
npm i https://pkg.pr.new/@tanstack/ai-remix@1731@tanstack/ai-sandbox
npm i https://pkg.pr.new/@tanstack/ai-sandbox@1731@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/@tanstack/ai-sandbox-blaxel@1731@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/@tanstack/ai-sandbox-boxd@1731@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@1731@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@1731@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@1731@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/@tanstack/ai-sandbox-e2b@1731@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@1731@tanstack/ai-sandbox-railway
npm i https://pkg.pr.new/@tanstack/ai-sandbox-railway@1731@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@1731@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/@tanstack/ai-sandbox-upstash-box@1731@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@1731@tanstack/ai-skills
npm i https://pkg.pr.new/@tanstack/ai-skills@1731@tanstack/ai-solid
npm i https://pkg.pr.new/@tanstack/ai-solid@1731@tanstack/ai-solid-ui
npm i https://pkg.pr.new/@tanstack/ai-solid-ui@1731@tanstack/ai-svelte
npm i https://pkg.pr.new/@tanstack/ai-svelte@1731@tanstack/ai-typesafe
npm i https://pkg.pr.new/@tanstack/ai-typesafe@1731@tanstack/ai-utils
npm i https://pkg.pr.new/@tanstack/ai-utils@1731@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/@tanstack/ai-vercel-gateway@1731@tanstack/ai-vertex
npm i https://pkg.pr.new/@tanstack/ai-vertex@1731@tanstack/ai-vue
npm i https://pkg.pr.new/@tanstack/ai-vue@1731@tanstack/ai-vue-ui
npm i https://pkg.pr.new/@tanstack/ai-vue-ui@1731@tanstack/ai-worldlabs
npm i https://pkg.pr.new/@tanstack/ai-worldlabs@1731@tanstack/openai-base
npm i https://pkg.pr.new/@tanstack/openai-base@1731@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@1731@tanstack/react-ai-devtools
npm i https://pkg.pr.new/@tanstack/react-ai-devtools@1731@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@1731@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/@tanstack/svelte-ai-devtools@1731commit:
aa2b97cCoverage#
✅ Coverage held across 66 compared package(s).
Each package is measured twice in this job — on this PR and on its merge-base with
main— and compared. A metric fails only when it is at or above 60% on the merge-base and under 60% on this PR. Other drops are listed but do not fail. Packages your PR doesn't affect are not measured and not listed.package statements branches functions lines ai 91.37% (-0.01) 84.88% (+0.09) 92.04% (-0.02) 92.95% (-0.02) ok ai-acp 78.41% (0.00) 66.79% (0.00) 70.27% (0.00) 80.13% (0.00) ok ai-angular 73.37% (0.00) 60.66% (0.00) 62.14% (0.00) 75.13% (0.00) ok ai-anthropic 91.67% (0.00) 85.80% (0.00) 95.53% (0.00) 92.07% (0.00) ok ai-bedrock 89.52% (0.00) 82.07% (0.00) 92.62% (0.00) 90.82% (0.00) ok ai-byteplus 97.06% (0.00) 91.62% (0.00) 98.26% (0.00) 98.49% (0.00) ok ai-claude-code 88.93% (0.00) 76.88% (0.00) 86.88% (0.00) 90.40% (0.00) ok ai-client 86.47% (+0.01) 79.23% (+0.01) 84.62% (+0.01) 88.41% (+0.01) ok ai-cloudflare 84.64% (0.00) 75.00% (0.00) 83.92% (0.00) 86.00% (0.00) ok ai-code-mode 91.71% (0.00) 83.12% (0.00) 86.27% (0.00) 92.63% (0.00) ok ai-code-mode-snippets 87.13% (0.00) 75.67% (0.00) 91.11% (0.00) 88.39% (0.00) ok ai-codex 94.55% (0.00) 85.10% (0.00) 89.28% (0.00) 95.56% (0.00) ok ai-cohere 88.97% (0.00) 88.37% (0.00) 85.71% (0.00) 91.80% (0.00) ok ai-compaction 95.70% (0.00) 82.35% (0.00) 100.00% (0.00) 97.88% (0.00) ok ai-devtools 83.13% (0.00) 72.77% (0.00) 87.07% (0.00) 85.22% (0.00) ok ai-durable-stream 86.70% (0.00) 82.25% (0.00) 92.30% (0.00) 88.72% (0.00) ok ai-elevenlabs 74.68% (0.00) 69.59% (0.00) 59.13% (0.00) 75.46% (0.00) ok ai-fal 91.10% (0.00) 82.63% (0.00) 92.40% (0.00) 91.60% (0.00) ok ai-gemini 68.12% (0.00) 67.54% (0.00) 63.97% (0.00) 68.82% (0.00) ok ai-grok 48.80% (0.00) 53.33% (0.00) 56.16% (0.00) 49.63% (0.00) ok ai-grok-build 79.19% (0.00) 63.56% (0.00) 77.39% (0.00) 81.02% (0.00) ok ai-groq 51.31% (0.00) 47.17% (0.00) 65.11% (0.00) 53.42% (0.00) ok ai-isolate-cloudflare 94.11% (0.00) 70.66% (0.00) 100.00% (0.00) 93.96% (0.00) ok ai-isolate-daytona 90.25% (0.00) 81.34% (+0.75) 100.00% (0.00) 90.15% (0.00) ok ai-isolate-e2b 92.11% (0.00) 81.48% (0.00) 97.36% (0.00) 95.05% (0.00) ok ai-isolate-node 84.00% (0.00) 43.39% (0.00) 100.00% (0.00) 83.78% (0.00) ok ai-isolate-quickjs 89.07% (0.00) 76.41% (0.00) 90.90% (0.00) 90.30% (0.00) ok ai-isolate-quickjs-bun 7.76% (0.00) 8.08% (0.00) 5.00% (0.00) 8.33% (0.00) ok ai-llmgateway 97.67% (0.00) 100.00% (0.00) 88.88% (0.00) 97.67% (0.00) ok ai-lovable 73.21% (0.00) 55.63% (0.00) 85.07% (0.00) 73.96% (0.00) ok ai-mcp 96.52% (0.00) 91.68% (0.00) 96.88% (0.00) 98.48% (0.00) ok ai-memory 73.87% (0.00) 52.70% (0.00) 79.74% (0.00) 76.04% (0.00) ok ai-mistral 84.99% (0.00) 79.97% (0.00) 92.59% (0.00) 85.64% (0.00) ok ai-octane 90.58% (0.00) 71.48% (0.00) 87.29% (0.00) 91.24% (0.00) ok ai-ollama 91.76% (0.00) 76.47% (0.00) 90.62% (0.00) 91.71% (0.00) ok ai-ollaya 86.84% (0.00) 89.28% (0.00) 85.71% (0.00) 91.66% (0.00) ok ai-openai 65.34% (0.00) 65.68% (0.00) 66.66% (0.00) 65.63% (0.00) ok ai-opencode 68.77% (0.00) 60.82% (0.00) 64.04% (0.00) 70.78% (0.00) ok ai-openrouter 86.01% (0.00) 69.73% (0.00) 90.00% (0.00) 87.82% (0.00) ok ai-perplexity 91.34% (0.00) 90.43% (0.00) 100.00% (0.00) 93.87% (0.00) ok ai-persistence 91.41% (+0.23) 81.19% (+1.05) 97.44% (+0.06) 94.82% (+0.20) ok ai-preact 87.80% (0.00) 75.87% (0.00) 88.73% (0.00) 89.66% (0.00) ok ai-react 73.13% (0.00) 52.16% (0.00) 75.54% (0.00) 73.08% (0.00) ok ai-reactor 94.91% (0.00) 83.33% (0.00) 93.33% (0.00) 96.55% (0.00) ok ai-remix 39.39% (0.00) 23.35% (0.00) 35.51% (0.00) 41.58% (0.00) ok ai-sandbox 77.45% (0.00) 82.80% (0.00) 74.47% (0.00) 77.97% (0.00) ok ai-sandbox-blaxel 87.64% (0.00) 77.18% (0.00) 82.26% (0.00) 89.71% (0.00) ok ai-sandbox-boxd 95.86% (0.00) 87.12% (0.00) 95.31% (0.00) 98.17% (0.00) ok ai-sandbox-cloudflare 67.91% (0.00) 57.47% (0.00) 71.79% (0.00) 69.62% (0.00) ok ai-sandbox-daytona 82.70% (0.00) 81.89% (0.00) 67.14% (0.00) 85.18% (0.00) ok ai-sandbox-docker 80.15% (0.00) 71.49% (0.00) 77.38% (0.00) 82.13% (0.00) ok ai-sandbox-e2b 94.42% (0.00) 88.97% (0.00) 93.24% (0.00) 98.63% (0.00) ok ai-sandbox-local-process 68.00% (0.00) 53.59% (0.00) 75.86% (0.00) 68.88% (0.00) ok ai-sandbox-railway 94.75% (0.00) 92.68% (0.00) 90.90% (0.00) 97.59% (0.00) ok ai-sandbox-sprites 73.23% (0.00) 59.70% (0.00) 73.83% (0.00) 76.17% (0.00) ok ai-sandbox-upstash-box 94.82% (0.00) 91.52% (0.00) 91.04% (0.00) 97.76% (0.00) ok ai-sandbox-vercel 44.67% (0.00) 38.18% (0.00) 35.18% (0.00) 45.76% (0.00) ok ai-skills 80.38% (0.00) 64.05% (0.00) 84.86% (0.00) 82.44% (0.00) ok ai-solid 53.73% (0.00) 40.45% (0.00) 51.94% (0.00) 57.78% (0.00) ok ai-svelte 70.44% (0.00) 54.50% (0.00) 69.86% (0.00) 75.99% (0.00) ok ai-typesafe 78.04% (0.00) 84.61% (0.00) 66.66% (0.00) 82.05% (0.00) ok ai-vercel-gateway 75.97% (0.00) 55.63% (0.00) 85.41% (0.00) 79.38% (0.00) ok ai-vertex 96.77% (0.00) 97.22% (0.00) 100.00% (0.00) 96.77% (0.00) ok ai-vue 60.70% (0.00) 36.17% (0.00) 62.00% (0.00) 62.95% (0.00) ok ai-worldlabs 79.62% (0.00) 71.50% (0.00) 91.42% (0.00) 82.66% (0.00) ok openai-base 88.71% (0.00) 76.01% (0.00) 98.35% (0.00) 90.86% (0.00) ok github-actions[bot](GitHub profile, opens in a new tab) assignedjherr
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
jherr approved these changes
github-actions[bot](GitHub profile, opens in a new tab) added labelsready-to-merge
AlemTuzlak changed the title
AlemTuzlak changed the title
AlemTuzlak merged this122b22d
AlemTuzlak closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 49bf3b11030cd8169f35a9e25b490e3bdf2e86ee
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 51 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR