Skip to content

The agent that grows with you

fix(agent): preserve legacy summary hook overrides

fangliquanflq4d3409f7ff42
diff --git a/agent/context_compressor_summary.py b/agent/context_compressor_summary.py
index 42361ff4d91..0cb46716aac 100644
--- a/agent/context_compressor_summary.py
+++ b/agent/context_compressor_summary.py
@@ -2,6 +2,7 @@
from __future__ import annotations
+import inspect
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from agent.auxiliary_client import AuxiliaryExplicitCancellation
@@ -10,6 +11,21 @@ if TYPE_CHECKING:
from agent.context_compressor import _HandoffScan
+def _accepts_keyword_argument(callable_obj: Any, name: str) -> bool:
+ """Return whether an inspectable callable accepts ``name`` as a keyword."""
+ try:
+ parameters = inspect.signature(callable_obj).parameters
+ except (TypeError, ValueError):
+ return False
+ if any(parameter.kind is inspect.Parameter.VAR_KEYWORD for parameter in parameters.values()):
+ return True
+ parameter = parameters.get(name)
+ return parameter is not None and parameter.kind in (
+ inspect.Parameter.POSITIONAL_OR_KEYWORD,
+ inspect.Parameter.KEYWORD_ONLY,
+ )
+
+
class SummaryDispatchMixin:
def _summarize_window(
self, messages: List[Dict[str, Any]], turns_to_summarize: List[Dict[str, Any]], scan: "_HandoffScan",
@@ -17,11 +33,14 @@ class SummaryDispatchMixin:
) -> Optional[str]:
"""Run the summary LLM; a cancellation rolls back the handoff scan's self-heal mutation first."""
# Focus-topic derivation scans user turns; only pay when a summary is generated.
+ summary_kwargs: Dict[str, Any] = {
+ "focus_topic": focus_topic or self._derive_auto_focus_topic(messages),
+ "memory_context": memory_context,
+ }
+ if bypass_cooldown and _accepts_keyword_argument(self._generate_summary, "bypass_cooldown"):
+ summary_kwargs["bypass_cooldown"] = True
try:
- return self._generate_summary(
- turns_to_summarize, focus_topic=focus_topic or self._derive_auto_focus_topic(messages),
- memory_context=memory_context, bypass_cooldown=bypass_cooldown,
- )
+ return self._generate_summary(turns_to_summarize, **summary_kwargs)
except AuxiliaryExplicitCancellation:
# Cancellation is a true no-op: restore the scan's mutation before the exception escapes.
self._previous_summary = scan.previous_summary_before