[firebase_ai]: TemplateChatSession.sendMessage drops auto-executed function call/response turns from history
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Dart
- Estrellas
- 9.3k
- Forks
- 4.1k
- Merge medio
- 2 d 7 h
- PR fusionados (30 d)
- 47
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase Android SDK (35.0.0 → 35.0.1)Posiblemente ocupada @SelaseKay la tomó hoy. AbiertoNeeds Attention type: enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 20/100
firebase/flutterfire#18807 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[firebase_auth]: authStateChanges() never emits null when the user is force-signed-out before the stream is listened to (iOS, macOS, Android)Posiblemente ocupada @JulianPscheid la tomó hace 3 días. AbiertoNeeds Attention platform: android platform: ios platform: macos plugin: auth reproduced type: bug
Dificultad 4/5 1-2 días Aptitud para principiantes 15/100
firebase/flutterfire#18796 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
blocked: customer-response Needs Attention platform: ios plugin: messaging type: bug
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
firebase/flutterfire#18776 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
[📚] Remote Config Windows Support still N/A on ReadmePosiblemente ocupada @nightcityblade la tomó hace 9 días. Abiertoblocked: customer-response good first issue Needs Attention platform: windows plugin: remote_config type: documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 30/100
firebase/flutterfire#18763 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
[cloud_firestore]: a snapshots() listener cancelled while it registers is never removed nativelyPosiblemente ocupada @chiliec la tomó hace 21 días. AbiertoNeeds Attention platform: android platform: ios platform: macos plugin: cloud_firestore reproduced type: bug
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
firebase/flutterfire#18724 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de firebase/flutterfire
Issues similares
-
[Bug] Windows:开启 Flutter windowing 后对话框被提升为原生窗口,首个 ShowWindow 死锁导致整个应用卡死(设置 → 远程访问端口 100% 复现)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
AimesSoft/NipaPlay-Reload#1021 ·
Los mantenedores suelen responder en 1 día
-
enhancement triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
fluttercommunity/plus_plugins#4004 ·
Los mantenedores suelen responder en 1 día
-
agent:ready bug P2 · 中 健壮性 区域: 启动与合规 待验证 隐私与合规
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
ASDW51/DanmuFloat#106 ·
Los mantenedores suelen responder en 1 día
-
c: proposal p: go_router package team-ecosystem
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
flutter/flutter#194542 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100