Add AI Gateway tool calling support#363
Open
IzumiSy wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The previous AI Gateway transport migration made AppShell rely on the OpenAI SDK for OpenAI-compatible streaming, but
useAIChat()was still limited to plain text request/response flows.The next step is to let AppShell consumers register AI Gateway tools directly, while keeping the public API centered on Tailor Platform's AI Gateway instead of leaking provider SDK concepts into application code.
This PR is stacked on top of
izumis/ai-gateway-openai-sdkso the tool-calling diff stays focused on the hook, tool definitions, and Gateway-facing message contract.Design Decision
Keep the public API AI Gateway-first
useAIChat()now accepts a unifiedtoolsobject that can contain both local executable tools and provider tools. Local tools are defined withdefineAIChatTool(...)plusaiToolSchema.*, while provider tools start withaiProviderTool.openai.webSearch(...).This keeps AppShell's contract centered on AI Gateway concepts instead of exposing OpenAI SDK tool types directly.
Keep public messages text-first
The public
messagesarray remains focused on user/assistant text messages, with optional assistantsourcesfor provider-backed results such as web search. Tool-call and tool-result messages are kept in the internal transcript only, so AppShell can run local tool loops without forcing consumers to render low-level tool protocol details.Normalize tool execution responsibilities
Local tools are converted to normalized AI Gateway
type: "function"definitions, validated with Standard Schema, executed inside AppShell, and then fed back into the internal transcript. Provider tools are passed through as normalized AI Gatewaytype: "provider"definitions and are not executed locally.This keeps AppShell responsible only for local tool orchestration while leaving provider-specific behavior on the AI Gateway side.
Summary
defineAIChatTool(...),aiToolSchema.*, andaiProviderTool.openai.webSearch(...)useAIChat()to handle local tool loops while keeping public messages user/assistant text-first