Recover tool calls wrapped in a markdown code fence
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
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
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.
- Lenguaje dominante
- Go
- Estrellas
- 1
- Forks
- 2
- Merge medio
- 1 h 31 min
- PR fusionados (30 d)
- 7
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Edwin-metcalf/MetCode
-
Add a code coverage badge to CIAbiertodocumentation enhancement help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Edwin-metcalf/MetCode#19 ·
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Edwin-metcalf/MetCode#16 ·
-
Add tests for resolveSafePathAbiertotesting
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Edwin-metcalf/MetCode#9 ·
-
Add a MakefileAbiertoenhancement good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Edwin-metcalf/MetCode#8 ·
-
Add a --host flagAbiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Edwin-metcalf/MetCode#7 ·
Todos los issues de Edwin-metcalf/MetCode
Issues similares
-
area/import kind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
kind/documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
kubernetes-sigs/dra-driver-nvidia-gpu#1569 ·
Los mantenedores suelen responder en 1 día
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
openclaw/openclaw-enterprise#2571 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
All resource links brokenAbierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día