Fix Role 'function' Not Supported: firebase_ai Tool Calls
The role function is not supported firebase_ai error is a 4.0.0-era bug: firebase_ai 4.0.0 sends tool results with role `function`, which gemini-3.8-flash rejects. Your tool runs fine — the chat dies afterwards. The workaround is sending tool results back with role `user` (verified Content API),…
Last updated: October 21, 2026 Your tool ran fine — then the chat crashed with Role 'function' is not supported . This is a firebase_ai 4.0.0-era bug: the 4.0.0 SDK sends tool results back with role function , and newer Gemini models like gemini-3.8-flash reject that role outright. The fix is one line: stop sending results via Content.functionResponses and send them with role user instead. The workaround below works on 4.0.0 and on firebase_ai 5.0.0 alike — and I'll tell you honestly what I could and couldn't verify about the upstream fix. 🎬 Watch: firebase_ai chat patterns in Flutter [[YT|yqy-nwsFG9M|1476|unverified|codestorywithMIK|Make Your AI Assistant Use Tools: Tool Calling Explained — meet the fourth role|Partial match: a Python/Ollama tool-calling explainer, not firebase_ai — but the 24:36 flow-diagram chapter shows exactly where the 'function'/'tool' roles live in the loop this fix repairs. Video verified via browser.open 2026-10-21; duration unverifiable from text fetch.]] What the "Role 'function' is not supported" error looks like The failure has a maddening shape. Your function executes — logs prove it, side effects happened — and then the *follow-up* message to the model throws: Role 'function' is not supported The typical code that triggers it on firebase_ai 4.0.0: final reply = await chat.sendMessage(Content.text('What is the weather in Kanpur?')); // The tool runs fine... final results = <FunctionResponse>[]; for (final call in reply.functionCalls) { final output = await runTool(call.name, call.args); results.add(FunctionResponse(call.name, {'result': output})); } // ...and the chat dies HERE: final next = await chat.sendMessage(Content.functionResponses(results)); //…