vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
9.9k stars 1.46k forks source link

experimental_activeTools needs a hallucination filter when tools are disabled mid-conversation #3322

Open oalexdoda opened 1 week ago

oalexdoda commented 1 week ago

Description

There's a bug where although experimental_activeTools properly filters through the active/inactive tools, it causes the LLM to think it can do something that it can't anymore.

  1. Set up an AI agent with a bunch of tools (i.e. calculator and weather)
  2. Ask them what the weather is like in a city (i.e. London)
  3. They answer and call the tool
  4. Disable the weather tool, but keep calculator
  5. Ask them what the weather is like in another city (i.e. Vegas)

Instead of the agent saying "I can't do that anymore", they act as if they do & invent responses.

This is likely something that needs to be done better on the LLM side, but perhaps there could be a built-in AI SDK filter that informs the LLM the tool is no longer available if it isn't in activeTools, but it exists in the message history.

Code example

image

Additional context

image

lgrammel commented 1 week ago

I suspect this is the standard behavior of the LLM when the disabled tools are not available. If you mention the tools in e.g. the system prompt, it's up to you to change that as well.

I want to prevent injecting any textual information into the chat as much as we can, since this is up to the user.

oalexdoda commented 1 week ago

Understood, thank you @lgrammel!

What would be really useful (as a suggestion) is if there was, perhaps a separate prop, called experimental_guardrails where we could build/have some pre-defined filters to avoid stuff that LLMs fail to address.

Similar to how Azure allows you to add content filters, or to how platforms like Portkey have guardrails.