Skip to content
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

The current implementation for function calling with Anthropic models doesn't set tool_calls in AIMessage #53

Closed
thiagotps opened this issue May 21, 2024 · 3 comments
Labels

Comments

@thiagotps
Copy link
Contributor

The current implementation for function calling with Anthropic models only seems to include the available tools in the system prompt. It does not add </function_calls> to the list stop_sequences and does not make use of the stop_reason and stop_sequence values returned by the Bedrock API. Consequently, it does not add the tool_calls value in the AIMessage, as expected by LangGraph .

@3coins 3coins added the bedrock label May 23, 2024
@bigbernnn
Copy link
Contributor

Hi - This latest PR should allow you to make use of stop_reason and tool_calls in the AIMessage's response metadata.

@ssg-kstewart
Copy link

Appreciate the work you've done here. With regard to "tool_calls" being populated, I am indeed now seeing expected formatting. However, I have an implementation mimicking the documentation for LangGraph collaborative multi-agent system and seeing odd behavior when using ChatBedrock over ChatOpenAI. In my case, in addition to the entry point node not calling the correct tool, tools are not actually being called at all and I'm having difficulty discerning the root cause. On top of this, I'm getting a "list index out of range" here:

File "/usr/local/lib/python3.11/site-packages/langchain_aws/llms/bedrock.py", line 235, in prepare_output
   text = content[0].get("text")
            ~~~~~~~^^^
IndexError: list index out of range

I have verified that simply swapping to the ChatOpenAI model resolves the issue and tool calling works as expected.

If this requires a standalone issue, please let me know and I will get that sorted.

@ssg-kstewart
Copy link

ssg-kstewart commented Jun 12, 2024

There's a few separate issues, including my own, that was affected by this in different capacities so commenting here as well for visibility. @thiagotps I have created a PR against the fork @bigbernnn created which sets the tool_calls as you have suggested:

bigbernnn#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants