Gemini 3.5 Flash emits tool calls as text transcripts
Problem
Gemini 3.5 Flash sometimes returns tool calls as plain assistant text instead of structured OpenAI-compatible tool_calls.
Observed in Chermes/Telegram:
[Called function "terminal" with args: {"command":"whoami"}]
and:
[Called function "search_files" with args: {"pattern":"*","target":"files"}]
Other models generally return proper structured tool calls, so this appears specific to Gemini 3.5 Flash behavior through the OpenAI-compatible path.
Expected
Gemini tool calls should reach downstream clients as structured OpenAI-style tool_calls, with empty assistant content and finish_reason: "tool_calls".
Actual
The model sometimes emits a text transcript, which downstream chat surfaces may display to the user instead of dispatching the tool.
Testbed notes
A local testbed patch that parses this shape:
[Called function "NAME" with args: {...}]
and converts it into a structured tool call made direct ClawRouter requests work for both non-streaming and streaming responses.
Example direct streaming response after the patch included:
{
"delta": {
"tool_calls": [
{
"type": "function",
"function": {
"name": "terminal",
"arguments": "{\"command\":\"whoami\"}"
}
}
]
}
}
Targeted tests added on testbed passed:
27 passed
Checks also passed on the patched testbed checkout:
npm run typecheck
npm run lint
npm run build
npm run format:check
Related symptom
After adding runtime normalization, Hermes/Telegram can execute the tool, but may still display raw tool result lines like:
[Tool "function" returned]: {...}
That may be a separate display-layer issue, but the original failure is Gemini returning tool calls as text transcripts instead of structured calls.