Skip to content

docs(tools): a failed returnDirect call ends the run too - #811

Merged
blove merged 1 commit into
mainfrom
blove/langchain-returndirect-fix-f2b391
Sep 23, 2026
Merged

blove merged 1 commit into
mainfrom
blove/langchain-returndirect-fix-f2b391

Conversation

@blove

@blove blove commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Summary

returnDirect (shipped in #800) ends the run on any result from the tool, including an error. LangGraph's prebuilt agent routes to END by matching the trailing ToolMessage's name against the returnDirect set and never checks status, so when a returnDirect tool throws, or the model's arguments fail the tool's schema, the error ToolMessage ends the run and the model never gets to correct the call.

This PR corrects the docs until that changes upstream:

  • apps/web/content/docs/tools.mdx ("Ending the run from a tool"): adds a paragraph saying a failed call ends the run too, so returnDirect is only for tools that cannot usefully fail. A validating renderer that expects the model to fix a rejected call should stay a normal tool. The example is replaced: it awaited validateUi(input), which made it exactly the kind of tool that should not use returnDirect.
  • packages/core/src/capabilities/types.ts: the B4ToolDefinition.returnDirect JSDoc says the same thing.
  • Changeset: patch for @b4run/cli (the docs ship in its bundled docs/) and @b4run/core (JSDoc).

Reproduced against the latest published @langchain/langgraph 1.4.17 (createReactAgent, what B4 uses) and langchain 1.5.12 (createAgent): a scripted model calls a returnDirect tool that fails, then retries. Both runs end after 1 model call on the error ToolMessage. A fix that skips status: "error" messages is being proposed upstream, and it gives 2 calls and ends on the successful retry. The Python version of this bug is langchain-ai/langchain#36411.

Test plan

  • node scripts/check-docs.mjs passes
  • Biome is clean on the changed source file
  • CI validate

🤖 Generated with Claude Code

LangGraph's prebuilt agent routes a returnDirect tool's result to END by
tool name without checking the ToolMessage status, so an error result
(the tool threw, or the model's arguments failed the schema) also ends
the run and the model never gets to retry. Say so in the Tools docs and
the B4ToolDefinition JSDoc, and replace the example, which validated its
input and so was exactly the tool that should not use returnDirect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Sep 23, 2026 3:43pm UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@blove
blove merged commit 7f81d24 into main Sep 23, 2026
31 of 32 checks passed
@blove
blove deleted the blove/langchain-returndirect-fix-f2b391 branch September 23, 2026 18:12

This branch was successfully deployed

1 active and 1 inactive deployments
vercel-preview — 928e50d4 Deployed Sep 23, 2026 by blove via vercel-native #2283
Preview — 928e50d4 Deployed Sep 23, 2026 by vercel[bot]
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.

1 participant