Back Home

GitHub Repo

LangChain Community Reports Dynamic Tool Routing Anomaly That May Cause Agents to Stop Early

A LangChain community report on October 25 says that running dynamically registered tools alongside direct-return tools may cause an agent to skip further model processing. The report includes a comparison script that requires no external API, but maintainers have yet to confirm the root cause or an official fix.

Dirck van Baburen · Public domain · Image source
zh-Hant

On October 25, the LangChain community reported that create_agent may stop without letting the model continue to synthesize results when, in the same turn, it calls both a direct-return tool and a regular tool dynamically registered through middleware. According to the reporter, both tools execute successfully, but the agent may end the run without further model processing. The behavior was observed in LangChain 1.4.7 and on a specified commit on the main branch; the reporter also disclosed that AI assisted with the investigation. Issue report

The official documentation says return_direct=True lets a tool’s output become the final result, avoiding an additional model call. But when a batch also includes regular tools, all tool results should be sent back to the model. The agent should stop only when every tool in the batch is configured for direct return. The documentation also supports dynamically adjusting tools based on permissions, verification status, or conversation stage, so the interaction between these features can affect the integrity of the agent’s workflow. Tool execution and dynamic selection documentation

The minimal reproduction uses a fake model that returns scripted responses by default, and requests both a direct-answer tool and a query tool whose result still requires analysis. When both tools are registered in advance, the model is called twice. When the query tool is instead added by middleware during execution, the model is called only once, leaving the tool output unanalyzed; no exception is raised. This comparison requires no model provider, credentials, or network inference, which helps rule out generation randomness. Reproduction code and output

The reporter points to _make_tools_to_model_edge as a possible source of the problem: if the direct-return check considers only the static tool table, it may fail to account for dynamic tools. This root cause remains unconfirmed. For engineering teams, the case is a reminder that successful tool execution does not mean the agent has completed the task. Integration tests should check whether mixed calls return control to the model and whether the final answer handles all results. Pre-registering the tools restored the expected behavior in this case, but may not be suitable for every deployment. At the time of review, the issue remained open, with no related fix PR. Follow-up should track maintainer confirmation, synchronous and asynchronous regression tests, and a release containing the fix. Issue status

Sources

  1. create_agent ends mixed batches early when a non-direct tool is registered at runtime
  2. Tools — Return directly from a tool and Dynamic tool selection