langchain-ai / langsmith-sdk

LangSmith Client SDK Implementations
https://docs.smith.langchain.com/
MIT License
414 stars 79 forks source link

Issue: Error when using two consecutive tools on playground ChatAnthropic claude-3-5-sonnet-20240620 #899

Open GuilhermeKO opened 3 months ago

GuilhermeKO commented 3 months ago

Issue you'd like to raise.

The following error occurs when creating consecutive AI messages with tool calls followed by Tool Messages:

400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.3.content.0.tooluse.name: String should match pattern '^[a-zA-Z0-9-]{1,64}$'"}}

Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.3.content.0.tooluse.name: String should match pattern '^[a-zA-Z0-9-]{1,64}$'"}} at APIError.generate (file:///node_modules/@anthropic-ai/sdk/error.mjs:36:20) at Anthropic.makeStatusError (file:///node_modules/@anthropic-ai/sdk/core.mjs:256:25) at Anthropic.makeRequest (file:///node_modules/@anthropic-ai/sdk/core.mjs:299:30) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async RetryOperation._fn (/node_modules/p-retry/index.js:50:12

Steps to Reproduce:

Provider: ChatAnthropic Model: claude-3-5-sonnet-20240620

  1. Create a AI message with tool call:

tool name: getOrderData tool id : toolu_018kq2eUEPncj2jBeEodys4Q

{
  "days": 30,
  "unfinisehd_orders": "false"
}
  1. Then the Tool message with the response:

tool name: getOrderData tool id: toolu_018kq2eUEPncj2jBeEodys4Q

[
  {
    "orderCode": "123456789",
    "orderDate": "11/07/2024",
    "status": "Canceled",
    "deliveryDate": "12/07/2024",
    "origin": "Test1",
    "orderPrice": 20.01
  }
]

Note: Works fine until this point.

  1. Now create another AI message with tool call: tool name: authenticate_user tool id : toolu_01D1GYt1s5UhtKd2dNQydjY5

    {
    "user_info": "1234567890",
    "password": "password"
    }
  2. And another Tool message with response: tool name: authenticate_user tool id : toolu_01D1GYt1s5UhtKd2dNQydjY5

    "Authenticated"

Running this generates the error above mentioned. I have tried changing the tools names as the error suggests and tried changing the order of tools but nothing changed. Both tools work when there is no consecutive tool.

Screenshot with initial AI and Tool Message: image

Screenshot with The consecutive Ai and Tool Messages: image

Screenshot with Error: image

Suggestion:

No response

hinthornw commented 3 months ago

Thanks for raising! Could you share a link to an example trace where this occurs?

GuilhermeKO commented 3 months ago

Sure thing! Here is the link: https://smith.langchain.com/public/3537d35c-9ff2-445f-92bf-94586c0874b3/r

hinthornw commented 3 months ago

@GuilhermeKO if you look at the tool names, you'll see there's an invalid space in your tool name there:

"tool_calls": [
                        {
                            "name": "authenticate_user ",
                            "args": {
                                "cpf_or_cnpj": "12345678900",
                                "password": "Senha12345"
                            },
                            "id": "toolu_01D1GYt1s5UhtKd2dNQydjY5"
                        }
                    ],

Notice the "authenticate_user "

I'm not entirely sure why the model is adding the space, since the schema provided seems to be correct. Will check on our side if anything is fishy

{"name":"authenticate_user","description":"This tool authenticates the current user, so tools that use the solar API will be able to fetch the user data. You must use this tool if the user is actually not authenticated or if some other tool failed with auth issues.","input_schema":{"type":"object","properties":{"cpf_or_cnpj":{"type":"string","description":"User cpf or cnpj value."},"password":{"type":"string","description":"User password"}},"required":["cpf_or_cnpj","password"]}}