Skip to content

ai: Support tool calls in RAG methods #1302

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

scotttrinh
Copy link
Collaborator

@scotttrinh scotttrinh commented Jul 11, 2025

Our previous methods only supported returning text that was generated by an assistant, but if you provide tools, we were never returning a rich enough object that would allow you to call the tools with the provided arguments.

This is a breaking change because instead of returning string | null, we now return a whole AssistantMessage from the main methods. See the updated README for additional details.

@scotttrinh scotttrinh requested review from anbuzin and Copilot July 11, 2025 14:05
Copilot

This comment was marked as outdated.

@scotttrinh scotttrinh requested a review from Copilot July 14, 2025 18:50
@scotttrinh scotttrinh changed the title ai: Add some guidance on tool calls ai: Support tool calls in RAG methods Jul 14, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive support for tool calling functionality to the AI package, expanding its capabilities to handle OpenAI-style function calls in both streaming and non-streaming modes. The changes include extensive test infrastructure improvements, new API types, and detailed documentation.

Key changes:

  • Implements OpenAI-style tool calling support with proper streaming and non-streaming handling
  • Adds comprehensive test coverage for tool calling scenarios
  • Refactors test infrastructure with better debugging and shared setup utilities

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/ai/test/test-setup.ts New shared test environment setup utility
packages/ai/test/mockHttpServer.ts Enhanced mock server with tool calling support and debug logging
packages/ai/test/globalSetup.ts Added performance timing for test setup
packages/ai/test/core.test.ts Refactored tests and added tool calling test cases
packages/ai/src/utils.ts Improved error message formatting
packages/ai/src/types.ts Added tool definition types and streaming message types
packages/ai/src/core.ts Updated to return AssistantMessage objects with tool call support
packages/ai/package.json Added debug dependency
packages/ai/jest.config.js Added test concurrency limits and timeout configuration
packages/ai/README.md Added comprehensive tool calling documentation with examples
Comments suppressed due to low confidence (1)

packages/ai/src/types.ts:110

  • The property name 'args' is ambiguous and inconsistent with the function calling convention. Consider renaming to 'arguments' to match the OpenAI API standard used elsewhere in the codebase.
      args?: Record<string, unknown> | null;

Even for Anthropic, we translate their tool calls into our own
consistent format, but we were accidentally passing through a possible
Anthropic style and documentating _that_.
@scotttrinh scotttrinh marked this pull request as ready for review July 14, 2025 19:43
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.

2 participants