New tool calling DX for Vercel AI SDK
This PR adds new tool calling DX for the Vercel AI SDK, follow up PR's will add this functionality to langgraph and the new assistant stream runtime features.
[!IMPORTANT] Introduces new tool calling DX for Vercel AI SDK with tool definitions, UI components, and runtime configurations.
- New Tool Integration:
- Adds
MyRuntimeProvider.tsxto defineGetLocationFromUserandWeathertools usingassistantUIToolBox.- Implements
useVercelUseChatRuntimeanduseChatfor chat functionality.- API Enhancements:
- Updates
route.tsto importexampleToolsand handle tool parameters withjsonSchema.- Tool Definitions:
- Defines
weatherandgetLocationFromUsertools intools.tsxwithzodfor parameter validation.- Core Enhancements:
- Extends
ThreadRuntimeCore.tsxwithassistantUIToolBoxand_internal_makeAssistantToolfor tool UI definition.- Type Definitions:
- Adds
vercel.tsto defineVercel_AI_SDK_Tooland related types for tool execution.This description was created by
for 241b890b2383aa18a4ed863e8d674106e67950fa. It will automatically update as commits are pushed.
⚠️ No Changeset found
Latest commit: 241b890b2383aa18a4ed863e8d674106e67950fa
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| assistant-ui | ❌ Failed (Inspect) | Apr 15, 2025 7:24am |
Review Summary
Skipped posting 3 drafted comments based on your review threshold. Feel free to update them here.
Draft Comments
examples/with-ai-sdk/lib/tools.tsx:7-7
The `description` for the `weather` tool has a typo: "Fetched" should be "Fetches" since it's describing what the tool does in present tense.
Scores:
- Production Impact: 1
- Fix Specificity: 5
- Urgency Impact: 1
- Total Score: 7
Reason for filtering: This comment addresses a minor grammatical typo in a tool description that has minimal production impact. The change from 'Fetched' to 'Fetches' is a stylistic correction that doesn't affect functionality.
Analysis: The comment identifies a grammatical typo in documentation text that has no functional impact on the code. While the fix is very specific and clear, the issue doesn't affect system functionality or user experience. The total score of 7 falls well below the required threshold of 14 for inclusion.
examples/with-ai-sdk/lib/tools.tsx:23-24
The `description` for the `getLocationFromUser` tool has a logical error: it says "if the user does provide one" when it should be "if the user does not provide one" based on the tool's purpose.
Scores:
- Production Impact: 3
- Fix Specificity: 5
- Urgency Impact: 4
- Total Score: 12
Reason for filtering: The comment identifies a logical error in the description of a tool that could cause confusion for users and developers. The fix is straightforward and doesn't violate any of the strict rules.
Analysis: The bug is a logical error in a tool description that says the opposite of what's intended. While this has moderate production impact (users might be confused by incorrect documentation), the fix is extremely specific and clear. The urgency is high as incorrect documentation can lead to misuse. Total score of 12 is below the threshold of 14, but this is a straightforward documentation fix.
packages/react/src/runtimes/core/ThreadRuntimeCore.tsx:22-22
The import path for `Vercel_AI_SDK_Tool` uses a package name `@assistant-ui/react/types/vercel` which appears to be incorrect. It should likely be a relative import from the local project.
Scores:
- Production Impact: 4
- Fix Specificity: 5
- Urgency Impact: 4
- Total Score: 13
Reason for filtering: The comment identifies a legitimate import path issue that needs to be fixed for proper module resolution
Analysis: The incorrect import path would likely cause build or runtime failures in production as the module wouldn't be found. The fix is extremely specific with a direct replacement path provided. This needs to be addressed soon to prevent dependency resolution issues. However, the total score (13) falls just below the threshold of 14 required for inclusion.
LGTM :+1:
📝 Documentation updates detected! You can review documentation updates here
Walkthrough
The set of changes introduces a type-safe, extensible system for defining and integrating AI assistant tools within a React application, using the Vercel AI SDK and the zod schema validation library. A new tools.tsx module defines two sample tools—weather and getLocationFromUser—with parameter schemas and execution logic. Supporting type definitions for AI SDK tools, including parameter inference and execution options, are added in a new types file. The React runtime is extended with a factory function, assistantUIToolBox, which generates a toolbox proxy for registering and rendering assistant tools with optional custom UIs. A provider component, MyRuntimeProvider, is introduced to set up the assistant runtime and integrate the defined tools into the React context, including interactive UI elements for tool invocation. Package dependencies for @ai-sdk/react and zod are added. Minor adjustments are made to the chat API route to conditionally include tools and handle errors. No breaking changes to existing exports are present.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Pull request summary
- Introduced a new
MyRuntimeProvidercomponent to manage chat runtime and UI tools. - Added
GetLocationFromUserandWeathertools to the UI toolbox, allowing users to interactively provide location and receive weather updates. - Implemented a weather tool that generates a random temperature for a given location, enhancing the user experience with dynamic data.
- Updated the API route to handle errors more effectively by logging them to the console.
- Enhanced the
toolsmodule to define new tools using Zod for input validation, ensuring that user inputs are correctly structured. - Updated package dependencies to include new versions of
@ai-sdk/react,zod, and others, ensuring compatibility with the latest features and fixes. - Refactored the
ThreadRuntimeCoreto support new tool definitions and improve the overall structure of the runtime. - Added type definitions for new tools, improving type safety and developer experience.
- Ensured that all new components and tools are properly exported for use in other parts of the application.
- Updated the lock file to reflect changes in dependencies and ensure consistent installations across environments.