Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#18,757 コメント 2 件 リアクション 0 件 担当者 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日 2時間
マージ済み PR(30日)
38

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/flutterfire のほかの issue

firebase/flutterfire の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。