agent-ops-patterns / gallery / LangChain map / how it decides

How LangChain decides

In the ordinary tool loop of an agent built with LangChain's create_agent, the model decides when it is finished: a reply that asks for no tool ends the run, and nothing checks that reply. By default nothing trims the conversation; call limits and summarization are middleware the developer adds.

From langchain-ai/langchain at source version efebcf50, mapped 2026-11-02. Each answer links the place in the code where that decision is made; the full map has the rest.

How it decides it is done

Limits and memory

Other judgments

Three problems in the code

  1. 1. In an agent with tools, a reply with only invalid_tool_calls ends the run

    In an agent with a tools step, if a reply's calls are all recorded as invalid_tool_calls (on ChatOpenAI's chat-completions path, arguments that are not valid JSON) and its tool_calls list is empty, the run ends there, without retrying them and without an exception. On that route, the model is told about such a call only on a later invocation that carries that history, and only if the call has an ID.

    Already tracked upstream (#33504), checked 2026-11-15.

    Where: factory.py:2016-2019, factory.py:692-707. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-08, in four rounds; each sentence it questioned was narrowed, removed or kept with the reason recorded.

  2. 2. An invalid structured answer beside another tool call can end the run without a structured response

    With a tool-based response format and the default error handling, one reply can hold a structured answer that fails to parse and also an ordinary tool call. The ordinary tool can then run and the run can end with no structured response and no exception, before the model reads the retry message.

    Already tracked upstream (#40423), checked 2026-11-15.

    Where: factory.py:1329-1346, factory.py:2021-2032, factory.py:2102-2104. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-08, in four rounds; each sentence it questioned was narrowed, removed or kept with the reason recorded.

  3. 3. A long tool loop can turn summarized history into a fixed placeholder

    By default, summarization middleware tries to trim the older messages to a 4,000-token window that starts at a human message. If nothing is left, as can happen in a long run of tool calls after one request, the summary model is not called and the older messages are replaced by the text "Previous conversation was too long to summarize."

    Already tracked upstream (#41146), checked 2026-11-15.

    Where: summarization.py:1028-1046, summarization.py:935-937. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-08, in four rounds; each sentence it questioned was narrowed, removed or kept with the reason recorded.

See the full map →

This card was taken from the published map of LangChain, which read langchain-ai/langchain and langchain-ai/langgraph at one commit each; its code pointers cover the langchain repository only, it covers only decisions shown there, it did not look at code outside the map's scope (an agent built with create_agent, its opt-in middleware and the LangGraph runtime) or at the 3 decisions left out of that edition, and no LangChain code was run to make it.

Map: edition with 3 of 92 cards left out (published 2026-11-03) · taken from the full map · card data: gallery/cards/langchain.json. Found something wrong? Use the correction form.