AGENT SKILL

LLM Agent多语言注入规范

language-injection

LLM Agent 多语言注入规范。在修改 Agent 提示词、添加新的 Agent 端点、处理用户可见的后端消息(message_code)时使用。

适用职业AI 工程师
使用场景智能体开发
License 许可
MIT
最近更新
2026-11-09
Stars
★ 1.8w
Forks
1.7k

01 前言 Front Matter

name
language-injection
description
LLM Agent 多语言注入规范。在修改 Agent 提示词、添加新的 Agent 端点、处理用户可见的后端消息(message_code)时使用。

03 SKILL.md 正文

Language Injection for Agent Prompts

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.

Architecture

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)

Core Modules

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

Code Examples

Route handler — inject language

# 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},
]

Agent constructor — use inject_language_instruction()

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:**"
)

Python-side user-visible messages — message_code pattern

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.*.

Anti-Patterns (with explanations)

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')

Adding a New Language

  1. Add language code + display name to LANGUAGE_DISPLAY_NAMES in agents/agent_language.py.
  2. Optionally add extra rules to LANGUAGE_EXTRA_RULES (e.g. simplified vs traditional Chinese).
  3. Add frontend translations in src/i18n/locales/<lang>/ — copy an existing locale folder as template.
  4. No Agent code changes needed — the existing flow picks up new languages automatically.

04 同仓库更多 Skills

microsoft
microsoft/data-formulator

Markdown 报告生成

report

将一次探索(线程、发现、图表)转换为单篇 Markdown 报告——笔记、博客文章、执行摘要、KPI 仪表板、幻灯片简报或多章节分析报告,并嵌入图表。

数据分析师数据分析与报告
★ 1.8w
microsoft
microsoft/data-formulator

数据源发现与加载

data-loading

发现已连接的数据源,通过用户确认的表单添加新的数据连接器,检查表元数据,并在当前工作区数据不足时运行有界的只读探测。

数据分析师数据分析与报告
★ 1.8w
microsoft
microsoft/data-formulator

数据源发现与加载

data-loading

发现已连接的数据源,通过用户确认的表单添加新的数据连接器,检查表元数据,并在当前工作区数据不足时运行有界只读探测。

数据分析师数据治理与目录管理
★ 1.8w
microsoft
microsoft/data-formulator

分析师内置能力与工具

core

分析师的内置能力:数据检查工具以及始终可用的操作(可视化 visualize 和询问用户 ask_user)。

数据分析师数据分析与报告
★ 1.8w
microsoft
microsoft/data-formulator

服务端路径安全规范

path-safety

服务端路径安全与文件访问编码规范。在编写文件下载路由、Agent 工具(文件读取/目录列出)、数据连接器/Loader、Workspace 路径操作、沙箱配置时使用。

软件开发工程师Web应用安全防护
★ 1.8w
microsoft
microsoft/data-formulator

统一错误处理系统

error-handling

统一错误处理系统。在添加 API 端点、修改错误处理、添加前端 API 调用、编写错误相关测试时使用。

软件开发工程师代码实现
★ 1.8w