vercel / ai

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

Allow the AI to continue the conversation after calling a tool #3204

Closed mrasoahaingo closed 8 hours ago

mrasoahaingo commented 1 week ago

Feature Description

How do you manage the AI to continue the conversation when user doesn't need to respond after the tool response?

For example:

I want to make a tool which saves the user choice

streamUI({
system: 'Ask the user to choose between A and B, save the choice. Then C and D, saved the choice'
...
tools: {
  save_user_choice: {
    ...
    generate: async function* ({ choice }) {
      yield "saving..."
      async saveChoice(choice)
      return "Your choice has been saved"
    }
  }
}

The chat :

assistant : choose between A and B
user : A
assistant : Your choice has been saved

Then I want the assisant to continue the conversation

assistant : choose between A and B
user : A
assistant : Your choice has been saved

assistant: now choose between C and D
user : C
assistant : Your choice has been saved
assistant : Thank you!

Use Case

No response

Additional context

No response

jeremyphilemon commented 17 hours ago

Hey @mrasoahaingo, thanks for opening an issue!

Based on your requirements, it sounds like this behavior can be achieved by switching over to useChat and streamText + using maxSteps along with some prompt engineering. streamUI currently does not support multi-step tool calls.

I also imagine the system prompt to be:

You are a friendly assistant. You need to save two choices by asking the user two questions. The first choice is between A and B, while the second choice is between C and D.

So the flow ends up being like:

assistant: choose between A and B
user: A
assistant: great thank you! no choose between C and D
user: C
assistant: awesome, I've saved your responses

[!NOTE] You will have to write the system prompt in such a way that you assume the flow will have alternating user and assistant messages.

mrasoahaingo commented 8 hours ago

Thanks, actually I want to use streamUI so I will deal with it :)

lgrammel commented 8 hours ago

Please note that we are moving away from streamUI and putting it on pause for the near future. We recommend using ai sdk core + ui.

mrasoahaingo commented 2 hours ago

Oh 🥲 ... It will be deprected? just asking if I should rewrite my code now 😄

lgrammel commented 1 hour ago

@mrasoahaingo There are several long-standing limitations with AI SDK RSC that have been causing pain for our users, and there are no good solutions in the near term: https://sdk.vercel.ai/docs/getting-started/navigating-the-library#when-to-use-ai-sdk-rsc

To avoid people running into these issues, we recommend using AI SDK UI. We may resume work on AI SDK RSC once there are paths to resolving the underlying limitations.