Function call Loops on GPT3.5

Sometimes GPT3.5 chat completion starts to loop on the same function call and sometimes after 2-3 function call it goes out and start print normal text as it should

It happens with strange prompt, for example when I say that I want to reserve a table for 9 PM it works correctly but when I say i want to reserve a table for 9 PM outside, it starts to loop.

Probably GPT4 doesn’t loop, but why this is happening on GPT3.5 isn’t it able to find when a function is completed correctly?

2 Likes

I’ve run into the same issue. Curious to see what other’s experience is.

are you passing the output of the function call back to the input prompt for the next question?

If not, the model will think it has not satisfied the function call and try again, you can even just fill in a placeholder with something like “Function called successfully”

1 Like

Well it’s quite complicated, I’m used langchain and it doesn’t support it natively so I’ve tried my best

I’ll share an example of memory history (it’s in italian)

MESSAGES:  {
  "history": [
    {
      "id": [
        "HumanMessage"
      ],
      "kwargs": {
        "content": "Buonasera, vorrei prenotare un tavolo per stasera alle 21 fuori.",
        "additional_kwargs": {}
      }
    },
    {
      "id": [
        "AIMessage"
      ],
      "kwargs": {
        "content": "",
        "additional_kwargs": {
          "function_call": {
            "name": "selezione_azione",
            "arguments": "{\n  \"selezione\": \"prenotazione\"\n}"
          }
        }
      }
    },
    {
      "id": [
        "FunctionMessage"
      ],
      "kwargs": {
        "content": "{azione:\"prenotazione\"}",
        "name": "selezione_azione",
        "additional_kwargs": {
          "name": "selezione_azione"
        }
      }
    },
    {
      "id": [
        "HumanMessage"
      ],      "kwargs": {
        "content": "",
        "additional_kwargs": {}
      }
    },
    {
      "id": [
        "AIMessage"
      ],
      "kwargs": {
        "content": "",
        "additional_kwargs": {
          "function_call": {
            "name": "prenotazione",
            "arguments": "{\n  \"data\": {\n    \"giorno\": \"oggi\",\n    \"orario\": \"21:00\"\n  },\n  \"extra\": {\n    \"zona\": \"fuori\"\n  }\n}"
          }
        }
      }
    }
  ]
}

After this i remove the last Function Message and the last empty Human Message leaving AIMessage only.

Now the AI should be able to detect that an answer is possible to be given, but it replay the function another time

MESSAGES:  {
  "history": [
    {
      "id": [
        "HumanMessage"
      ],
      "kwargs": {
        "content": "Buonasera, vorrei prenotare un tavolo per stasera alle 21 fuori.",
        "additional_kwargs": {}
      }
    },
    {
      "id": [
        "AIMessage"
      ],
      "kwargs": {
        "content": "",
        "additional_kwargs": {
          "function_call": {
            "name": "selezione_azione",
            "arguments": "{\n  \"selezione\": \"prenotazione\"\n}"
          }
        }
      }
    },
    {
      "id": [
        "AIMessage"
      ],
      "kwargs": {
        "content": "",
        "additional_kwargs": {
          "function_call": {
            "name": "prenotazione",
            "arguments": "{\n  \"data\": {\n    \"giorno\": \"oggi\",\n    \"orario\": \"21:00\"\n  },\n  \"extra\": {\n    \"zona\": \"fuori\"\n  }\n}"
          }
        }
      }
    },    {
      "id": [
        "FunctionMessage"
      ],
      "kwargs": {
        "content": "{tavolo_disponibile:true}",
        "name": "prenotazione",
        "additional_kwargs": {
          "name": "prenotazione"
        }
      }
    },
    {
      "id": [
        "HumanMessage"
      ],
      "kwargs": {
        "content": "",
        "additional_kwargs": {}
      }
    },
    {
      "id": [
        "AIMessage"
      ],
      "kwargs": {
        "content": "",
        "additional_kwargs": {
          "function_call": {
            "name": "prenotazione",
            "arguments": "{\n  \"data\": {\n    \"giorno\": \"oggi\",\n    \"orario\": \"21:00\"\n  },\n  \"extra\": {\n    \"zona\": \"fuori\"\n  }\n}"
          }
        }
      }
    }
  ]
}

And it goes over in the same loop. If instead of asking “Stasera alle 21 fuori” I just ask “Stasera alle 21” it works as it should

1 Like

In my experience, this happens when the result you give to the last chat completion to summarize the result is not satisfactory as an answer or different to the original inquiry so it will respond with another function calling response.

5 Likes

Ok, I’ll try giving more context inside the result and see if giving more information will give better results.
Thanks!

It worked! using a more exhaustive response it seems to not going in loop anymore
Thank you :smiley: