Skip to content

fix(langgraph): map LangChain tool status back onto AG-UI ToolMessage.error - #2316

Open
TheSeydiCharyyev wants to merge 1 commit into
ag-ui-protocol:mainfrom
TheSeydiCharyyev:fix/2305-langgraph-reverse-tool-status
Open

fix(langgraph): map LangChain tool status back onto AG-UI ToolMessage.error#2316
TheSeydiCharyyev wants to merge 1 commit into
ag-ui-protocol:mainfrom
TheSeydiCharyyev:fix/2305-langgraph-reverse-tool-status

Conversation

@TheSeydiCharyyev

Copy link
Copy Markdown
Contributor

Fixes #2305.

Problem

#2263 fixed the forward direction (AG-UI → LangChain): an incoming ToolMessage.error becomes status="error". The reverse direction was still lossy — langchainMessagesToAgui / langchain_messages_to_agui never read status, so a LangChain tool result with status="error" came back to the client with error unset.

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 error unset, and silently gets status="success" again.

Fix

Map status == "error" back onto AG-UI's error in both adapters:

  • TypeScript — integrations/langgraph/typescript/src/utils.ts, the tool branch of langchainMessagesToAgui.
  • Python — integrations/langgraph/python/ag_ui_langgraph/utils.py, the ToolMessage branch of langchain_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. error therefore 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's toolResult has none, AI SDK's providerOptions is 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.

  • TS: message-conversion.test.ts — full package suite green, 268 tests.
  • Python: test_message_conversion.pyunittest discover tests green, 385 tests.

….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
@TheSeydiCharyyev
TheSeydiCharyyev requested a review from a team as a code owner August 5, 2026 04:24
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]: LangGraph adapters drop ToolMessage status on the LangChain → AG-UI direction, so a tool failure is not durable across MESSAGES_SNAPSHOT

1 participant