Recover tool calls wrapped in a markdown code fence
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in internal/agent/agent.go at normalizeMessage, where the strings.HasPrefix(stripped, "{") guard and the <tool_call> branch decide whether content is a tool call. Add a small step before that gate that strips a leading and trailing triple-backtick fence, then re-trims and falls through to the existing logic. Done when the new cases in internal/agent/agent_test.go pass, Turn reports Rounds == 1 for fenced JSON, and the prose and non-tool-call fence tests are unchanged.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Go
- Stars
- 1
- Forks
- 2
- Avg merge
- 1h 31m
- Merged PRs (30d)
- 7
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Edwin-metcalf/MetCode
-
documentation enhancement help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Edwin-metcalf/MetCode#19 ·
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Edwin-metcalf/MetCode#16 ·
-
testing
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Edwin-metcalf/MetCode#9 ·
-
Add a MakefileOpenenhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Edwin-metcalf/MetCode#8 ·
-
Add a --host flagOpenenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Edwin-metcalf/MetCode#7 ·
All issues in Edwin-metcalf/MetCode
Similar issues
-
documentation hacktoberfest priority: low skill: good first issue status: ready for dev
Difficulty 2/5 Half a day Newbie friendliness 85/100
hyperledger-labs/fabric-smart-client#2142 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
numberly/vault-db-injector#107 ·
Maintainers usually reply within 1 day
-
area/import kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
[DOC] Wrong sg_egress_ports range in the Terraform Databricks Guide for AWS Hub & Spoke with Network FirewallPossibly taken @akhil9tiet claimed this today. Opendocs
Difficulty 1/5 Under an hour Newbie friendliness 72/100
databricks/terraform-provider-databricks#6080 · 1 comment ·
Maintainers usually reply within 3 days
-
spqr-coordinator usage shows 'run --config', but 'run' is not a subcommand (unknown command "run")Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pg-sharding/spqr#3092 · 1 comment ·
Maintainers usually reply within 1 day