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

19 lines
817 B
Python

"""Capture the run preference without changing checkpoint or backend APIs."""
from deerflow.agents.language import ui_locale
_MEMORY_LOCALE_KEY = "deerflow_ui_locale"
def with_memory_locale(messages: list, context: object) -> list:
locale = ui_locale(context)
captured = []
for message in messages:
kwargs = {key: value for key, value in message.additional_kwargs.items() if key != _MEMORY_LOCALE_KEY}
if locale is not None:
kwargs[_MEMORY_LOCALE_KEY] = locale
# Stamp every queued copy: filtering and the extraction watermark may
# leave only an assistant tail. Never write this marker to graph state.
captured.append(message.model_copy(update={"additional_kwargs": kwargs}) if kwargs != message.additional_kwargs else message)
return captured