Skip to content

fix(ai): keep auto-executed function turns in TemplateChatSession history - #18758

Open
chiliec wants to merge 1 commit into
firebase:mainfrom
chiliec:fix/template-chat-auto-function-history
Open

chiliec wants to merge 1 commit into
firebase:mainfrom
chiliec:fix/template-chat-auto-function-history

Conversation

@chiliec

@chiliec chiliec commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #18757.

TemplateChatSession.sendMessage only added the original user message and the final model response to history, dropping the intermediate turns collected in requestHistory — the model's functionCall content and the function responses produced by auto-executed TemplateAutoFunctionDeclarations. On the next sendMessage the model no longer saw what its tools returned (e.g. an id a prior call created), while the other three paths (sendMessageStream, ChatSession.sendMessage, ChatSession.sendMessageStream) already append the whole exchange with addAll(requestHistory).

The change aligns sendMessage with the streaming path. requestHistory is seeded with [message], so in the non-auto single-turn case addAll(requestHistory) records exactly the same user message as before — no behavior change there.

Tests

Added sendMessage retains auto-executed function turns in history to server_template_test.dart: a mocked two-turn exchange (first response a functionCall, second the final text) asserts history ends up with 4 entries — user message, functionCall, functionResponse, final reply — matching what sendMessageStream produces.

Validation

Ran from a standalone checkout of packages/firebase_ai/firebase_ai (Flutter 3.47.5, headless):

  • RED (before fix): the new test fails — Expected length 4, Actual length 2.
  • GREEN (after fix): flutter test test/server_template_test.dart — all 6 pass.
  • Regression: flutter test test/chat_test.dart — all pass; full package suite flutter test — 353 passed, 9 skipped.

…tory

TemplateChatSession.sendMessage only added the user message and final
model response to history, dropping the intermediate functionCall and
functionResponse turns collected in requestHistory. On a follow-up
sendMessage the model no longer saw what its tools returned. The other
three paths (sendMessageStream, ChatSession.sendMessage/Stream) already
append the whole requestHistory. Align sendMessage with them.
@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant