[GH-ISSUE #1962] [langchain]: <Please write a comprehensive title> #247

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

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

Type of issue

issue / bug

Language

Python

Description

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),
),
],
)

Using fractional limits

agent3 = create_agent(
model="gpt-4o",
tools=[your_weather_tool, your_calculator_tool],
middleware=[
SummarizationMiddleware(
model="gpt-4o-mini",
trigger=("fraction", 0.8),
keep=("fraction", 0.3),
),
],
)

Single condition 与Multiple conditions logic both or

Originally created by @longchen111111 on GitHub (Dec 17, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/1962 ### Type of issue issue / bug ### Language Python ### Description 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), ), ], ) # Using fractional limits agent3 = create_agent( model="gpt-4o", tools=[your_weather_tool, your_calculator_tool], middleware=[ SummarizationMiddleware( model="gpt-4o-mini", trigger=("fraction", 0.8), keep=("fraction", 0.3), ), ], ) Single condition 与Multiple conditions logic both or
yindo added the langchainexternal labels 2026-02-17 17:19:29 -05:00
yindo changed title from [langchain]: <Please write a comprehensive title> to [GH-ISSUE #1962] [langchain]: <Please write a comprehensive title> 2026-06-05 17:25:52 -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#247