fix(core): 在 Agent.resolveSystemPrompt 中集成动态模板渲染
This commit is contained in:
@@ -17,7 +17,13 @@ import {
|
||||
type CompressionConfig,
|
||||
} from '../context/index.js';
|
||||
import type { AgentInfo, ImageData } from '../agent/types.js';
|
||||
import { agentRegistry, AgentExecutor, checkBashPermission } from '../agent/index.js';
|
||||
import {
|
||||
agentRegistry,
|
||||
AgentExecutor,
|
||||
checkBashPermission,
|
||||
renderTemplate,
|
||||
createPlanContext,
|
||||
} from '../agent/index.js';
|
||||
import { loadVisionConfig } from '../utils/config.js';
|
||||
import { getProviderRegistry, resolveApiKey } from '../provider/index.js';
|
||||
import { getHookManager } from '../hooks/index.js';
|
||||
@@ -790,10 +796,23 @@ export class Agent {
|
||||
/**
|
||||
* 解析系统提示词
|
||||
*
|
||||
* 直接使用 Agent 的 prompt 字段作为系统提示词
|
||||
* 如果 Agent 启用了 promptTemplate,则动态渲染模板变量
|
||||
*/
|
||||
private resolveSystemPrompt(agent: AgentInfo): string {
|
||||
return agent.prompt || '';
|
||||
if (!agent.prompt) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// 如果启用了模板渲染,动态解析变量
|
||||
if (agent.promptTemplate) {
|
||||
const context = createPlanContext({
|
||||
workdir: process.cwd(),
|
||||
isSubagent: agent.mode === 'subagent',
|
||||
});
|
||||
return renderTemplate(agent.prompt, context);
|
||||
}
|
||||
|
||||
return agent.prompt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user