Skip to content

Support for client-defined tools in useAgentChat #727

@alexanderjacobsen

Description

@alexanderjacobsen

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:

  1. Expose prepareSendMessagesRequest in UseAgentChatOptions so clients can attach tool definitions to each request
  2. Add a clientTools option to useAgentChat that automatically sends tool schemas to the server, similar to how body works in useChat
  3. Document a pattern for registering tools via agent.send() on connection, which the server's onMessage can handle

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions