Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Recover tool calls wrapped in a markdown code fence

Open Beginner friendly
#18 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
ai

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

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.
Dominant language
Go
Stars
1
Forks
2
Avg merge
1h 31m
Merged PRs (30d)
7

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Edwin-metcalf/MetCode

All issues in Edwin-metcalf/MetCode

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.