-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anthropic user content inside tool result #2047
Comments
My current patch with https://github.com/ds300/patch-package if some body faced this problem too and need solution.
|
Thank you, @sintanial! This worked for me. @lgrammel - this was super useful. Might be worth taking a look at :) |
|
In my case, i make 'ai web crawler', and this is my message seuqence:
As you can see, i put role 'user' just after role 'tool'. For my case it was necessary, because every time after every browser action i must to show LLM content of the current page. OpenAI and Claude allow this case and proper handle it. For anthropic when you need to answer on 'tool-call' (which part of assistant message), you must put your 'tool-result' type inside 'user' role message content, and also if this is the 'user' role, it's allowed to adding type 'text' with any text content. The same way related to OpenAI too. |
I see - so you want to provide additional information to the LLM when the user clicks accept. Have you considered the following:
|
That idea aside, this raises an important issue. It might be better to simplify the messages API for the Vercel AI SDK into |
Yep, your version is good. But it has a little problem if the function must return some result (for example, collect something). Yes, you can concatenate all results and HTML page content, but a better approach for me is to separate it. I think this library should support all the flexibility of providers (Anthropic, OpenAI, etc.).
It's a good idea! Makes sense! Also, it's much more intuitive because the tool is called on the assistant side and the tool results must be on the user side. The Anthropic version of organizing this functionality is quite good. |
Can we get this fixed? Blocks very basic Anthropic usage without the patch |
Description
Title:
Error with Consecutive User Role Messages After Tool Role Messages in Anthropic API
Description:
When attempting to place a user role message immediately after a tool role message using the Anthropic API, an error is encountered:
This issue seems to be caused by the Anthropic API's requirement for roles to alternate strictly between "user" and "assistant". The current behavior does not support having a user role message following a tool role message without an intermediate assistant message.
Steps to Reproduce:
Expected Behavior:
The API should accept the message structure, possibly by automatically incorporating the user message content within the tool result content or by providing a mechanism to handle such sequences without causing an error.
Suggested Solution:
Replace this line https://github.com/vercel/ai/blob/main/packages/anthropic/src/convert-to-anthropic-messages-prompt.ts#L74 to this code:
The text was updated successfully, but these errors were encountered: