Repository navigation
feat(ai, ai-persistence): one subagent tool with sessionId continue - #1731
AlemTuzlak wants to merge 2 commits into
Conversation
subagents.tool 'single' gives the model one subagent tool that names the agent, takes input or a prompt, continues a stored child by sessionId through the new LoadChild capability, and starts a background child through binding.start. withPersistence provides LoadChild and stores the task and owner thread of each child.
🦋 Changeset detectedLatest commit: b3d2a4b 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 |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
View your CI Pipeline Execution ↗ for commit b3d2a4b
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-acp
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-bedrock
@tanstack/ai-byteplus
@tanstack/ai-claude-code
@tanstack/ai-client
@tanstack/ai-cloudflare
@tanstack/ai-code-mode
@tanstack/ai-code-mode-snippets
@tanstack/ai-codex
@tanstack/ai-cohere
@tanstack/ai-compaction
@tanstack/ai-devtools-core
@tanstack/ai-durable-stream
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-grok-build
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-daytona
@tanstack/ai-isolate-e2b
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-isolate-quickjs-bun
@tanstack/ai-llmgateway
@tanstack/ai-lovable
@tanstack/ai-mcp
@tanstack/ai-memory
@tanstack/ai-mistral
@tanstack/ai-octane
@tanstack/ai-ollama
@tanstack/ai-ollaya
@tanstack/ai-openai
@tanstack/ai-opencode
@tanstack/ai-openrouter
@tanstack/ai-perplexity
@tanstack/ai-persistence
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-reactor
@tanstack/ai-remix
@tanstack/ai-sandbox
@tanstack/ai-sandbox-blaxel
@tanstack/ai-sandbox-boxd
@tanstack/ai-sandbox-cloudflare
@tanstack/ai-sandbox-daytona
@tanstack/ai-sandbox-docker
@tanstack/ai-sandbox-e2b
@tanstack/ai-sandbox-local-process
@tanstack/ai-sandbox-railway
@tanstack/ai-sandbox-sprites
@tanstack/ai-sandbox-upstash-box
@tanstack/ai-sandbox-vercel
@tanstack/ai-skills
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-typesafe
@tanstack/ai-utils
@tanstack/ai-vercel-gateway
@tanstack/ai-vertex
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/ai-worldlabs
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
@tanstack/svelte-ai-devtools
commit: |
Coverage✅ Coverage held across 66 compared package(s). Each package is measured twice in this job — on this PR and on its merge-base with
|
With
subagents: { tool: 'single' }, the parent model gets onesubagenttool and names the agent in each call. WithwithPersistenceon the parentchat(), a call can continue an earlier child by itssessionId, so the model can send a follow-up to a child that already answered. A host can also start a child in the background.This piece is split out of #1555. It is a prerequisite for the harness work there. It stacks on #1727 (
feat/agent-limits-keys-step).🎯 Changes
subagents.tool: 'single'(SubagentToolInput, a union onagent). An agent withinputSchematakesinput(checked against the schema), and an agent without one takesprompt, which becomes the last user message.chat()throws if an agent or tool is already namedsubagent.sessionIdcontinues a stored child through the newLoadChildcapability (LoadChildCapability,getLoadChild,provideLoadChild). The child gets its stored transcript, then the new prompt. A resumed continued child gets each stored message once.background: truecalls the host'ssubagents.binding.startand counts against the tree budget. Without a host, the call is a tool error.detach: the single tool supportsToolExecutionContext.detach.subagentRunIdonly for the single tool, when a persistence store can continue the child. Wrong calls (bad field types, a prompt for an input agent, an unknownsessionId, a child of another agent or thread) are tool errors.@tanstack/ai-persistence:withPersistenceprovidesLoadChild. The recorder stores the task of each child's first call, the thread that started it, the follow-up prompt of each continue call, and how many messages came before the current call. It loads only the children of the calling thread. Open tool calls are dropped when a run ends.Docs:
chat/subagents.md(Give the model one subagent tool, Continue a child, Wrong calls).toolChoicefrom the same #1555 changeset is already on main (#1692) and is not in this PR. Left out on purpose: session index entries for children (thesessionsstore is not on main) and the routed-host selection changes inreconstruct.tsandkeepSubagentRunIds(a separate fix, not needed for this feature).✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.docs/for this change, or this change is not user-facing.pnpm changeset), or this PR does not change a published package.🚀 Release Impact
Testing
Commands run. After merging the
SubagentForwardfix from the lower PRs, these passed locally:nx run-many -t test:types,test:lib,test:oxlint -p @tanstack/ai @tanstack/ai-persistence,pnpm --filter @tanstack/ai-react-native-smoke typecheck,nx run @tanstack/ai-e2e:test:types, andpnpm --filter @tanstack/ai-e2e test:e2e --grep 'subagents|mcp input'(11 passed, including theresult,limits, andsessionscenarios).Manual test.
pnpm --filter @tanstack/ai-e2e test:e2e --grep "subagents".the single subagent tool continues a child by its sessionIdpasses. The secondsubagentcall continues the first child: one card shows bothSquids have three hearts.andSquids also have blue blood., and the parent answersBoth notes are ready.How this PR makes testing easy.
packages/ai/tests/subagent-single-tool.test.ts, and new recorder andwithPersistencecases inpackages/ai-persistence/tests/subagent-persistence-cards.test.ts.sessionscenario intesting/e2e/tests/subagents.spec.ts, withfixtures/subagents/single-tool.json.Risk / rollback
Low for existing apps:
tool: 'single'is opt-in, and per-agent tool results do not change.withPersistencenow adds atanstack:subagentChildmarker to the head of each stored child transcript and keeps open tool-call names and arguments until the run ends.Known limits: two parallel calls with the same
sessionIdin one turn run on the same child id. Afterdetachwins, the child's later chunks do not reach the parent stream. Revert the PR to undo.Public API change
Before
After
🤖 Generated with Claude Code