Execution of clientTools

Currently, when defining clientTools in mastra/client-js, execute is completely ignored.
That is, even if llm requests tool-call, execute is never called in client-js.

const clinet = new MastraClient({ baseUrl: 'http://localhost:4111' })
const weatherAgent = client.getAgent('weatherAgent');

const response = await weatherAgent.stream({
  messages, 
  clientTools: {
    getLocation: {
      id: 'getLocation',
      description: 'Get the user location. Always ask for confirmation before using this tool.',
      inputSchema: z.object({}),
      execute: async () => { // never called.
        console.log('called getLocation');
        return 'New York';
      },
    },
  }
}


You should call execute in the client-js environment and feed the tool-result back to llm.

In ai-sdk, addToolResult is used on the front end. On the backend, appendMessageAnnotation can be used to feed back the status of any tool call.
https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#add-tool-result
API reference for the useChat hook.
Was this page helpful?