fix(langgraph): map LangChain tool status back onto AG-UI ToolMessage.error - #2316
Open
TheSeydiCharyyev wants to merge 1 commit into
Open
Conversation
….error The reverse conversion (langchainMessagesToAgui / langchain_messages_to_agui) dropped the LangChain tool result status, so a status='error' tool message came back to the client with error unset. After ag-ui-protocol#2263 fixed the forward direction, a client whose message list seeds the next run (fresh thread, stateless replay, snapshot-then-resend) re-converted with error unset and silently produced status='success' again, undoing the fix. Map status == 'error' back onto AG-UI's error in both adapters. The forward direction is flag-only, so the original text is not recoverable here; error carries a fixed sentinel so a client can tell a reported failure apart from a reported failure text. Flag durable, text best-effort, per the standard agreed on ag-ui-protocol#2306. A test is added on each side. Fixes ag-ui-protocol#2305
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 #2305.
Problem
#2263 fixed the forward direction (AG-UI → LangChain): an incoming
ToolMessage.errorbecomesstatus="error". The reverse direction was still lossy —langchainMessagesToAgui/langchain_messages_to_aguinever readstatus, so a LangChain tool result withstatus="error"came back to the client witherrorunset.This undoes #2263's fix for any flow where the client's message list seeds the next run (a fresh thread, a stateless replay, a snapshot-then-resend): the client re-converts through the forward path with
errorunset, and silently getsstatus="success"again.Fix
Map
status == "error"back onto AG-UI'serrorin both adapters:integrations/langgraph/typescript/src/utils.ts, thetoolbranch oflangchainMessagesToAgui.integrations/langgraph/python/ag_ui_langgraph/utils.py, theToolMessagebranch oflangchain_messages_to_agui.The sentinel, and the honest contract
Per the standard agreed on #2306, the forward direction is flag-only, so the original error text is not recoverable here.
errortherefore carries a fixed sentinel ("error") rather than a synthesized-but-plausible string, so a client can tell "the agent reported failure" apart from "the agent reported this failure text". The flag is durable across a round trip; the text is best-effort. There is no portable free-text slot to preserve it (Bedrock'stoolResulthas none, AI SDK'sproviderOptionsis provider-namespaced).I picked a bare
"error"sentinel to be obviously synthetic — open to a different marker if you prefer.Tests
A test is added on each side, next to the existing reverse-direction tool-message tests.
message-conversion.test.ts— full package suite green, 268 tests.test_message_conversion.py—unittest discover testsgreen, 385 tests.