[GH-ISSUE #2027] Documentation Issue: Identical code examples for Single (AND) vs Multiple (OR) conditions in SummarizationMiddleware #256

Open
opened 2026-02-17 17:19:30 -05:00 by yindo · 0 comments
Owner

Originally created by @LingangXiao on GitHub (Dec 26, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/2027

Type of issue

issue / bug

Language

Python

Description

Title: Documentation Issue: Identical code examples for Single (AND) vs Multiple (OR) conditions in SummarizationMiddleware
Description: I was reading the Built-in middleware documentation specifically regarding SummarizationMiddleware. The documentation explains two types of trigger logic:

Single condition (AND logic: all properties must be met)

Multiple conditions (OR logic: any condition must be met)

However, the provided code examples for these two scenarios are syntactically identical (both use a list of tuples), which is confusing.

Snippet from the official doc (https://docs.langchain.com/oss/python/langchain/middleware/built-in#configuration-options):

from langchain.agents import create_agent
from langchain.agents.middleware import SummarizationMiddleware

Single condition: trigger if tokens >= 4000 AND messages >= 10

agent = create_agent(
model="gpt-4o",
tools=[your_weather_tool, your_calculator_tool],
middleware=[
SummarizationMiddleware(
model="gpt-4o-mini",
trigger=[("tokens", 4000), ("messages", 10)],
keep=("messages", 20),
),
],
)

Multiple conditions

agent2 = create_agent(
model="gpt-4o",
tools=[your_weather_tool, your_calculator_tool],
middleware=[
SummarizationMiddleware(
model="gpt-4o-mini",
trigger=[
("tokens", 3000),
("messages", 6),
],
keep=("messages", 20),
),
],
)

Both examples use a list of tuples [("key", value), ...]. This makes it unclear how to actually implement the "AND" logic versus the "OR" logic.

Please review the example code, and thanks for sharing these new functions!!!

Originally created by @LingangXiao on GitHub (Dec 26, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/2027 ### Type of issue issue / bug ### Language Python ### Description Title: Documentation Issue: Identical code examples for Single (AND) vs Multiple (OR) conditions in SummarizationMiddleware Description: I was reading the [Built-in middleware documentation](https://www.google.com/search?q=https://python.langchain.com/docs/how_to/agents/middleware/built-in/%23summarization) specifically regarding SummarizationMiddleware. The documentation explains two types of trigger logic: Single condition (AND logic: all properties must be met) Multiple conditions (OR logic: any condition must be met) However, the provided code examples for these two scenarios are syntactically identical (both use a list of tuples), which is confusing. Snippet from the official doc (https://docs.langchain.com/oss/python/langchain/middleware/built-in#configuration-options): from langchain.agents import create_agent from langchain.agents.middleware import SummarizationMiddleware # Single condition: trigger if tokens >= 4000 AND messages >= 10 agent = create_agent( model="gpt-4o", tools=[your_weather_tool, your_calculator_tool], middleware=[ SummarizationMiddleware( model="gpt-4o-mini", trigger=[("tokens", 4000), ("messages", 10)], keep=("messages", 20), ), ], ) # Multiple conditions agent2 = create_agent( model="gpt-4o", tools=[your_weather_tool, your_calculator_tool], middleware=[ SummarizationMiddleware( model="gpt-4o-mini", trigger=[ ("tokens", 3000), ("messages", 6), ], keep=("messages", 20), ), ], ) Both examples use a list of tuples [("key", value), ...]. This makes it unclear how to actually implement the "AND" logic versus the "OR" logic. Please review the example code, and thanks for sharing these new functions!!!
yindo added the langchainexternal labels 2026-02-17 17:19:30 -05:00
yindo changed title from Documentation Issue: Identical code examples for Single (AND) vs Multiple (OR) conditions in SummarizationMiddleware to [GH-ISSUE #2027] Documentation Issue: Identical code examples for Single (AND) vs Multiple (OR) conditions in SummarizationMiddleware 2026-06-05 17:25:54 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#256