Skip to content
Discussion options

You must be logged in to vote

@dbridges Yeah I figured this out, although I'm not sure if it's the accepted answer: with a custom backend, useChat does not automatically execute client-side tools. You have to do it yourself in onFinish:

const chat = useChat({
  // ...
  onFinish: async (message) => {
    // Find tool calls that the server returned but haven't been executed yet
    const pendingToolCalls = message.parts.flatMap((p) =>
      p.type === 'tool-call' && p.state === 'input-complete' && p.output === undefined ? [p] : []
    );

    await Promise.all(
      pendingToolCalls.map(async (part) => {
        const tool = tools.find((t) => t.name === part.name);
        if (!tool?.execute) return;

        try {

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dbridges
Comment options

Answer selected by puehringer
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants