Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created January 10, 2026 15:02
Show Gist options
  • Select an option

  • Save larkintuckerllc/c0e4a005d2cbecaaa829b8d43585dd8c to your computer and use it in GitHub Desktop.

Select an option

Save larkintuckerllc/c0e4a005d2cbecaaa829b8d43585dd8c to your computer and use it in GitHub Desktop.
diff --git a/app.py b/app.py
index e101a85..a7d3334 100644
--- a/app.py
+++ b/app.py
@@ -2,6 +2,7 @@ import os
import threading
from langchain.agents import create_agent
+from langchain.agents.middleware import SummarizationMiddleware
from langgraph.checkpoint.memory import InMemorySaver
from langchain.messages import HumanMessage
from langchain.tools import tool
@@ -29,6 +30,13 @@ def square_root(x: float) -> float:
agent = create_agent(
checkpointer=InMemorySaver(),
+ middleware=[
+ SummarizationMiddleware(
+ model="gpt-5-nano",
+ trigger=("tokens", 10000),
+ keep=("messages", 4)
+ )
+ ],
model="gpt-5-nano",
tools=[square_root],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment