SummarizationNode causing invalid chat history? #1011

Closed
opened 2026-02-20 17:42:43 -05:00 by yindo · 2 comments
Owner

Originally created by @peterkarman1 on GitHub (Oct 17, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

summarization_model = LLMProvider().llm(LLMTaskType.SUMMARIZATION)
        summarization_node = SummarizationNode(
            token_counter=partial(
                LLMTokenCounter.count_tokens,
                extra_tokens_per_message=AppConfig.EXTRA_TOKENS_PER_MESSAGE,
                chars_per_token=AppConfig.CHARACTERS_PER_TOKEN,
            ),
            model=summarization_model,
            max_tokens=AppConfig.MAX_CONTEXT_LENGTH_TOKENS,
            max_summary_tokens=AppConfig.MAX_OUTPUT_TOKENS,
            output_messages_key="messages",  # using the same key as input to override the history
            initial_summary_prompt=INITIAL_SUMMARY_PROMPT,
            existing_summary_prompt=EXISTING_SUMMARY_PROMPT,
        )

        prompt = PromptTemplate.from_template(prompt_template)
        prompt = prompt.invoke(prompt_input).to_string()
        checkpointer = MemorySaver()
        agent_executor = create_react_agent(
            model=llm,
            tools=tools,
            prompt=SystemMessage(content=prompt),
            debug=Env.LLM_VERBOSE,
            checkpointer=checkpointer,
            pre_model_hook=summarization_node,
            state_schema=ReactAgentState,
        )

                task = asyncio.create_task(
                    agent_executor.ainvoke(
                        {"messages": [HumanMessage(content=json.dumps(inputs))]},
                        {
                            "metadata": {"context_name": context_name},
                            "recursion_limit":200,
                            "configurable": {
                                "thread_id": cls.get_thread_id(context_name)
                            },
                        },
                    )
                )

                result = await asyncio.wait_for(task, timeout=900)



My thread id code

    def get_thread_id(cls, context_name):
        return hashlib.sha256(context_name.encode()).hexdigest()


and example of what goes to context_name
        unique_id = uuid.uuid4()
task_id="some_id"

        context_name = (
            f"{self.__class__.__name__} ({task_id}) {unique_id}"
        )

Error Message and Stack Trace (if applicable)

Found AIMessages with tool_calls that do not have a corresponding ToolMessage. Here are the first few of those tool calls:

Description

I have added the summarization node to my react agent. Since adding this, I intermittently get the error message
Found AIMessages with tool_calls that do not have a corresponding ToolMessage. Here are the first few of those tool calls:

Removing the summarization node seems to make this go away so it seems like this is the cause. I'm not sure if I'm doing something wrong(probably) or if there is a bug.

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
Python Version: 3.12.8 (main, Dec 6 2024, 19:42:06) [Clang 18.1.8 ]

Package Information

langchain_core: 0.3.76
langchain: 0.3.27
langchain_community: 0.3.30
langsmith: 0.3.45
langchain_anthropic: 0.3.21
langchain_aws: 0.2.34
langchain_azure_ai: 0.1.4
langchain_openai: 0.3.33
langchain_text_splitters: 0.3.11
langgraph_sdk: 0.2.9

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.12.12
aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
anthropic<1.0.0,>=0.69.0: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
azure-ai-inference[opentelemetry]: Installed. No version info available.
azure-core: 1.35.1
azure-cosmos: 4.9.0
azure-identity: 1.25.0
azure-monitor-opentelemetry: Installed. No version info available.
beautifulsoup4: Installed. No version info available.
bedrock-agentcore: Installed. No version info available.
boto3: 1.40.45
dataclasses-json<0.7.0,>=0.6.7: Installed. No version info available.
httpx: 0.28.1
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
httpx>=0.25.2: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<1.0.0,>=0.3.72: Installed. No version info available.
langchain-core<1.0.0,>=0.3.76: Installed. No version info available.
langchain-core<2.0.0,>=0.3.75: Installed. No version info available.
langchain-core<2.0.0,>=0.3.76: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-perplexity;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langchain<2.0.0,>=0.3.27: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith<1.0.0,>=0.1.125: Installed. No version info available.
langsmith>=0.1.17: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
numpy: 2.2.5
numpy>=1.26.2;: Installed. No version info available.
numpy>=2.1.0;: Installed. No version info available.
openai-agents: Installed. No version info available.
openai<2.0.0,>=1.104.2: Installed. No version info available.
opentelemetry-api: 1.36.0
opentelemetry-exporter-otlp-proto-http: 1.36.0
opentelemetry-instrumentation-threading: Installed. No version info available.
opentelemetry-sdk: 1.36.0
opentelemetry-semantic-conventions-ai: Installed. No version info available.
orjson: 3.10.16
orjson>=3.10.1: Installed. No version info available.
packaging: 24.2
packaging>=23.2: Installed. No version info available.
playwright: Installed. No version info available.
pydantic: 2.11.3
pydantic-settings<3.0.0,>=2.10.1: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic>=2.7.4: Installed. No version info available.
pytest: 8.4.1
PyYAML<7.0.0,>=5.3.0: Installed. No version info available.
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.5
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
requests<3.0.0,>=2.32.5: Installed. No version info available.
rich: Installed. No version info available.
SQLAlchemy<3,>=1.4: Installed. No version info available.
SQLAlchemy<3.0.0,>=1.4.0: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0

Originally created by @peterkarman1 on GitHub (Oct 17, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python summarization_model = LLMProvider().llm(LLMTaskType.SUMMARIZATION) summarization_node = SummarizationNode( token_counter=partial( LLMTokenCounter.count_tokens, extra_tokens_per_message=AppConfig.EXTRA_TOKENS_PER_MESSAGE, chars_per_token=AppConfig.CHARACTERS_PER_TOKEN, ), model=summarization_model, max_tokens=AppConfig.MAX_CONTEXT_LENGTH_TOKENS, max_summary_tokens=AppConfig.MAX_OUTPUT_TOKENS, output_messages_key="messages", # using the same key as input to override the history initial_summary_prompt=INITIAL_SUMMARY_PROMPT, existing_summary_prompt=EXISTING_SUMMARY_PROMPT, ) prompt = PromptTemplate.from_template(prompt_template) prompt = prompt.invoke(prompt_input).to_string() checkpointer = MemorySaver() agent_executor = create_react_agent( model=llm, tools=tools, prompt=SystemMessage(content=prompt), debug=Env.LLM_VERBOSE, checkpointer=checkpointer, pre_model_hook=summarization_node, state_schema=ReactAgentState, ) task = asyncio.create_task( agent_executor.ainvoke( {"messages": [HumanMessage(content=json.dumps(inputs))]}, { "metadata": {"context_name": context_name}, "recursion_limit":200, "configurable": { "thread_id": cls.get_thread_id(context_name) }, }, ) ) result = await asyncio.wait_for(task, timeout=900) My thread id code def get_thread_id(cls, context_name): return hashlib.sha256(context_name.encode()).hexdigest() and example of what goes to context_name unique_id = uuid.uuid4() task_id="some_id" context_name = ( f"{self.__class__.__name__} ({task_id}) {unique_id}" ) ``` ### Error Message and Stack Trace (if applicable) ```shell Found AIMessages with tool_calls that do not have a corresponding ToolMessage. Here are the first few of those tool calls: ``` ### Description I have added the summarization node to my react agent. Since adding this, I intermittently get the error message Found AIMessages with tool_calls that do not have a corresponding ToolMessage. Here are the first few of those tool calls: Removing the summarization node seems to make this go away so it seems like this is the cause. I'm not sure if I'm doing something wrong(probably) or if there is a bug. ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041 > Python Version: 3.12.8 (main, Dec 6 2024, 19:42:06) [Clang 18.1.8 ] Package Information ------------------- > langchain_core: 0.3.76 > langchain: 0.3.27 > langchain_community: 0.3.30 > langsmith: 0.3.45 > langchain_anthropic: 0.3.21 > langchain_aws: 0.2.34 > langchain_azure_ai: 0.1.4 > langchain_openai: 0.3.33 > langchain_text_splitters: 0.3.11 > langgraph_sdk: 0.2.9 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > aiohttp: 3.12.12 > aiohttp<4.0.0,>=3.8.3: Installed. No version info available. > anthropic<1.0.0,>=0.69.0: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > azure-ai-inference[opentelemetry]: Installed. No version info available. > azure-core: 1.35.1 > azure-cosmos: 4.9.0 > azure-identity: 1.25.0 > azure-monitor-opentelemetry: Installed. No version info available. > beautifulsoup4: Installed. No version info available. > bedrock-agentcore: Installed. No version info available. > boto3: 1.40.45 > dataclasses-json<0.7.0,>=0.6.7: Installed. No version info available. > httpx: 0.28.1 > httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. > httpx>=0.25.2: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > langchain-anthropic;: Installed. No version info available. > langchain-aws;: Installed. No version info available. > langchain-azure-ai;: Installed. No version info available. > langchain-cohere;: Installed. No version info available. > langchain-community;: Installed. No version info available. > langchain-core<1.0.0,>=0.3.72: Installed. No version info available. > langchain-core<1.0.0,>=0.3.76: Installed. No version info available. > langchain-core<2.0.0,>=0.3.75: Installed. No version info available. > langchain-core<2.0.0,>=0.3.76: Installed. No version info available. > langchain-deepseek;: Installed. No version info available. > langchain-fireworks;: Installed. No version info available. > langchain-google-genai;: Installed. No version info available. > langchain-google-vertexai;: Installed. No version info available. > langchain-groq;: Installed. No version info available. > langchain-huggingface;: Installed. No version info available. > langchain-mistralai;: Installed. No version info available. > langchain-ollama;: Installed. No version info available. > langchain-openai;: Installed. No version info available. > langchain-perplexity;: Installed. No version info available. > langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available. > langchain-together;: Installed. No version info available. > langchain-xai;: Installed. No version info available. > langchain<2.0.0,>=0.3.27: Installed. No version info available. > langsmith-pyo3: Installed. No version info available. > langsmith<1.0.0,>=0.1.125: Installed. No version info available. > langsmith>=0.1.17: Installed. No version info available. > langsmith>=0.3.45: Installed. No version info available. > numpy: 2.2.5 > numpy>=1.26.2;: Installed. No version info available. > numpy>=2.1.0;: Installed. No version info available. > openai-agents: Installed. No version info available. > openai<2.0.0,>=1.104.2: Installed. No version info available. > opentelemetry-api: 1.36.0 > opentelemetry-exporter-otlp-proto-http: 1.36.0 > opentelemetry-instrumentation-threading: Installed. No version info available. > opentelemetry-sdk: 1.36.0 > opentelemetry-semantic-conventions-ai: Installed. No version info available. > orjson: 3.10.16 > orjson>=3.10.1: Installed. No version info available. > packaging: 24.2 > packaging>=23.2: Installed. No version info available. > playwright: Installed. No version info available. > pydantic: 2.11.3 > pydantic-settings<3.0.0,>=2.10.1: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic>=2.7.4: Installed. No version info available. > pytest: 8.4.1 > PyYAML<7.0.0,>=5.3.0: Installed. No version info available. > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.5 > requests-toolbelt: 1.0.0 > requests<3,>=2: Installed. No version info available. > requests<3.0.0,>=2.32.5: Installed. No version info available. > rich: Installed. No version info available. > SQLAlchemy<3,>=1.4: Installed. No version info available. > SQLAlchemy<3.0.0,>=1.4.0: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tiktoken<1,>=0.7: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > zstandard: 0.23.0
yindo added the bugpending labels 2026-02-20 17:42:43 -05:00
yindo closed this issue 2026-02-20 17:42:43 -05:00
Author
Owner

@Jayantparashar10 commented on GitHub (Oct 18, 2025):

can you assign this to me?

@Jayantparashar10 commented on GitHub (Oct 18, 2025): can you assign this to me?
Author
Owner

@sydney-runkle commented on GitHub (Nov 7, 2025):

We're now recommending usage of SummarizationMiddleware in LangChain, going to close this as stale given that!

@sydney-runkle commented on GitHub (Nov 7, 2025): We're now recommending usage of `SummarizationMiddleware` in LangChain, going to close this as stale given that!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1011