dify icon indicating copy to clipboard operation
dify copied to clipboard

When using the "command-r-plus" model in an agent to invoke a tool, a 400 error typically indicates a client request error

Open vary opened this issue 1 year ago • 11 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When using the "command-r-plus" model in an agent to invoke a tool, a 400 error typically indicates a client request error. This suggests that the format or content of the request may not meet the expected standards, or there may be an error with the parameters passed: [cohere] Bad Request Error, status_code: 400, body: {'message': 'invalid request: cannot specify both message and tool_results in multistep mode' image

✔️ Expected Behavior

Expect normal use of tool invocation.

❌ Actual Behavior

400 error

vary avatar Jun 20 '24 09:06 vary

Hi @vary! I'm here to help you with bugs, questions, and becoming a contributor. Let me know how I can assist you while you wait for a human maintainer.

To resolve the 400 error indicating "invalid request: cannot specify both message and tool_results in multistep mode" when using the "command-r-plus" model in an agent to invoke a tool, ensure that you are not specifying both message and tool_results in your request. The request should include either message or tool_results, but not both simultaneously.

Here is an example of how you might structure your request correctly:

model: command-r-plus
parameters:
  temperature: 0.7
  p: 0.75
  k: 50
  presence_penalty: 0.5
  frequency_penalty: 0.5
  max_tokens: 1024
# Ensure you only include either message or tool_results, not both
request:
  message: "Your message here"
  # tool_results: "Your tool results here"  # Comment this out or remove it

Make sure to adjust the parameters and request content according to your specific use case [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jun 20 '24 10:06 dosubot[bot]

I encountered the same issue. Currently, I can only avoid it by setting force_single_step=True.

ice91 avatar Jul 03 '24 07:07 ice91

Encountered the same issue. Only thing I do differently than in documentation is that I stream the request. Cohere multistep tool docs show the following example

message = "Who is the mayor of the capital of Ontario?"
model = "command-r-plus"

# STEP 2: Check what tools the model wants to use and how

res = co.chat(model=model, message=message, force_single_step=False, tools=[web_search_tool])

# as long as the model sends back tool_calls,
# keep invoking tools and sending the results back to the model
while res.tool_calls:
  print(res.text) # This will be an observation and a plan with next steps
  tool_results = []
  for call in res.tool_calls:
    # use the `web_search` tool with the search query the model sent back
    web_search_results = {"call": call, "outputs": web_search(call.parameters["query"])}
    tool_results.append(web_search_results)

  res = co.chat(
    model="command-r-plus",
    chat_history=res.chat_history,
    message="",
    force_single_step=False,
    tools=[web_search_tool],
    tool_results=tool_results
  )

Are you invoking co.chat() or co.chat_stream(); I get this error when streaming the request. I believe multi-step streaming is not fully functional yet.

Omitting message or giving it an empty string with chat_stream will yield a (should have at least 1 token) error. Making it impossible without changing source-code.

surferfelix avatar Jul 10 '24 10:07 surferfelix