fix(langgraph): carry ToolMessage.error onto the LangChain status flag - #2263
Open
TheSeydiCharyyev wants to merge 1 commit into
Open
Conversation
Both langgraph adapters dropped AG-UI's ToolMessage.error when converting an incoming tool message to a LangChain ToolMessage. LangChain has a status field (success/error) for this, and providers such as langchain_anthropic map it onto the model's tool-result flag. With the field dropped, a client-reported tool failure reached the model as a success. The impact is provider-dependent, so it was invisible on Gemini. Map error onto status in both adapters (TypeScript and Python): status is error when the AG-UI error field is set, else success. A test is added on each side. Scope: the status flag only. Preserving the error text and round-tripping it back to the client are separate questions raised in the issue and left out here. Fixes ag-ui-protocol#2226
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.
Fixes #2226.
Problem
Both langgraph adapters drop AG-UI's
ToolMessage.errorwhen they convert an incoming tool message to a LangChainToolMessage. LangChain has astatusfield ("success" | "error") for exactly this, and providers such aslangchain_anthropicmap it onto the model's tool-result flag. With the field dropped, a client-reported tool failure reaches the model as a success. The impact is provider-dependent, so it is invisible on Gemini and shows up on Anthropic.Fix
Map
errorontostatusin both adapters:"error"when the AG-UIerrorfield is set, else"success".integrations/langgraph/typescript/src/utils.ts, thetoolbranch ofaguiMessagesToLangChain. The langgraph-sdkToolMessagetype already typesstatus?: "error" | "success".integrations/langgraph/python/ag_ui_langgraph/utils.py, thetoolbranch ofagui_messages_to_langchain.The AG-UI
ToolMessageschema already haserrorin both languages, so no type changes are needed.Scope
This PR maps the flag only. The two open questions from the issue — preserving the
errortext and round-tripping it back to the client — look like a separate protocol topic and are left out here.Tests
A test is added on each side, next to the existing tool-message conversion tests.
message-conversion.test.ts— full package suite green, 265 tests.test_message_conversion.py—unittest discover testsgreen, 43 tests.