diff --git a/plugins/memory/hindsight/__init__.py b/plugins/memory/hindsight/__init__.py index 7d88f54b4a..709e2ba2f8 100644 --- a/plugins/memory/hindsight/__init__.py +++ b/plugins/memory/hindsight/__init__.py @@ -919,11 +919,8 @@ class HindsightMemoryProvider(MemoryProvider): def _recall_disabled(self) -> bool: """Guards shared by the async and synchronous recall paths.""" - for skip, why in ( - (self._memory_mode == "tools", "tools-only mode"), - (not self._auto_recall, "auto_recall disabled"), - (self._shutting_down.is_set(), "shutting down"), - ): + for skip, why in ((self._memory_mode == "tools", "tools-only mode"), (not self._auto_recall, "auto_recall disabled"), + (self._shutting_down.is_set(), "shutting down")): if skip: logger.debug("Prefetch: skipped (%s)", why) return True @@ -1157,8 +1154,7 @@ class HindsightMemoryProvider(MemoryProvider): return [] if self._memory_mode == "context" else [RETAIN_SCHEMA, RECALL_SCHEMA, REFLECT_SCHEMA] def _tool_retain(self, args: dict) -> str: - content = args["content"] - context = args.get("context") + content, context = args["content"], args.get("context") item = self._build_retain_kwargs(content, context=context, tags=args.get("tags"), occurred_at=args.get("occurred_at")) logger.debug("Tool hindsight_retain: bank=%s, content_len=%d, context=%s", @@ -1193,10 +1189,9 @@ class HindsightMemoryProvider(MemoryProvider): } def handle_tool_call(self, tool_name: str, args: dict, **kwargs) -> str: - entry = self._TOOL_HANDLERS.get(tool_name) - if entry is None: + required, handler = self._TOOL_HANDLERS.get(tool_name, ("", None)) + if handler is None: return tool_error(f"Unknown tool: {tool_name}") - required, handler = entry if not args.get(required, ""): return tool_error(f"Missing required parameter: {required}") try: diff --git a/plugins/memory/query_rewrite.py b/plugins/memory/query_rewrite.py index 8789239012..9b3c0c22df 100644 --- a/plugins/memory/query_rewrite.py +++ b/plugins/memory/query_rewrite.py @@ -50,9 +50,7 @@ def _bounded_user_message(message: str) -> str: text = (message or "").strip() if len(text) <= _MAX_INPUT_CHARS: return text - head = text[:3_000].rstrip() - tail = text[-900:].lstrip() - return f"{head}\n\n[... middle omitted ...]\n\n{tail}" + return f"{text[:3_000].rstrip()}\n\n[... middle omitted ...]\n\n{text[-900:].lstrip()}" def _extract_response_text(response: Any) -> str: diff --git a/plugins/observability/langfuse/__init__.py b/plugins/observability/langfuse/__init__.py index 3da9f0bd27..7907667095 100644 --- a/plugins/observability/langfuse/__init__.py +++ b/plugins/observability/langfuse/__init__.py @@ -300,9 +300,8 @@ def _truncate_text(value: str, max_chars: int) -> Any: # Redact BEFORE truncating so a secret straddling the cut cannot leak. if _capture_mode() == "sanitized": value = _redact_secrets(value) - if len(value) <= max_chars: - return value - return value[:max_chars] + f"... [truncated {len(value) - max_chars} chars]" + over = len(value) - max_chars + return value if over <= 0 else value[:max_chars] + f"... [truncated {over} chars]" def _maybe_parse_json_string(value: str) -> Any: