jianyx1 4b1e06bbf9
feat(runtime): honor the web UI language in replies and DeerMem updates (#7294)
* feat(runtime): honor the web UI language in replies and DeerMem updates

Carry Settings > Appearance > Language as request-only run data: the
Gateway validates context.locale against a finite allowlist, the lead
agent prefers it for replies, and bundled DeerMem writes new facts and
summary prose in it. Explicit user language requests still take
precedence; checkpoint configurable, static prompts, and memory backend
APIs are unchanged.

Refs #7287

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(runtime): guard language context and pin locale maps

* test(runtime): pin UI locales across frontend and Gateway

Add the shared locale fixture and document the intentional language fallback for internal runs. Clarify live-locale precedence in the run context contract.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-26 13:24:30 +08:00

35 lines
1.6 KiB
Python

"""Hooks fired before summarization removes messages from state."""
from __future__ import annotations
from deerflow.agents.memory import get_memory_manager
from deerflow.agents.memory.locale import with_memory_locale
from deerflow.agents.middlewares.memory_middleware import redact_queued_messages
from deerflow.agents.middlewares.summarization_middleware import SummarizationEvent
from deerflow.config.memory_config import get_memory_config
from deerflow.config.pii_redaction_config import PiiRedactionConfig
from deerflow.runtime.user_context import resolve_runtime_user_id
def memory_flush_hook(event: SummarizationEvent, pii_redaction_config: PiiRedactionConfig | None = None) -> None:
"""Flush messages about to be summarized into the memory queue.
Thin, backend-agnostic entry: only the ``enabled`` + ``thread_id`` gate
and ``user_id`` resolution live here. The backend (via
``manager.add_nowait``) does the filtering, human/AI validation, and
correction/reinforcement detection. The queued payload is redacted at
this boundary (#3190 vector 5): compaction removes these messages from
state right after, so the later after-agent redaction cannot repair a
raw batch queued here.
"""
if not get_memory_config().enabled or not event.thread_id:
return
user_id = resolve_runtime_user_id(event.runtime)
get_memory_manager().add_nowait(
event.thread_id,
with_memory_locale(redact_queued_messages(list(event.messages_to_summarize), pii_redaction_config), getattr(event.runtime, "context", None)),
agent_name=event.agent_name,
user_id=user_id,
)