feat(acp): support locale injection via ACP initialize for i18n - #128
feat(acp): support locale injection via ACP initialize for i18n#128Million-mo wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for client locales within the ACP server by extracting the locale from client metadata and injecting a language directive into the agent's system prompts. Feedback highlights a potential prompt injection vulnerability where the client-provided locale should be validated, and suggests using explicit is not None checks for metadata dictionary presence. Additionally, a potential memory leak and state residue risk was identified, recommending that the locale prompt be cleaned up in ACPSession.close() to ensure proper garbage collection.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Client can pass locale through ACP initialize request's _meta field.
The locale is propagated through session creation and injected as a
callable system prompt that instructs the agent to respond in the
specified language.
Changes:
- AgentPoolACPAgent.initialize(): extract locale from params.field_meta
- AgentPoolACPAgent: thread client_locale through all session creation
paths (new_session, fork_session, load_session, resume_session)
- ACPSessionManager: accept and forward client_locale in
create_session() and resume_session()
- ACPSession: add client_locale field, inject get_locale_prompt()
callable prompt in __post_init__() and switch_active_agent()
- Update test assertion to include client_locale kwarg
Client usage (ACP initialize JSON-RPC):
{
"method": "initialize",
"params": {
"_meta": { "locale": "en" },
"protocolVersion": 1,
...
}
}
Address code review feedback: - Extract locale validation into _extract_locale() helper with format checking (alphanumeric + hyphens, max 15 chars) to prevent prompt injection via crafted locale strings - Use explicit 'is not None' check for field_meta instead of implicit truthiness - Add get_locale_prompt cleanup in ACPSession.close() to prevent memory leak and stale state residue
…ies test The test_from_config_capabilities_not_duplicated test used model='openai:gpt-4o-mini' which requires OPENAI_API_KEY to initialize the OpenAI client. This causes CI failures on fork PRs where repository secrets are not available. Switch to TestModelConfig which needs no API credentials.
ffef79f to
a515134
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for client locales in the ACP server. It extracts and validates the client's locale from metadata during initialization, propagates it to sessions, and appends a system prompt instructing the agent to respond in the preferred language. The review feedback highlights a security improvement in the locale validation logic, suggesting that the character check be restricted to ASCII alphanumeric characters to prevent potential prompt injection via Unicode characters.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Per review feedback, c.isalnum() returns True for Unicode characters (Chinese, Cyrillic, etc.), which could allow prompt injection via crafted locale strings. Added c.isascii() guard to restrict to ASCII-only alphanumeric characters, hyphens, and underscores.
Same fix as PR wolf1069b#128 — replace openai:gpt-4o-mini with TestModelConfig so the test doesn't need real API credentials in CI.
Summary
支持通过 ACP
initialize请求传入 locale 变量,实现 agent 输出的多语言国际化。客户端在 ACP
initialize时通过_meta字段传入locale,agentpool 将其透传到 session,并作为 callable system prompt 注入到 agent,指导 agent 以指定语言响应。Background
当前 agentpool 不支持任何 i18n 基础设施。agent 输出语言完全由 YAML 配置中的静态 prompt 文本决定,客户端无法在运行时指定语言偏好。
Changes
服务端(agentpool)
acp_agent.pyinitialize()从params.field_meta提取locale,存储为self.client_locale;在new_session/fork_session/load_session/resume_session中透传session_manager.pycreate_session()和resume_session()接受client_locale参数,转发给ACPSessionsession.pyACPSession增加client_locale字段;__post_init__()和switch_active_agent()中注入get_locale_prompt()callable prompttest_acp_session_resume.pyclient_localekwarg客户端支持
ACP 客户端在
initialize请求中通过_meta字段传入 locale:{ "method": "initialize", "params": { "protocolVersion": 1, "clientInfo": { "name": "xeno-agent", "title": "Xeno Agent", "version": "1.0" }, "clientCapabilities": { "terminal": true, "fs": { "readTextFile": true, "writeTextFile": true } }, "_meta": { "locale": "en" } } }如果使用 agentpool 的 ACP 客户端 SDK(
ACPAgentAPI):metadata参数会被序列化为field_meta,在 JSON-RPC 中映射为_meta。How It Works
initialize时通过_meta.locale传入语言偏好AgentPoolACPAgent.initialize()提取并存储self.client_localenew_session/fork_session/load_session/resume_session将 locale 传递到ACPSessionManagerACPSession.__post_init__()将get_locale_prompt作为 callable prompt 注册到 agent 的sys_prompts.prompts"Language: You MUST respond in en."指令复用了已有的 callable prompt 机制(与
get_cwd_context完全同构),在switch_active_agent时也会正确清理和重新注入。Testing
ruff check✅mypy✅pytest tests/servers/acp_server/— 315 passed, 4 skipped ✅pytest tests/acp/ tests/agents/acp_agent/— 251 passed ✅Limitations / Future Work
format_system_prompt()支持{{ locale }}模板变量AgentPoolACPAgent实例)new_session级别的 locale 覆盖