Skip to content

feat: add AGENTMEMORY_OUTPUT_LANG to control generated-text language#711

Open
cyangfang wants to merge 1 commit into
rohitg00:mainfrom
cyangfang:feat/output-language-env
Open

feat: add AGENTMEMORY_OUTPUT_LANG to control generated-text language#711
cyangfang wants to merge 1 commit into
rohitg00:mainfrom
cyangfang:feat/output-language-env

Conversation

@cyangfang
Copy link
Copy Markdown

@cyangfang cyangfang commented May 28, 2026

Problem

All LLM-generated memory fields (title, narrative, facts, concepts, summary) are produced in the language the system prompts are written in — English — regardless of the user's working language. For non-English users this means:

  • Memories are stored in English even when every input is in their native language, making them hard to read back.
  • Native-language recall queries match these English memories poorly (cross-lingual gap on both the BM25 and dense legs), so cross-session memory becomes much less useful.

A quick A/B against a real corpus showed same-concept recall scoring ~4x worse for a non-English query than its English equivalent, largely because the stored text had been forced to English.

Change

Add an opt-in AGENTMEMORY_OUTPUT_LANG env var. It's injected once in ResilientProvider — the wrapper every provider passes through — so a single change covers compress + summarize across all providers and all prompts (compression, summary, consolidation, graph-extraction, reflect, …).

Value Behaviour
unset / empty unchanged — English (strictly opt-in, default byte-for-byte identical)
match follow the user's input/observation language
zh / ja / ko / … known code, expanded to a full language label
any other string used verbatim as the target language name (e.g. Português)

Code, identifiers, and file paths are always preserved verbatim.

Why ResilientProvider

Every provider is constructed inside a ResilientProvider (see createProvider / createFallbackProvider), and both compress and summarize funnel through it. Injecting the directive there keeps the diff to ~6 lines and guarantees no prompt path is missed, rather than touching each of the 10+ call sites.

Files

  • src/prompts/output-language.ts (new) — outputLanguageDirective() helper
  • src/providers/resilient.ts — append directive in compress / summarize
  • .env.example — document the flag

Notes

  • Returning "" for the unset case keeps current behaviour exactly, so existing users see no change.
  • Verified the directive logic for all input shapes (unset, match, known codes case-insensitively, verbatim names).

Summary by CodeRabbit

  • New Features
    • Added configurable output language feature for generated text fields (title, narrative, facts, summary). Users can set the language to English (default), match their input language, or specify any target language via the AGENTMEMORY_OUTPUT_LANG environment variable.

Review Change Stack

LLM-generated memory fields (title, narrative, facts, concepts, summary)
are always produced in the language the system prompts are written in
(English), regardless of the user's working language. Non-English users
get English memories that are hard to read and that their native-language
recall queries match poorly.

Add an opt-in AGENTMEMORY_OUTPUT_LANG env var, injected once in
ResilientProvider (the wrapper every provider passes through), so a single
change covers compress + summarize across all providers and prompts:

  - unset / empty  -> unchanged behaviour (English); strictly opt-in
  - "match"        -> follow the user's input/observation language
  - "zh"/"ja"/...  -> a known code, expanded to a full language label
  - any other      -> used verbatim as the target language name

Code, identifiers, and file paths are always preserved verbatim. Documented
in .env.example.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@cyangfang is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2afa1727-0045-4a36-b252-8fc655a629f6

📥 Commits

Reviewing files that changed from the base of the PR and between 59ab328 and e9d9f4d.

📒 Files selected for processing (3)
  • .env.example
  • src/prompts/output-language.ts
  • src/providers/resilient.ts

📝 Walkthrough

Walkthrough

This PR adds configurable output language control for generated text fields. A new environment variable AGENTMEMORY_OUTPUT_LANG documents language selection modes (English default, "match" for user input language, or explicit language identifiers). A new utility function processes this variable and returns appropriately formatted directives for LLM system prompts. The resilient provider integrates this directive into compress and summarize methods.

Changes

Output Language Directive

Layer / File(s) Summary
Output language directive definition
.env.example, src/prompts/output-language.ts
Configuration variable AGENTMEMORY_OUTPUT_LANG documents language modes (default English, "match" to follow user input, or explicit identifiers). The outputLanguageDirective() utility reads the environment variable, returns empty string when unset, returns a "match user language" directive for "match", or returns a formatted directive with canonicalized language labels or raw language names.
Resilient provider integration
src/providers/resilient.ts
The resilient provider imports and uses outputLanguageDirective() to append language directives to system prompts in compress() and summarize() methods before delegating to inner provider calls.

🎯 2 (Simple) | ⏱️ ~12 minutes

🐰 A linguistic hop through prompts anew,
Where output speaks in language true—
Match the input, or English bright,
Or chosen tongues set just right.
The directive whispers, soft and clear,
What language should the LLM hear? 🌍

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add AGENTMEMORY_OUTPUT_LANG to control generated-text language' directly and accurately summarizes the main change—introducing a new environment variable to control the output language of generated text fields.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant