Assistant API V2: Function Calling Gets Stuck and Executes Twice

Hello,

I am building an Assistant API V2 with function calling and have encountered an issue where, given a user message, the assistant calls a function but experiences the following problems:

  • The function is called twice.
  • The thread gets stuck in the function and never ends.

I’ve provided the prompt, the function, and some test cases below.

Prompt:

You are an assistant tasked with obtaining contact details from user input. Note that the user may provide first and last names; in such cases, remove the last names before calling the function.

Follow these rules:
- Use `get_contacts_list` when the user first inputs a request to retrieve a list of contacts and select the one that best matches the user's message. If no results are found, create the object with the "create" flag set to true. If you are given a list, select the name that is closest to the one provided.
- Call the function only once at a time.

Function:

{
  "name": "get_contacts_list",
  "description": "Get the list of user's contacts. Use this function to retrieve a list of contacts and choose the one that best matches the user's input.",
  "strict": false,
  "parameters": {
    "type": "object",
    "properties": {
      "firstname": {
        "type": "string",
        "description": "The name of the contact"
      }
    },
    "required": [
      "firstname"
    ]
  }
}

User Message:

I've just talked with John Doe, and he is fine.

Tool Output:

[
  {
    "id": "123",
    "firstname": "John",
    "lastname": null,
    "email": null
  },
  {
    "id": "1234",
    "firstname": "John",
    "lastname": "Doe",
    "email": "j_doe@icloud.com"
  },
  {
    "id": "1",
    "firstname": "John",
    "lastname": "D.",
    "email": null
  },
  {
    "id": "2",
    "firstname": "John",
    "lastname": "Doe",
    "email": "johndoe@gmail.com"
  },
  {
    "id": "3",
    "firstname": "John",
    "lastname": "Smith",
    "email": "johnsmith@example.com"
  }
]

Regards,
Diego

i tested your function without any instructions and it is called only once.

Sorry, I’ve just forgot to mention that the output of the API is json_schema

{
  "name": "contactSchema",
  "strict": false,
  "schema": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "firstname": {
        "type": "string"
      },
      "lastname": {
        "type": "string"
      },
      "email": {
        "type": "string"
      },
      "phone_number": {
        "type": "string"
      },
      "create": {
        "type": "boolean"
      }
    },
    "required": [
      "firstname"
    ],
    "additionalProperties": false,
    "$schema": "http://json-schema.org/draft-07/schema#"
  }
}```

i added your response schema. i still cannot recreate the issue. however, i am not using any instructions. it is said that parallel function calling isn’t compatible with structured outputs and you can set some parameter, parallel_tool_calls: false to disable it.

Hello,

I set the parallel_tool_calls: false on my nodejs api but it’s still getting stuck asking again and again for the same contact list…

One thing that I didn’t tell you is that the response_format of the assistan is the following:

zodResponseFormat(ContactSchema, "contact_schema")
const ContactSchema = z.object({
  id: z.string().optional(),
  firstname: z.string(),
  lastname: z.string(),
  email: z.string().optional(),
  phone_number: z.string(),
  create: z.boolean(),
});