Curated chat history ends on an unanswered function_call when the turn after AFC is invalid
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- backend-api-design
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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?
- Linguagem predominante
- Python
- Estrelas
- 4.1k
- Forks
- 1.1k
- Merge médio
- 1d 20h
- PRs com merge (30d)
- 99
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de googleapis/python-genai
-
Interactions retries ignore the documented `initial_delay` and `max_delay` defaultsTalvez já em andamento @Sun-Wukhan assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
googleapis/python-genai#3317 ·
Mantenedores costumam responder em até 1 dia
-
Test import module that doesn't existTalvez já em andamento @Venkaiahbabuneelam assumiu há 25 dias. Abertapriority: p2 type: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
googleapis/python-genai#3122 · 6 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Curated history keeps half a user turn when the model turn is invalidTalvez já em andamento @Venkaiahbabuneelam assumiu há 34 dias. Abertapriority: p2 type: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
googleapis/python-genai#3051 · 3 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFCTalvez já em andamento @Venkaiahbabuneelam assumiu há 34 dias. Abertapriority: p2 type: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
googleapis/python-genai#3044 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
all `client.webhooks` operations fail with API error occurred: Status 404Talvez já em andamento @VISHNU0906 assumiu hoje. Abertapriority: p2 type: bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 54/100
googleapis/python-genai#3316 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de googleapis/python-genai
Issues semelhantes
-
LLVM versionsAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
Mantenedores costumam responder em até 1 dia
-
Translate docs/ to SpanishAbertadocumentation good first issue language
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 91/100
-
good first issue help wanted translation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 1 dia
-
Fix duplicated word in speculative decoding docsTalvez já em andamento @ddlw assumiu hoje. Abertacommunity-request
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 89/100
NVIDIA/Megatron-LM#9118 ·
Mantenedores costumam responder em até 2 dias