Skip to content

fix(agent): recover concatenated tool arguments#1461

Open
wolfkill wants to merge 1 commit into
Tencent:mainfrom
wolfkill:fix/agent-concat-tool-args
Open

fix(agent): recover concatenated tool arguments#1461
wolfkill wants to merge 1 commit into
Tencent:mainfrom
wolfkill:fix/agent-concat-tool-args

Conversation

@wolfkill
Copy link
Copy Markdown
Contributor

Summary

  • Fixes [Bug]: Failed to parse tool arguments: invalid character '{' after top-level value #1455.
  • Recovers tool calls where the model/provider concatenates two JSON argument objects into one Function.Arguments string, e.g. {...}{...}.
  • Uses only the first complete top-level JSON object, then keeps the existing RepairJSON fallback unchanged for other malformed JSON cases.
  • Adds regression coverage for the Agent tool-call path and JSON object extraction edge cases.

Why this is safe

  • Valid JSON arguments are not changed because this recovery only runs after normal json.Unmarshal fails.
  • Existing JSON repair behavior is preserved when no complete first JSON object can be recovered.
  • The fix does not merge multiple objects, which would be ambiguous; it executes the first valid argument payload and logs the recovery.

Tests

  • CGO_LDFLAGS="-lc++" go test ./internal/agent -run TestRunToolCallRecoversConcatenatedJSONArguments -count=1
  • CGO_LDFLAGS="-lc++" go test ./internal/agent/tools -run 'Test(ExtractFirstJSONObject|RepairJSON)' -count=1
  • CGO_LDFLAGS="-lc++" go test ./internal/agent ./internal/agent/tools -count=1
  • CGO_LDFLAGS="-lc++" go test ./internal/agent/... -count=1
  • git diff --check

Also ran CGO_LDFLAGS="-lc++" go test ./internal/... -count=1; Agent-related packages passed, while unrelated existing tests failed in internal/application/service, internal/application/service/file, internal/datasource/connector/yuque, and internal/infrastructure/web_search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Failed to parse tool arguments: invalid character '{' after top-level value

1 participant