agent.language 配置强制回复语言
This commit is contained in:
@@ -39,6 +39,9 @@ agent:
|
||||
temperature: 1.0
|
||||
max_tool_iterations: 50
|
||||
max_retries: 2
|
||||
# 回复语言:注入到 system prompt 末尾,强制模型用该语言回复用户
|
||||
# (工具名/代码/命令保持原样);留空则不限制。改后重启生效。
|
||||
language: "中文"
|
||||
|
||||
# 大图上传预处理:图片超过 threshold_kb(默认 1.5M)时,浏览器端询问是否压缩;
|
||||
# 同意后在用户本地 canvas 压缩(长边 ≤ image_max_dim,JPEG image_quality)再上传。
|
||||
|
||||
@@ -9,7 +9,7 @@ const DEFAULTS = {
|
||||
workspace_root: './data/tasks',
|
||||
db_path: '', // 默认为 workspace_root/.agent.db
|
||||
terminal: { default_timeout_ms: 30000, max_output_chars: 10000 },
|
||||
agent: { temperature: 1.0, max_tool_iterations: 50, max_retries: 2 },
|
||||
agent: { temperature: 1.0, max_tool_iterations: 50, max_retries: 2, language: '中文' },
|
||||
// 大图上传预处理:图片文件超过 threshold_kb 时,浏览器端询问用户后用 canvas 压缩
|
||||
// (长边 ≤ max_dim,JPEG quality)再上传,减轻服务器带宽与存储压力。参数经 /api/system/status 下发给前端。
|
||||
upload: { image_compress_threshold_kb: 1536, image_max_dim: 2000, image_quality: 0.85 },
|
||||
|
||||
@@ -415,7 +415,7 @@ async function runLoopInner(sessionId, run) {
|
||||
if (!session || session.status !== 'active' || !session.model_id) break;
|
||||
session.history = loadHistory(sessionId);
|
||||
for (const m of session.history) if (m.id > lastIncludedId) lastIncludedId = m.id;
|
||||
const messages = buildMessages(session);
|
||||
const messages = buildMessages(session, (cfg.agent || {}).language);
|
||||
// 内置工具 + 启动时发现的 MCP 工具,一起随 system prompt 发给模型
|
||||
const tools = TOOL_DEFINITIONS.concat(mcp.toolDefinitions());
|
||||
|
||||
|
||||
+15
-3
@@ -12,6 +12,18 @@ function buildSystemPrompt() {
|
||||
return SYSTEM_PROMPT_TEMPLATE;
|
||||
}
|
||||
|
||||
// 部署级回复语言指令:拼在 system prompt 末尾(尾部对弱模型约束力最强)。
|
||||
// 同一进程内恒定,不破坏前缀缓存;改配置需重启生效。
|
||||
function systemPromptText(language) {
|
||||
const t = String(language || '').trim();
|
||||
if (!t) return SYSTEM_PROMPT_TEMPLATE;
|
||||
return SYSTEM_PROMPT_TEMPLATE +
|
||||
'\n\n## Reply Language\n' +
|
||||
'- ALWAYS respond to the user in ' + t + '. Tool descriptions, tool outputs and errors are usually in English — ' +
|
||||
'never let them switch your reply language. Tool names, parameters, code, file paths and shell commands stay as-is; ' +
|
||||
'every sentence addressed to the user MUST be in ' + t + '.';
|
||||
}
|
||||
|
||||
// 多模态内容块存取:messages.content 列为 TEXT,含图片的 tool 消息
|
||||
// 以 {"__blocks__":[content...]} 哨兵 JSON 落库(见需求 §5),
|
||||
// 发请求时还原为 OpenAI 内容块数组(text + image_url)。tool/user 消息共用。
|
||||
@@ -28,8 +40,8 @@ function decodeBlocks(content) {
|
||||
// 省 token:image_url 块仅在其位于最后一条 assistant 消息之后(模型尚未对它回复)时保留;
|
||||
// 之前的视为已消费,发请求时替换为文字标记。DB 始终存全量:UI 历史照常渲染图片,
|
||||
// 模型如需重看可再次 read_file(新消息在尾部,会重新携带图片)。
|
||||
function buildMessages(session) {
|
||||
const messages = [{ role: 'system', content: SYSTEM_PROMPT_TEMPLATE }];
|
||||
function buildMessages(session, language) {
|
||||
const messages = [{ role: 'system', content: systemPromptText(language) }];
|
||||
const history = session.history;
|
||||
let lastAssistant = -1;
|
||||
for (let i = history.length - 1; i >= 0; i--) {
|
||||
@@ -161,4 +173,4 @@ async function callModel(cfg, modelId, messages, tools, options) {
|
||||
return { content, tool_calls: Array.from(toolCalls.values()), finish_reason: finishReason, usage, aborted };
|
||||
}
|
||||
|
||||
module.exports = { callModel, buildMessages, buildSystemPrompt, encodeBlocks, decodeBlocks };
|
||||
module.exports = { callModel, buildMessages, buildSystemPrompt, systemPromptText, encodeBlocks, decodeBlocks };
|
||||
|
||||
@@ -301,10 +301,10 @@
|
||||
</div>
|
||||
|
||||
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
|
||||
<script src="/js/core.js?v=20260902f"></script>
|
||||
<script src="/js/tasks.js?v=20260902f"></script>
|
||||
<script src="/js/skills.js?v=20260902f"></script>
|
||||
<script src="/js/models.js?v=20260902f"></script>
|
||||
<script src="/js/settings.js?v=20260902f"></script>
|
||||
<script src="/js/core.js?v=20260902g"></script>
|
||||
<script src="/js/tasks.js?v=20260902g"></script>
|
||||
<script src="/js/skills.js?v=20260902g"></script>
|
||||
<script src="/js/models.js?v=20260902g"></script>
|
||||
<script src="/js/settings.js?v=20260902g"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -37,6 +37,7 @@ const CFG_FORM = [
|
||||
{ path: 'agent.temperature', label: '温度 temperature', type: 'float' },
|
||||
{ path: 'agent.max_tool_iterations', label: '单会话最大工具轮次', type: 'int' },
|
||||
{ path: 'agent.max_retries', label: '上游失败重试次数', type: 'int' },
|
||||
{ path: 'agent.language', label: '回复语言(留空不限)', type: 'text' },
|
||||
] },
|
||||
{ group: '终端工具', items: [
|
||||
{ path: 'terminal.default_timeout_ms', label: '命令默认超时(ms)', type: 'int' },
|
||||
@@ -120,6 +121,12 @@ function svcCard(st) {
|
||||
function cfgInput(it) {
|
||||
const cur = getByPath(effCfg, it.path);
|
||||
const v = cur == null ? '' : String(cur);
|
||||
if (it.type === 'text') {
|
||||
return '<div class="cfg-kv"><label>' + esc(it.label) + '</label>' +
|
||||
'<input class="cfg-input" type="text"' +
|
||||
' data-path="' + att(it.path) + '" data-type="text" data-label="' + att(it.label) + '" data-orig="' + att(v) + '"' +
|
||||
' value="' + att(v) + '" placeholder="如:中文 / English"></div>';
|
||||
}
|
||||
const step = it.type === 'float' ? ' step="any"' : ' step="1"';
|
||||
return '<div class="cfg-kv"><label>' + esc(it.label) + '</label>' +
|
||||
'<input class="cfg-input" type="number"' + step +
|
||||
|
||||
Reference in New Issue
Block a user