Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[firebase_ai]: TemplateChatSession.sendMessage drops auto-executed function call/response turns from history

已关闭
#18,757 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@chiliec 已经在做这个了。

开始于 2026年10月6日。

  • #18758 来自 @chiliec —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
dart, firebase, flutter
领域
api, backend

调研方向

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 内容生成。

描述

Needs Attention platform: all platform: web plugin: ai reproduced type: bug
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.sendMessageStream
  • ChatSession.sendMessage
  • ChatSession.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
  1. Create a server prompt template that declares one function, e.g. getValue, and includes {{history}}.
  2. final chat = FirebaseAI.googleAI().templateGenerativeModel().startChat('<template-id>', inputs: {}, tools: [TemplateTool.functionDeclarations([TemplateAutoFunctionDeclaration(name: 'getValue', parameters: {}, callable: (_) => {'value': 42})])]);
  3. await chat.sendMessage(Content.text('Call getValue and tell me the result.')); The model calls the function and the SDK auto-executes it.
  4. Inspect chat.history: it has 2 entries (user message, final reply). The functionCall and functionResponse turns are missing. Doing the same with sendMessageStream gives 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/flutterfire 的其他 Issue

查看 firebase/flutterfire 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。