LLM Agent 多语言注入规范。在修改 Agent 提示词、添加新的 Agent 端点、处理用户可见的后端消息(message_code)时使用。
npx skills add https://github.com/microsoft/data-formulator --skill language-injection
Authoritative developer guide: docs/dev-guides/6-i18n-language-injection.md.
> Prerequisites: Read docs/dev-guides/6-i18n-language-injection.md before changing Agent prompts, Agent routes, backend user-visible messages, or frontend i18n strings.
> If your work introduces new language injection patterns or conventions, update this file and related dev-guides accordingly.
Frontend i18n.language → Accept-Language header → get_language_instruction()
│
build_language_instruction()
(agents/agent_language.py)
│
┌────────────┴────────────┐
▼ ▼
mode="full" mode="compact"
(text-heavy agents) (code-gen agents)
| Module | Role |
|--------|------|
| agents/agent_language.py | build_language_instruction(lang, mode) — generates prompt fragments; inject_language_instruction() — injects into system prompts; supports 20 languages; returns "" for English |
| routes/agents.py → get_language_instruction() | Reads Accept-Language header, delegates to build_language_instruction |
| routes/agents.py → _get_ui_lang() | Extracts primary language code from Accept-Language header |
| src/app/utils.tsx → fetchWithIdentity() | Sets Accept-Language header on every API request from i18n.language |
| src/app/utils.tsx → translateBackend() | Translates backend message_code / content_code using frontend i18n |
# In a Flask route handler:
lang_instruction = get_language_instruction(mode="compact")
lang_suffix = f"\n\n{lang_instruction}" if lang_instruction else ""
messages = [
{"role": "system", "content": "You are a helpful assistant." + lang_suffix},
{"role": "user", "content": user_input},
]
from data_formulator.agents.agent_language import inject_language_instruction
# Simple append (most agents)
system_prompt = inject_language_instruction(system_prompt, language_instruction)
# Insert before a marker (complex prompts)
system_prompt = inject_language_instruction(
system_prompt, language_instruction,
marker="**About the execution environment:**"
)
For fixed strings in Python that appear in the UI, do NOT translate in Python.
Return a message_code and let the frontend translate:
# In an Agent or route handler:
yield {
"type": "error",
"message": "Output DataFrame is empty (0 rows).", # English fallback
"message_code": "agent.emptyDataframe", # frontend i18n key
}
# With parameters:
result = {
"status": "error",
"content": f"Fields not found: {missing}",
"content_code": "agent.fieldsNotFound",
"content_params": {"missing": missing, "available": available},
}
Frontend consumption:
import { translateBackend } from '../app/utils';
const msg = translateBackend(event.message, event.message_code, event.message_params);
Translation keys go in src/i18n/locales/{en,zh}/messages.json under messages.agent.*.
| Pattern | Why it's wrong |
|---------|---------------|
| os.environ.get("DF_DEFAULT_LANGUAGE") | Process-level — all users get same language; breaks multi-user |
| Global LLM client interceptor | Hidden behavior; can't distinguish full/compact mode; fragile string detection |
| New MessageBuilder class | Duplicates agent_language.py; creates parallel conflicting abstractions |
| Hardcoded "回答请使用中文" in prompts | Not configurable; skips the mode system; breaks for other languages |
| Backend-side translation dict (agent_messages.py) | Forces adding every new language to Python; translations should all live in src/i18n/locales/ |
| Hardcoded English UI strings in .tsx without t() | Not translatable; use useTranslation + t('key') |
LANGUAGE_DISPLAY_NAMES in agents/agent_language.py.LANGUAGE_EXTRA_RULES (e.g. simplified vs traditional Chinese).src/i18n/locales/<lang>/ — copy an existing locale folder as template.A skill that creates new Claude skills and automatically shares them on Slack using Rube for seamless team collaboration and skill discovery.
Walk the operator through creating the first NanoClaw agent for a DM channel — resolve the operator's channel identity, wire the DM messaging group to a new agent, and trigger a welcome DM via the normal delivery path. Use after channel credentials are configured and the service is running.
Authoring playbook for building agents that triage and reply to customer messages — support tickets, email inquiries, chat questions, refund requests, or product issues. Use this when the user wants an agent that handles inbound customer questions, drafts replies, escalates hard cases, summarizes tickets, or follows a support playbook.
Reference skill for Zoom Team Chat. Use after routing to a chat workflow when building user-scoped messaging integrations, chatbot experiences, rich cards, buttons, slash commands, or chat webhooks.
> Advanced and operational chat.agent capabilities for Trigger.dev, loaded on demand. Load this when working on the raw Sessions primitive (sessions / SessionHandle), a custom chat transport or the realtime wire protocol, durable sub-agents (AgentChat, chat.stream.writer), human-in-the-loop, steering, actions, background injection (chat.defer / chat.inject), fast starts (preload, Head Start via @trigger.dev/sdk/chat-server), context resilience (compaction, recovery boot, OOM, large payloads), chat.local run-scoped state, offline testing with mockChatAgent, or prerelease/version upgrades. For the everyday chat.agent({...}) definition and the useTriggerChatTransport happy path, use the trigger-authoring-chat-agent skill instead.
Install and authenticate, on demand, the CLIs the sandbox does not prebake — Node/npm, `gws` (Google Workspace), `gcloud`, `agents-cli` (call remote A2A/ADK agents), and `mcp-cli` (use MCP-server tools). Use this whenever one of those tools is needed but missing (a `node`/`npm`/`gws`/`gcloud`/`agents-cli`/`mcp-cli` command returns "command not found"), or before starting any task that requires one — Google Workspace work (Drive, Gmail, Sheets, Calendar, Chat), GCP via `gcloud`, calling another agent deployed remotely over HTTP (Cloud Run or Vertex Agent Runtime), or using tools exposed by an MCP server. Setup only (install + config + headless auth); each tool's own usage lives in its own skill(s).
Use when preparing HubSpot customer briefs for meetings, renewals, QBRs, sales calls, escalations, handoffs, or follow-ups.
A skill that creates new Claude skills and automatically shares them on Slack using Rube for seamless team collaboration and skill discovery.
Take microsoft/language-injection from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.