Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Recover tool calls wrapped in a markdown code fence

Aperta Adatta ai principianti
#18 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
ai

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

bug good first issue
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 json or json5), and drop a trailing three-backtick line if present.
  • Then TrimSpace and 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 with json tag, 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 ./..., and gofmt -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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Edwin-metcalf/MetCode

Tutte le issue di Edwin-metcalf/MetCode

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.