Assistants API expects multiple tool_calls, even though only one function provided

I have an assistant with a single function. Yet the Assistants API returns multiple tool_calls and expects results from all of them

I noticed the errors because my backend does a POST to …/submit_tool_outputs with the result for the function call I defined, however that throws an error, because the API expects multiple.

Upon further inspection, it seems the API often expects tool_calls for names including:

search, calculate or open_url

This doesn’t really make sense and is causing problems, I assume those are tools that OpenAI should be handling.

1 Like

Can you post code snippets of your api calls and the prompts behind them? any function definitions you have as well please, also could you include the logs from the posts? As much data as you can to help us to help you.

Here is an example error call:

POST
/threads/{$threadId}/runs/{$runId}/submit_tool_outputs

{
    "tool_outputs": [
      {
        "tool_call_id": "call_0ORM2unDOuMOpNyEdF1Plmk7",
        "output": "example output redacted"
      }
    ]
  }

RESPONSE:



{
  "error": {
    "message": "Expected tool outputs for call_ids ['call_0ORM2unDOuMOpNyEdF1Plmk7', 'call_kdPD6iLYf9Sx1wla6BwTbqYe'], got ['call_0ORM2unDOuMOpNyEdF1Plmk7']",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

As I mentioned, I only have a single function defined, here is a slightly redacted version of it. The parameter names are the same:

{
  "name": "example_name",
  "description": "Example description.",
  "parameters": {
    "type": "object",
    "properties": {
      "reason": {
        "type": "string",
        "description": "Example description."
      },
      "urgency": {
        "type": "string",
        "description": "Example description."
      }
    },
    "required": [
      "reason"
    ]
  }
}

The issue seems to be that the submit_tool_outputs endpoint expects outputs from other “tools”, which I guess are internal to OpenAI e.g. I have seen “calculate” and “search”

Fixed the problem!

while True:
    run_status = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)

    if run_status.status == 'completed':
        break

    elif run_status.status == 'requires_action':
        tools_outputs = []

        for tool_call in run_status.required_action.submit_tool_outputs.tool_calls:
            if tool_call.function.name == "google_search":
                arguments = json.loads(tool_call.function.arguments)

                print(f"Running tool - '{tool_call.function.name}' | With args - {arguments}")
                output = google_search(arguments["query"])
                print(len(output), output)

                tool_output = {"tool_call_id":tool_call.id, "output": json.dumps(output)}
                tools_outputs.append(tool_output)

        if run_status.required_action.type == 'submit_tool_outputs':
            print("Submit output")
            client.beta.threads.runs.submit_tool_outputs(thread_id=thread.id, run_id=run.id, tool_outputs=tools_outputs)

        time.sleep(1)