bug: instruct() and react() replay tool-call turns without tool_calls
I maintainer di solito rispondono entro 3 giorni
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
Direzione di ricerca
Inizia leggendo ChatFormatter.to_chat_messages in mellea/formatters/chat_formatter.py (righe 78-86) per vedere come i turni di assistant sono costruiti da Instruction._parse e ReactThought._parse. Conferma che ModelOutputThunk con tool_calls li perde quando il messaggio successivo è un ruolo tool. Fatto significa che la seconda chiamata instruct() invia il turno di assistant con i suoi tool_calls, soddisfacendo i provider rigorosi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Found while testing LLM provider integrations in agent frameworks: an automated tool flags candidates and each one is reproduced before it is reported. Reproduced on e6249a5 against local fake endpoints; no real provider was called.
With a ChatContext, a tool loop built on instruct() sends the tool-calling assistant turn back without its tool_calls, so the tool message after it answers nothing. react() does the same. On strict providers the loop dies at its second step.
session = MelleaSession(OpenAIBackend(model_id="gpt-5.1"), ctx=ChatContext())
options = {ModelOption.TOOLS: [weather_tool]}
result = session.instruct("What is the weather in Paris?", model_options=options, tool_calls=True, strategy=None)
for message in call_tools(result, session.backend):
session.ctx = session.ctx.add(message)
session.instruct("Answer using the tool results above.", model_options=options, tool_calls=True, strategy=None)
The second request carries:
[{"role": "user", "content": "What is the weather in Paris?"},
{"role": "assistant", "content": ""},
{"role": "tool", "content": "18C", "tool_call_id": "call_1"},
{"role": "user", "content": "Answer using the tool results above."}]
OpenAI answers that shape with a 400, Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'. (same error on an orphaned tool message in agent-framework#9851). Through LiteLLMBackend, the gemini/ and vertex_ai/ routes never get as far as a request: LiteLLM raises litellm.APIConnectionError: Missing corresponding tool call for tool response message. The anthropic/ route sends a tool_result with no tool_use before it, which Anthropic's tool docs rule out and which comes back as unexpected tool_use_id found in tool_result blocks (example).
Ollama's OpenAI layer has no pairing check, which may be why this hasn't surfaced there, but the model still never sees its own call. The same loop written with session.chat() sends the turn correctly.
Expected: the assistant turn keeps its tool_calls whichever component produced it.
Cause: the fix for #1349 made Message._parse keep tool calls, but Instruction._parse and ReactThought._parse return only the text, so ChatFormatter.to_chat_messages builds a plain Message from an empty string. That is the empty assistant turn #1349 described, still present for instruct(). reasoning_content and Gemini's extra_content are lost with it, so the replay rule from #1201 never applies here.
Fix idea: after building the list in to_chat_messages, when a ModelOutputThunk has tool_calls and the next message has role tool, rebuild that turn with Message._parse. The check on the next message matters, because calls the caller never ran would otherwise go out as dangling tool_calls, and strict providers reject those too.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 161
- Merge medio
- 4g 3h
- PR unite (30g)
- 45
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di generative-computing/mellea
-
bug: `mellea.plugins.builtin_debug.generation.log_generation_post_call` shows model as unknownApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
generative-computing/mellea#1864 ·
I maintainer di solito rispondono entro 3 giorni
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examplesForse già presa @madhusudhan1260 l’ha presa 18 giorni fa. Apertagood first issue p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
generative-computing/mellea#1780 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 3 giorni
-
area/telemetry enhancement p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
generative-computing/mellea#1210 ·
I maintainer di solito rispondono entro 3 giorni
-
Add requirement priorityApertaarea/requirement area/stdlib enhancement p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
generative-computing/mellea#31 · 2 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
generative-computing/mellea#1863 ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di generative-computing/mellea
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
OpenFreeEnergy/openfe#2371 ·
I maintainer di solito rispondono entro 2 giorni
-
HMDB's smiles file writes "None" for metabolites with an empty <smiles/> (file not currently used)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
NCATSTranslator/Babel#1269 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 80/100
I maintainer di solito rispondono entro 1 giorno
-
404 on sample dataApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
bcgov/nr-hydrometric-rating-curve#443 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100