Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Proposal]: New tool calling DX #1770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft

Conversation

heyglassy
Copy link
Collaborator

@heyglassy heyglassy commented Apr 1, 2025

This PR is a proposal of a more typesafe way to define tools. I've made minimal adjustments to the existing set of types across the application but just re worked the tool schema definition.

The goal of this is to push the user to define their tools in a central set of places so that they can prevent duplicate tools, and take advantage of the type-safety that centralization provides. We split the tools into client and server tools, but the tools would eventually be registered in one "tool box" across the set of tools.

If this approach looks good I'll also add typesafe client side tool handling, it's a pita to do with existing tools and I'd love to fix it.

Copy link

vercel bot commented Apr 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
assistant-ui ❌ Failed (Inspect) Apr 10, 2025 6:49am

import { openai } from "@ai-sdk/openai";
import { streamText } from "ai";
// import { aiSDKAdapter } from "@assistant-ui/rea=-ct";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the import comment for @assistant-ui/react where an equals sign is incorrectly included in the package name.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// import { aiSDKAdapter } from "@assistant-ui/rea=-ct";
// import { aiSDKAdapter } from "@assistant-ui/react";

// },
// });

export const weatherTool = aiSDKAdapter(webSearchTool);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aiSDKAdapter is applied to webSearchTool but should be applied to the corrected weatherTool implementation.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const weatherTool = aiSDKAdapter(webSearchTool);
export const weatherToolAdapter = aiSDKAdapter(weatherTool);

Copy link

trag-bot bot commented Apr 10, 2025

Pull request summary

  • Added a new maxSteps parameter to the useChat hook in MyRuntimeProvider.tsx to limit the number of steps in chat interactions.
  • Integrated a weatherTool into the chat API in route.ts, allowing the chat to fetch weather data based on user input.
  • Updated the import statements in page.tsx to use components from the @assistant-ui/react library, enhancing modularity.
  • Created a new weatherTool in tools.ts that connects to a PostgreSQL database to fetch weather data, improving data retrieval capabilities.
  • Updated the package.json files to include new dependencies for @ai-sdk/react, @assistant-ui/react-ui, and pg, ensuring all necessary packages are available.
  • Introduced registerTool and getToolUI functions in getTool.tsx and getToolUI.tsx to facilitate the registration and rendering of tools in the UI.
  • Refactored the tool function in tool.ts to support both client and server tools, allowing for more flexible tool definitions.
  • Enhanced type definitions in ContentPartComponentTypes.tsx to ensure type safety for the addResult function, improving code reliability.
  • Updated the lock file to reflect changes in dependencies and ensure consistent installations across environments.

Copy link

trag-bot bot commented Apr 10, 2025

Pull request summary

  • Added a new maxSteps parameter to the useChat hook in MyRuntimeProvider.tsx to limit the number of steps in chat interactions.
  • Integrated a weatherTool into the chat API in route.ts, allowing the chat to fetch weather data.
  • Updated the import statements in page.tsx to use components from @assistant-ui/react-ui and removed unused imports.
  • Created a new weatherTool in tools.ts that fetches weather data from a PostgreSQL database.
  • Updated package.json files to include new dependencies for @ai-sdk/react, @assistant-ui/react-ui, and pg for PostgreSQL support.
  • Introduced registerTool and getToolUI functions in getTool.tsx and getToolUI.tsx to facilitate tool registration and UI rendering.
  • Refactored the tool function in tool.ts to support both client and server tools, enhancing flexibility for future tool integrations.
  • Modified the useAssistantToolUI hook to ensure proper tool UI registration and rendering.
  • Updated type definitions in ContentPartComponentTypes.tsx to enforce stricter typing for the addResult function.
  • Cleaned up commented-out code and organized imports across multiple files for better readability and maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant