How to Prevent Tool Result Repetition in Assistant Response with Pleasantries and Follow-up Questions?

I am building a chatbot that has generative UI capabilities, and I am facing an issue regarding tool results and assistant responses. Here’s the situation:

  • When a question is asked, my bot calls a tool (like fetching data, etc.), and I get the tool’s result (in JSON format) to render a rich UI.
  • I also display the assistant’s response below the UI, which includes pleasantries, follow-up questions, and some additional context. The problem arises because the assistant’s response also includes the full details of the tool result, which results in redundancy, as I am already using that tool result to render the UI.

What I want to achieve:

  • I would like to keep the pleasantries and follow-up questions in the assistant’s response, but I do not want the tool’s detailed results to be repeated.
  • Essentially, I want to ensure the assistant’s response focuses on human-like interactions and context without redundantly showing the tool result, which I am already handling separately.

Is there a way to structure the assistant’s response so that it excludes the tool result when it’s already being used in the UI, but still provides the necessary pleasantries and follow-up questions?

Any insights or best practices for this would be greatly appreciated!

Thanks!

2 Likes

Having the assistant create a text response at the same time a function is called is hard to achieve in the same API call. Instead, create a system which detects if a function was used, and make an additional API call with a system prompt explaining a function was previously used.

For example, if one of our tools is to get the current weather:

  1. We make an API call passing the weather tool
  2. Check if the response contains a function call, if it doesn’t, then return the assistant text message to the user
  3. If it does contain a function call, execute the function in your code, and get the weather
  4. Make another API call passing the weather as context along with the messages from the conversation, excluding any tool messages