How can I invoke a tool and continue chatting without calling addToolResult
using useChat
?
#4432
-
I have a few client tools I want to invoke, which renders a component with a form, action or button the user needs to interact with. The tools work fine if the user completes the component and I run the However, if the user decides not to complete the task, e.g. if the AI ran the wrong tool, or they just changed their mind on what task they want to do, if they try to chat with the AI without completing the tool it throws an error:
How can I allow tools to be invoked without requiring a result? I have tried adding a result either in the tool I'm also okay if there's a solution that makes the AI not respond at all. As long as the chat can be continued without the tool having submitted a result yet. It's a bad user experience that they must complete the tool before being able to interact with the chat again. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Seems like the tools job is to actually display the form, not submit the form. I'd swap the tools purpose to be something like Then, you can immediately return a success ToolInvocation. If you need the chat thread to be aware of the data the form is submitting, you can add the form data to the thread with append when the user submits the displayed form. |
Beta Was this translation helpful? Give feedback.
It's a strict limitation in the LLMs. OpenAI, for example, will error directly if a result is not returned before generating the next message. Tool calls are sort of pre-requisites functions for the ai to respond.
You could get around this by filtering/editing the message history prior to sending to LLMs. But that's not a great way around the problem, imo.