Repair partial text tool-call recovery#4445
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the agent’s resilience to provider responses that begin XML-style text tool-call markup but truncate before emitting a complete tool call, by detecting the partial markup and retrying with targeted repair guidance (plus adding a regression test for this scenario).
Changes:
- Add detection for incomplete
<tool_call …>openings and extract the intended tool name when possible. - In
askLocked, if no tool calls were executed but a partial text tool call was detected, retry with a scoped prompt instructing the model to emit one complete valid tool call. - Add regression coverage for a provider response that stops at an opening
<tool_call>tag and succeeds on retry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| agent/text_tool_calls.go | Adds partial <tool_call> opener detection helper and supporting regex. |
| agent/agent.go | Uses the partial tool-call detection to trigger a repair/retry turn when no tool executed. |
| agent/conformance_test.go | Adds regression test ensuring partial text tool-call markup triggers a repair retry and executes the tool. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+123
to
+144
| openMatches := openingTaggedToolCall.FindAllStringSubmatchIndex(text, -1) | ||
| if len(openMatches) == 0 { | ||
| return "" | ||
| } | ||
| closedMatches := singleTaggedToolCall.FindAllStringSubmatchIndex(text, -1) | ||
| for _, open := range openMatches { | ||
| closed := false | ||
| for _, match := range closedMatches { | ||
| if match[0] == open[0] { | ||
| closed = true | ||
| break | ||
| } | ||
| } | ||
| if closed { | ||
| continue | ||
| } | ||
| tag := text[open[2]:open[3]] | ||
| name := taggedToolName(tag) | ||
| if canonical := allowed[name]; canonical != "" { | ||
| return canonical | ||
| } | ||
| } |
This was referenced Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Testing: