Curated chat history ends on an unanswered function_call when the turn after AFC is invalid
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- backend-api-design
Rechercherichtung
Read _BaseChat.__init__ and trace _extract_curated_history plus the four send_message variants that handle AFC. Compare their history truncation with record_history and the behavior discussed in #3290; start with tests/chats/test_send_message.py using the replay setup. Done means the curated history and next request handle an invalid turn after a function call consistently, with tests covering the exchange.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
When AFC runs a tool in Chat.send_message and the next model turn is invalid, curated history keeps the function_call and drops the computed function_response.
Dropping the response matches the _BaseChat.__init__ docstring (invalid turns "and their associated inputs"). The call is my question: 2580638 ends a turn on one on purpose when the budget is spent, before any function runs. Here it ran. A hand-built history passed to chats.create curates to the same tail, and #3290 leaves both.
Environment details
- Programming language: Python
- OS: Linux x86_64
- Language runtime version: CPython 3.12.14
- Package version: google-genai 3.0.0, main at afb10e8 (2026-11-07), also #3290 head 3eaeefa
Steps to reproduce
- Run the script below. The stubbed
generate_contentreturns afunction_call, then an emptySAFETYcandidate.
# afc_tail.py
from unittest import mock
from google import genai
from google.genai import types
def get_weather(city: str) -> dict:
"""Returns the weather for a city."""
return {"c": 21}
def kinds(history):
return [c.role + ":" + ("+".join(k for p in c.parts or [] for k in ("text", "function_call", "function_response")
if getattr(p, k) is not None) or "empty") for c in history]
call = types.GenerateContentResponse(candidates=[types.Candidate(content=types.Content(
role="model", parts=[types.Part.from_function_call(name="get_weather", args={"city": "Paris"})]))])
blocked = types.GenerateContentResponse(candidates=[types.Candidate(finish_reason="SAFETY")])
ok = types.GenerateContentResponse(candidates=[types.Candidate(content=types.Content(role="model", parts=[types.Part(text="ok")]))])
client = genai.Client(api_key="not-a-real-key")
chat = client.chats.create(model="gemini-3.8-flash", config=types.GenerateContentConfig(tools=[get_weather]))
sent = []
def fake(*, model, contents, config):
sent.append(list(contents))
return [call, blocked, ok][len(sent) - 1]
with mock.patch.object(chat._modules, "generate_content", side_effect=fake):
chat.send_message("what is the weather in Paris")
print("comprehensive:", kinds(chat.get_history()))
print("curated: ", kinds(chat.get_history(curated=True)))
chat.send_message("try again")
print("next request: ", kinds(sent[-1]))
$ python afc_tail.py # main afb10e8; the same three lines at #3290 head 3eaeefa
comprehensive: ['user:text', 'model:function_call', 'user:function_response', 'model:empty']
curated: ['user:text', 'model:function_call']
next request: ['user:text', 'model:function_call', 'user:text']
With a trial truncation in sync send_message back to the curated length before the AFC loop:
$ python afc_tail.py # main afb10e8 plus that truncation in Chat.send_message
curated: []
next request: ['user:text']
# not run: the live API, so I have not measured how the server answers that next request
# not run: tests/chats/test_send_message.py, which needs the replay setup
I would drop the whole exchange, as record_history already does with an invalid turn's input. The cost is that a retry may run the tool again. That needs the truncation in all four send_message variants, and _extract_curated_history popping through the call when it pops a function response. Is the tail intended once the function ran, or should the exchange go?
- Vorherrschende Sprache
- Python
- Sterne
- 4.1k
- Forks
- 1.1k
- Ø Merge
- 1 T. 21 Std.
- Gemergte PRs (30 T.)
- 103
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus googleapis/python-genai
-
Test import module that doesn't existEvtl. vergeben @Venkaiahbabuneelam hat das vor 24 Tagen übernommen. Offenpriority: p2 type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
googleapis/python-genai#3122 · 6 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Curated history keeps half a user turn when the model turn is invalidEvtl. vergeben @Venkaiahbabuneelam hat das vor 33 Tagen übernommen. Offenpriority: p2 type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
googleapis/python-genai#3051 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFCEvtl. vergeben @Venkaiahbabuneelam hat das vor 33 Tagen übernommen. Offenpriority: p2 type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
googleapis/python-genai#3044 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 57/100
googleapis/python-genai#3313 ·
Maintainer antworten meist innerhalb von 1 Tag
-
SyntaxWarning on import in 3.0.0 (invalid escape sequence in types.py)Evtl. vergeben @VISHNU0906 hat das vor 1 Tag übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 35/100
googleapis/python-genai#3308 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in googleapis/python-genai
Ähnliche Issues
-
integration: logger
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
home-assistant/core#191147 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
documentation p4
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
MillenniumDawn/focus-tree-creation-tool#417 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
CharlesP44/Beem_Energy#96 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
rheeloaded/paperpull#153 ·
Maintainer antworten meist innerhalb von 1 Tag