fix: pass is_error field to Anthropic API in tool results#7428
Open
ameenalkhaldi wants to merge 2 commits intomicrosoft:mainfrom
Open
fix: pass is_error field to Anthropic API in tool results#7428ameenalkhaldi wants to merge 2 commits intomicrosoft:mainfrom
ameenalkhaldi wants to merge 2 commits intomicrosoft:mainfrom
Conversation
The Anthropic client was dropping the is_error field when converting FunctionExecutionResult to ToolResultBlockParam. The field exists on the result and is set correctly by StaticWorkbench and AssistantAgent, but was never forwarded to the API. This means Claude couldn't distinguish tool errors from successful results. Relates to microsoft#5267
Contributor
|
@ameenalkhaldi please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Author
|
@microsoft-github-policy-service agree |
Explains the recommended pattern for handling tool errors: catch exceptions and return them as FunctionExecutionResult with is_error=True, so the model receives the error and can decide how to proceed. Also adds a brief cross-reference from the AgentChat tutorial to the Core API docs for error handling. Relates to microsoft#5272
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.
Why are these changes needed?
The Anthropic model client drops the
is_errorfield when convertingFunctionExecutionResulttoToolResultBlockParam. The field is already populated correctly throughout the codebase —StaticWorkbenchsetsis_error=Trueon caught exceptions,AssistantAgentpropagates it from tool results, and tests verify it's set. Buttool_message_to_anthropic()never passes it through to the API.Anthropic's
ToolResultBlockParamnatively supportsis_error, and passing it lets Claude distinguish actual tool output from error messages, which improves its retry and error handling behavior.Related issue number
Relates to #5267 (sub-task 2: explicit error field)
Checks