Recover tool calls wrapped in a markdown code fence
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Inizia da normalizeMessage in internal/agent/agent.go, dove la guardia strings.HasPrefix(stripped, "{") e il ramo <tool_call> decidono se il contenuto è una chiamata a uno strumento. Aggiungi un piccolo passaggio prima di questo controllo che rimuova una recinzione a triplo backtick all'inizio e alla fine, ripulisca di nuovo gli spazi e lasci proseguire la logica esistente. Completato quando i nuovi casi in internal/agent/agent_test.go passano, Turn riporta Rounds == 1 per il JSON racchiuso e i test per la prosa e per le recinzioni senza chiamata a strumento restano invariati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What
normalizeMessage recovers tool calls a model writes as plain text, but the entry guard only accepts content whose trimmed form starts with { or <tool_call>. When a model wraps the JSON in a markdown code fence (```json ... ```), the guard bails out and the call is silently dropped — rounds=0, and the raw JSON (or the fence) gets printed to the user as if it were the answer.
Evidence
Real qwen2.5-coder:7b session, prompted to run a command:
great now can you run a command in the terminal to echo the contents of job.go?
stats rounds=0 prompt_tok=1456 ...
{"name": "run_command", "arguments": {"command": "cat", "arguments": ["job.go"]}}
The call is well-formed and safe to run (it would hit the confirmation prompt). It is only missed because of the ```json prefix.
Where
internal/agent/agent.go, normalizeMessage — the strings.HasPrefix(stripped, "{") guard and the <tool_call> branch.
Proposed fix
Before the existing gate, strip a markdown code fence if present:
- If the trimmed content starts with three backticks, drop that first line (the fence plus an optional language tag such as
jsonorjson5), and drop a trailing three-backtick line if present. - Then
TrimSpaceand fall through to the current logic. - Handle the fence appearing around or inside
<tool_call>tags too, whichever ordering is simplest.
Keep the "starts with {" requirement after stripping — that is what keeps prose safe.
Acceptance criteria
- A fenced JSON tool call runs through
Turn(Rounds == 1) and reaches the tool with the correct arguments. - New tests in
internal/agent/agent_test.go: fenced withjsontag, fenced bare, fenced with trailing fence, fenced inside<tool_call>. - Existing negative cases still pass untouched: prose, and a fenced block that is not a tool call.
go build ./...,go vet ./...,go test ./..., andgofmt -l .all clean.
Notes
- Keep it a small, separate branch in
normalizeMessage, matching the style there. - Do not loosen the guard to "content contains
{anywhere" — that would turn any answer containing a JSON snippet into a tool call.
- Lingua principale
- Go
- Stelle
- 1
- Fork
- 2
- Merge medio
- 1h 31m
- PR unite (30g)
- 7
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun 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 Edwin-metcalf/MetCode
-
documentation enhancement help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Edwin-metcalf/MetCode#19 ·
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Edwin-metcalf/MetCode#16 · 1 commento ·
-
testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Edwin-metcalf/MetCode#9 ·
-
Add a MakefileApertaenhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Edwin-metcalf/MetCode#8 ·
-
Add a --host flagApertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Edwin-metcalf/MetCode#7 ·
Tutte le issue di Edwin-metcalf/MetCode
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
keyxmakerx/Chronicle#1469 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Gentleman-Programming/gentle-ai#5565 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug frontend grammar sev-3
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
-
connector docs good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
soma-intelligence/open-health-sync#134 ·
I maintainer di solito rispondono entro 1 giorno
-
bug frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 3 giorni