How do I terminate a langchain style loops in Gemini (original) (raw)

December 17, 2025, 11:03am 1

I tried to use the naive:

  "tool_config": {
    "function_calling_config": {
      "mode": "NONE"
    }
  }
{
  "generationConfig": {},
  "safetySettings": [
    {
      "category": "HARM_CATEGORY_HARASSMENT",
      "threshold": "BLOCK_NONE"
    },
    {
      "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
      "threshold": "BLOCK_NONE"
    },
    {
      "category": "HARM_CATEGORY_HATE_SPEECH",
      "threshold": "BLOCK_NONE"
    },
    {
      "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
      "threshold": "BLOCK_NONE"
    }
  ],
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "echo the text sam and and then echo the text bob, then echo the text jane, finally return the value of 3+3"
        }
      ]
    },
    {
      "role": "model",
      "parts": [
        {
          "functionCall": {
            "name": "echo",
            "args": {
              "text": "sam"
            }
          },
          "thoughtSignature": "CvICAXLI2nygZH0+LD5IrjaWf3oKe3wVIZk63RFP3dsMqU1WDS1lP0+lDke98JAboOb4rrnsUXZwT9YHbOmN0yqVOgNQTic7kmxiwooxBCKKK60eHAQyktOkRoh085cFyHuEBbSuZ1hdJav6TJL8DiBRvwpHYbxF4UF+iEIuf8d/MbIv3c7VB91o+zHfVnHmfi6N6dIC3QFT7d/5gp81ZYy8Z7Iika4/oFnKI0TCy2PR/VMd5hx4W+aEUGTF5SpxmQdLpa2oipt/FnwYdIKQMj0QQBdhHN+M7+buXSzBkvUtsg34Vu0XnlRGPs6th9Ldn4RxBHYoK6KTgnOGGccF6DHgHQtftInA47xTZT3zdiUExJXaKxckqj7reNoO6A+ooHikE/27Y35bzHDA6sxsAp7gnDy/NBt4noodrJasWHvgwV0lOf9HTprbRGooErZabycnz7rYhR+sKgMFNInx3tsfGrj8SkZJ3Eaok5RYXRPpOlAtIQ=="
        },
        {
          "functionCall": {
            "name": "echo",
            "args": {
              "text": "bob"
            }
          }
        }
      ]
    },
    {
      "role": "function",
      "parts": [
        {
          "functionResponse": {
            "name": "echo",
            "response": {
              "content": "sam"
            }
          }
        }
      ]
    },
    {
      "role": "function",
      "parts": [
        {
          "functionResponse": {
            "name": "echo",
            "response": {
              "content": "bob"
            }
          }
        }
      ]
    }
  ],
  "systemInstruction": {
    "role": "system",
    "parts": [
      {
        "text": "You are a helpful bot that helps eval tool call support for llms, be sure to use parallel tool calls and follow user instruction carefully."
      }
    ]
  },
  "tools": [
    {
      "function_declarations": [
        {
          "name": "echo",
          "description": "will echo the text",
          "parameters": {
            "type": "object",
            "properties": {
              "text": {
                "type": "string",
                "description": "the text to echo"
              }
            },
            "required": [
              "text"
            ]
          }
        }
      ]
    }
  ],
  "tool_config": {
    "function_calling_config": {
      "mode": "NONE"
    }
  }
}

However Gemini returns:

"finishReason\": \"UNEXPECTED_TOOL_CALL\"

I read through Gemini CLI and it appear the team force a tool call to terminate chains (and avoid mode NONE), they have a tool called “complete_task” to force chain terminations.

This is a bit clunky cause both Anthropic and OpenAI don’t tend to need this.

Is this a user error or API bug?