Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Recover tool calls wrapped in a markdown code fence

Abierto Apto para principiantes
#18 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
ai

Línea de trabajo

Empieza en internal/agent/agent.go en normalizeMessage, donde la guarda strings.HasPrefix(stripped, "{") y la rama <tool_call> deciden si el contenido es una llamada a herramienta. Añade un paso pequeño antes de esa comprobación que elimine una valla de triple backtick al principio y al final, vuelva a recortar los espacios y continúe con la lógica existente. Terminado cuando los nuevos casos de internal/agent/agent_test.go pasen, Turn informe Rounds == 1 para JSON con valla, y las pruebas de prosa y de vallas que no son llamadas a herramienta no cambien.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Go
Estrellas
1
Forks
2
Merge medio
1 h 31 min
PR fusionados (30 d)
7

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Edwin-metcalf/MetCode

Todos los issues de Edwin-metcalf/MetCode

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.