-
Notifications
You must be signed in to change notification settings - Fork 321
Description
I'm building a service that lets users embed an AI chat widget into their websites, where each website can define its own client-side tools (e.g., showAlert, changeBackgroundColor,
navigateToPage).
Currently, tools must be defined server-side in onChatMessage. However, my use case requires each client to register different tools dynamically - the server doesn't know what tools a particular
website wants to expose until runtime.
Current limitation
useAgentChat creates its own transport internally and doesn't expose a way to send additional data (like tool definitions) with each chat request:
const customTransport = useMemo(() => ({
sendMessages: async (options) => {
return new DefaultChatTransport({
api: agentUrlString,
fetch: aiFetch
}).sendMessages(options);
},
// No way to use prepareSendMessagesRequest here
}), [agentUrlString, aiFetch]);
The Vercel AI SDK's useChat supports this via prepareSendMessagesRequest on the transport, but useAgentChat doesn't expose it.
Proposed solution
One of these approaches would enable client-defined tools:
- Expose prepareSendMessagesRequest in UseAgentChatOptions so clients can attach tool definitions to each request
- Add a clientTools option to useAgentChat that automatically sends tool schemas to the server, similar to how body works in useChat
- Document a pattern for registering tools via agent.send() on connection, which the server's onMessage can handle