From a979105085bce1659cda1dec64c61d9ec57df4aa Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Thu, 18 Jun 2026 16:35:30 -0400 Subject: [PATCH] docs(langchain): document summarization prompt contract (#38256) Adds a contract note for the default summarization prompt so future edits preserve the pieces downstream consumers depend on. The key risk is not the prompt text itself, but the `` marker and `{messages}` placeholder that other middleware uses to splice in additional instructions. --- .../langchain/agents/middleware/summarization.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/langchain_v1/langchain/agents/middleware/summarization.py b/libs/langchain_v1/langchain/agents/middleware/summarization.py index 81c47f48622..9d2e4ffac28 100644 --- a/libs/langchain_v1/langchain/agents/middleware/summarization.py +++ b/libs/langchain_v1/langchain/agents/middleware/summarization.py @@ -76,6 +76,17 @@ Respond ONLY with the extracted context. Do not include any additional informati Messages to summarize: {messages} """ # noqa: E501 +"""Default prompt used to summarize conversation history. + +The `` marker (on its own line) and the `{messages}` placeholder are +part of this constant's public contract, not just cosmetic formatting. +Downstream consumers depend on them: for example, deep agents' +`SummarizationMiddleware` splices an extra instruction block in immediately +before the `` marker via `str.replace`. Removing, renaming, or +reformatting the marker (or the `{messages}` placeholder) is a breaking change +for those consumers even though it does not alter any function signature, so +treat edits to it accordingly. +""" _DEFAULT_MESSAGES_TO_KEEP = 20 _DEFAULT_TRIM_TOKEN_LIMIT = 4000