[firebase_ai]: TemplateChatSession.sendMessage drops auto-executed function call/response turns from history
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
调研方向
Start with lib/src/server_template/template_chat.dart, especially TemplateChatSession.sendMessage, and compare how requestHistory is added in sendMessageStream and the other chat methods. The report includes a reproduction using chat.history; verify that it contains the user message, function call and response turns, and final response. An open linked pull request (#18758) is already addressing this issue.
由索引模型根据 Issue 内容生成。
描述
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Other
Which platforms are affected?
Web
Description
Affected plugin: firebase_ai (not in the dropdown). The code is pure Dart, so other platforms are likely affected too; we have only built for Web.
When TemplateChatSession.sendMessage auto-executes functions (TemplateAutoFunctionDeclaration), only the original message and the final model response are added to history:
// lib/src/server_template/template_chat.dart, sendMessage
if (!shouldAutoExecute) {
if (response.candidates case [final candidate, ...]) {
_history.add(message);
// ...
_history.add(normalizedContent);
}
return response;
}
The intermediate turns collected in requestHistory are discarded: the model's functionCall content and the function responses. On the next sendMessage, the model no longer sees what its tools returned. For example, a createCharacter call that returned a new id is gone from history, so a follow-up call that needs that id has nothing to refer to.
The other three code paths keep the whole exchange with _history.addAll(requestHistory):
TemplateChatSession.sendMessageStreamChatSession.sendMessageChatSession.sendMessageStream
So this looks like an oversight in this one path rather than intended behavior.
Expected: after auto-executed function turns, history contains the user message, each model functionCall turn, each function response turn and the final response, as sendMessageStream does. Likely fix:
_history.addAll(requestHistory);
_history.add(normalizedContent);
Actual: history contains only the user message and the final response.
This is still the code on main as of today. We found it while building function calling on a server prompt template, and worked around it by using sendMessageStream.
Reproducing the issue
- Create a server prompt template that declares one function, e.g.
getValue, and includes{{history}}. final chat = FirebaseAI.googleAI().templateGenerativeModel().startChat('<template-id>', inputs: {}, tools: [TemplateTool.functionDeclarations([TemplateAutoFunctionDeclaration(name: 'getValue', parameters: {}, callable: (_) => {'value': 42})])]);await chat.sendMessage(Content.text('Call getValue and tell me the result.'));The model calls the function and the SDK auto-executes it.- Inspect
chat.history: it has 2 entries (user message, final reply). ThefunctionCallandfunctionResponseturns are missing. Doing the same withsendMessageStreamgives 4 entries.
Firebase Core version
4.14.0
Flutter Version
3.44.1
Relevant Log Output
No error is raised; the turns are silently missing from `chat.history`.
Flutter dependencies
Expand Flutter dependencies snippet
firebase_ai: 4.0.0
firebase_core: 4.14.0
Additional context and comments
Related, but already fixed on main in 6eb250f (#18685), not yet released: in 4.0.0, function responses are sent with role function, which the template endpoint rejects with Role 'function' is not supported. Please use a valid role: SYSTEM, SYSTEM_1, USER, ASSISTANT, DEVELOPER, CONTEXT, USER_CONTEXT, MODEL, USER. Mentioned only so it isn't re-reported. A release including that fix would be welcome.
- 主要语言
- Dart
- 星标
- 9.3k
- 派生
- 4.1k
- 平均合并
- 2 天 8 小时
- 30 天内合并 PR
- 46
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/flutterfire 的其他 Issue
-
[firebase_auth]: authStateChanges() never emits null when the user is force-signed-out before the stream is listened to (iOS, macOS, Android)可能已有人在做 @JulianPscheid 于 2 天前认领。 未关闭Needs Attention platform: android platform: ios platform: macos plugin: auth reproduced type: bug
难度 4/5 1-2 天 新手友好度 15/100
firebase/flutterfire#18796 · 1 条评论 ·
维护者通常 1 天内回复
-
blocked: customer-response Needs Attention platform: ios plugin: messaging type: bug
难度 4/5 3-5 天 新手友好度 48/100
firebase/flutterfire#18776 · 4 条评论 ·
维护者通常 1 天内回复
-
[📚] Remote Config Windows Support still N/A on Readme可能已有人在做 @nightcityblade 于 7 天前认领。 未关闭blocked: customer-response good first issue Needs Attention platform: windows plugin: remote_config type: documentation
难度 1/5 1 小时以内 新手友好度 30/100
firebase/flutterfire#18763 · 3 条评论 ·
维护者通常 1 天内回复
-
[cloud_firestore]: a snapshots() listener cancelled while it registers is never removed natively可能已有人在做 @chiliec 于 20 天前认领。 未关闭Needs Attention platform: android platform: ios platform: macos plugin: cloud_firestore reproduced type: bug
难度 3/5 1-2 天 新手友好度 72/100
firebase/flutterfire#18724 · 2 条评论 ·
维护者通常 1 天内回复
-
[firebase_storage] Windows native crash in upload progress callback, sink ownership and thread dispatch可能重新可做 关联的 PR 已关闭且未合并。 未关闭blocked: flutter platform: windows plugin: storage reproduced type: bug
难度 5/5 一周以上 新手友好度 25/100
firebase/flutterfire#18664 · 3 条评论 ·
维护者通常 1 天内回复
查看 firebase/flutterfire 的全部 Issue
相似的 Issue
-
area: rust-core bug priority: low
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug direct-code
难度 2/5 1-3 小时 新手友好度 66/100
aaronified/fluenough#526 · 1 条评论 ·
维护者通常 1 天内回复
-
bug documentation
难度 2/5 1-3 小时 新手友好度 70/100
fdittgen-png/deskilo#2605 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
[Bug]: The daily reminder keeps its old language after the app language changes可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭backlog:low bug localization
难度 2/5 1-3 小时 新手友好度 72/100
simonoppowa/OpenNutriTracker#1366 ·
维护者通常 1 天内回复