feat(ai-harness): routing.handoffTool can return undefined for the built-in tool #2286 (GitHub #2285)
main fromrefs/pull/2285/head·merged by AlemTuzlak View on GitHub🎯 Changes#
routing.handoffTool is called for every speaker, the main model (from === null) included. An app that wants a custom tool for only some root agents still has to return a tool for the others. defaultHandoffTool is not exported, so the app has to copy the built-in tool, and the copy can drift from it.
HandoffController.tool() already falls back: this.options.handoffTool?.(ctx) ?? defaultHandoffTool(ctx). This PR lets the types allow it:
handoffToolreturnsAnyTool | undefinedindefine.tsandhandoff.ts.undefinedgives that speaker the built-inhandofftool.- The option's doc comment and
docs/harness/handoffs.mdsay so.
The alternative is to export defaultHandoffTool, so a factory can call it. Happy to switch if you prefer that.
✅ 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).
Test plan#
packages/ai-harness/tests/handoff-tool.test.ts, "gives a speaker the default handoff tool when the factory returns undefined": the factory returnsundefinedforfrom === nulland atransfertool for a root agent. The main model getshandoff, and its call records a handoff. The root agent getstransfer. Without the type change,tscrejects the factory.- The change is type-only (the runtime already falls back), so there is no new E2E test.
- Full
ai-harnesssuite passes (2587 tests).tsc,oxlint, andoxfmtare clean on the changed files.
Summary by CodeRabbit#
- New Features
- Speakers can now use the built-in handoff tool when their configured handoff tool is unspecified.
- Documentation
- Clarified how to select the built-in handoff tool and when the harness calls the handoff tool configuration.
- 1
tanstack-source added labelsfeature
No actionable comments were generated in the recent review.
Walkthrough
-
routing.handoffToolcan now returnundefined. In that case, the speaker receives the built-inhandofftool. The change updates the routing contract, documentation, test coverage, and patch changeset.Changes: Handoff tool fallback
Layer / File(s) Summary Allow and verify the built-in fallback
packages/ai-harness/src/define.ts,packages/ai-harness/src/handoff.ts,packages/ai-harness/tests/handoff-tool.test.ts,docs/harness/handoffs.md,.changeset/handoff-tool-undefined.mdThe factory return type now allows undefined. Documentation describes the built-in fallback. A test checks that one speaker receives the built-in tool while another receives a custom tool. A patch changeset records the behavior.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Feature
Possibly related PRs
- TanStack/ai#2145: Introduces the
routing.handoffToolfactory contract that this change extends.
Suggested reviewers:
alemtuzlak,tombeckenham - TanStack/ai#2145: Introduces the
Merge Risk:
Minimal · up to890a5-
This is a type-level change that lets a handoff tool factory return undefined to get the built-in handoff tool. Existing runtime behavior is unchanged, and the new behavior is covered by a test and documented. Merge risk is minimal.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: routing.handoffTool may now return undefined, so the built-in handoff tool is used. It also names the affected package (ai-harness) and the feat type. The title matche… Description check The description follows the template sections: Changes, Checklist, and Release Impact. It explains the motivation (custom tools for only some root agents, and defaultHandoffTool is not exported), list… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the main change: routing.handoffTool may now return undefined, so the built-in handoff tool is used. It also names the affected package (ai-harness) and the feat type. The title matches the changeset, type signatures, handoff.ts logic, docs, and tests.
Full details: Description check
-
Explanation
The description follows the template sections: Changes, Checklist, and Release Impact. It explains the motivation (custom tools for only some root agents, and defaultHandoffTool is not exported), lists the type and doc changes, names the alternative considered, and gives a test plan. The checklist is marked. The Changes section does not name the changeset file, but the release impact box and the summary show that a changeset was added. The description is complete enough for review.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- 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.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/ai
- Branch: main
- File: .coderabbit.yaml
- Commit: f302e8b
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
866a7b44-7ce7-45ef-a06e-c3669c0823a1
Commits-
Reviewing files that changed from the base of the PR and between f302e8b77e5632de82f16eddb79ef4294ab9809e and 890a5fe10819abc393df784f66721580de245907.
Files selected for processing: 5-
.changeset/handoff-tool-undefined.mddocs/harness/handoffs.mdpackages/ai-harness/src/define.tspackages/ai-harness/src/handoff.tspackages/ai-harness/tests/handoff-tool.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
-
-
AlemTuzlak approved these changes
🤖 Nx Cloud AI Fix Eligible#
To disable these notifications, a workspace admin can disable them [in workspace settings.](https://cloud.nx.app/orgs/6412ca9d1c251d000efa21ba/workspaces/6928ccd60a2e27ab22f38ad0/settings/self-healing-ci?utm_source=pull-request&utm_medium=comment)An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.
View your CI Pipeline Execution ↗ for commit 890a5fe10819abc393df784f66721580de245907
Command Status Duration Result nx run-many --targets=test:coverage --projects=...❌ Failed 6m 14s View ↗ nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 7m 10s View ↗ nx run-many --targets=build --exclude=examples/...✅ Succeeded 1m 12s View ↗ 💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗
☁️ Nx Cloud last updated this comment at
2026-11-30 18:20:31UTC@tanstack/ai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@2285@tanstack/ai-acp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@2285@tanstack/ai-angular
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@2285@tanstack/ai-anthropic
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@2285@tanstack/ai-bedrock
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@2285@tanstack/ai-byteplus
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@2285@tanstack/ai-cartesia
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cartesia@2285@tanstack/ai-claude-code
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@2285@tanstack/ai-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@2285@tanstack/ai-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@2285@tanstack/ai-code-mode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@2285@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@2285@tanstack/ai-codex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@2285@tanstack/ai-cohere
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@2285@tanstack/ai-compaction
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@2285@tanstack/ai-computer-local
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-local@2285@tanstack/ai-computer-playwright
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-playwright@2285@tanstack/ai-computer-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-sandbox@2285@tanstack/ai-computer-use
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-use@2285@tanstack/ai-devtools-core
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@2285@tanstack/ai-durable-stream
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@2285@tanstack/ai-effect
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-effect@2285@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@2285@tanstack/ai-event-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@2285@tanstack/ai-fal
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@2285@tanstack/ai-gemini
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@2285@tanstack/ai-grok
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@2285@tanstack/ai-grok-build
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@2285@tanstack/ai-groq
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@2285@tanstack/ai-harness
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@2285@tanstack/ai-harness-cli
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness-cli@2285@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@2285@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@2285@tanstack/ai-isolate-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-e2b@2285@tanstack/ai-isolate-node
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@2285@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@2285@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@2285@tanstack/ai-llmgateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@2285@tanstack/ai-lovable
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@2285@tanstack/ai-mcp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@2285@tanstack/ai-mcp-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp-sandbox@2285@tanstack/ai-memory
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@2285@tanstack/ai-meshy
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-meshy@2285@tanstack/ai-mistral
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@2285@tanstack/ai-muse
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-muse@2285@tanstack/ai-neon
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-neon@2285@tanstack/ai-octane
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@2285@tanstack/ai-ollama
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@2285@tanstack/ai-ollaya
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollaya@2285@tanstack/ai-openai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@2285@tanstack/ai-opencode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@2285@tanstack/ai-openrouter
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@2285@tanstack/ai-optimize
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-optimize@2285@tanstack/ai-perplexity
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@2285@tanstack/ai-persistence
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@2285@tanstack/ai-preact
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@2285@tanstack/ai-react
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@2285@tanstack/ai-reactor
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@2285@tanstack/ai-remix
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@2285@tanstack/ai-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@2285@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@2285@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@2285@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@2285@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@2285@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@2285@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@2285@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@2285@tanstack/ai-sandbox-railway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-railway@2285@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@2285@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@2285@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@2285@tanstack/ai-skills
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@2285@tanstack/ai-solid
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@2285@tanstack/ai-svelte
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@2285@tanstack/ai-tripo
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-tripo@2285@tanstack/ai-typesafe
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@2285@tanstack/ai-uthana
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-uthana@2285@tanstack/ai-utils
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@2285@tanstack/ai-vercel-compat
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-compat@2285@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@2285@tanstack/ai-vertex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@2285@tanstack/ai-vue
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@2285@tanstack/ai-worldlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@2285@tanstack/openai-base
npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@2285@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@2285@tanstack/react-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@2285@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@2285@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@2285commit:
890a5feAlemTuzlak merged this56d1d11
AlemTuzlak closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 890a5fe10819abc393df784f66721580de245907
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
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