AI智能体Prompt模式
RailWise多智能体系统的Prompt设计模式,涵盖ReAct、Plan-and-Solve、Reflection等模式
AI智能体Prompt模式
Section titled “AI智能体Prompt模式”适用产品: RAILWISE-CLI
目标读者: AI应用架构师、Prompt工程师、后端开发工程师
阅读时间: 约35分钟
1.1 什么是AI智能体Prompt模式
Section titled “1.1 什么是AI智能体Prompt模式”AI智能体Prompt模式(AI Agent Prompt Patterns)是指用于构建自主AI Agent的标准化Prompt结构和方法论。在RailWise RAILWISE-CLI系统中,这些模式定义了Agent如何理解任务、使用工具、进行推理和协作。
1.2 核心模式列表
Section titled “1.2 核心模式列表”| 模式名称 | 适用场景 | 复杂度 | 可靠性 |
|---|---|---|---|
| ReAct | 工具调用、多步骤推理 | 中 | 高 |
| Plan-and-Solve | 复杂任务分解 | 高 | 高 |
| Reflection | 自我纠错、结果优化 | 中 | 高 |
| Multi-Agent Debate | 多视角分析、决策优化 | 高 | 中 |
| Chain-of-Verification | 事实核查、幻觉抑制 | 中 | 高 |
| Tool-Former | 动态工具选择 | 中 | 中 |
1.3 架构概览
Section titled “1.3 架构概览”┌─────────────────────────────────────────┐│ RAILWISE-CLI Agent系统 │├─────────────────────────────────────────┤│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │ ReAct │ │ Plan │ │Reflect │ ││ │ Agent │ │ Agent │ │ Agent │ ││ └────┬────┘ └────┬────┘ └────┬────┘ ││ └─────────────┴─────────────┘ ││ │ ││ ┌─────────────┐ ││ │ 协调器 │ ││ │ Coordinator │ ││ └──────┬──────┘ ││ │ ││ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │ 测量 │ │ 监测 │ │ 报告 │ ││ │ Agent │ │ Agent │ │ Agent │ ││ └─────────┘ └─────────┘ └─────────┘ │└─────────────────────────────────────────┘2. ReAct模式(Reasoning + Acting)
Section titled “2. ReAct模式(Reasoning + Acting)”2.1 模式原理
Section titled “2.1 模式原理”ReAct模式将推理(Reasoning)和行动(Acting)交织进行,Agent在每一步先思考当前状态,然后决定下一步行动。
2.2 Prompt结构
Section titled “2.2 Prompt结构”const REACT_SYSTEM_PROMPT = `你是一个轨道交通监测领域的AI助手,可以使用以下工具完成任务:
可用工具:{{#each tools}}- {{name}}: {{description}} 参数: {{parameters}}{{/each}}
工作规则:1. 每次回复必须以"思考:"开头,分析当前情况2. 然后决定"行动:",选择工具或给出最终答案3. 如果调用工具,格式为:行动:工具名[参数]4. 收到工具结果后,继续"思考:"并决定下一步5. 当任务完成时,输出"最终答案:"
示例格式:思考:用户需要查询测点MP-01的最新数据,我需要先调用数据查询工具。行动:query_measurement[point_id="MP-01", limit=1]
观察:{"point_id":"MP-01","x":29567.123,"y":10458.456,"z":12.345}
思考:已获得数据,现在需要分析变形量。行动:analyze_deformation[point_id="MP-01", baseline="initial"]
观察:{"status":"normal","displacement":0.001}
思考:分析完成,测点状态正常,可以给出最终答案。最终答案:测点MP-01当前状态正常,位移量0.001mm,处于稳定状态。`;2.3 完整实现示例
Section titled “2.3 完整实现示例”import { OpenAI } from 'openai';
interface Tool { name: string; description: string; parameters: z.ZodSchema; execute: (params: any) => Promise<any>;}
class ReActAgent { private client: OpenAI; private tools: Map<string, Tool>; private maxIterations: number = 10;
constructor(tools: Tool[]) { this.client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); this.tools = new Map(tools.map(t => [t.name, t])); }
async run(task: string): Promise<string> { const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [ { role: 'system', content: this.buildSystemPrompt() }, { role: 'user', content: `任务:${task}` }, ];
for (let i = 0; i < this.maxIterations; i++) { const response = await this.client.chat.completions.create({ model: 'gpt-4', messages, temperature: 0.2, });
const content = response.choices[0].message.content!; messages.push({ role: 'assistant', content });
// 解析思考和行动 const thoughtMatch = content.match(/思考:(.+)/); const actionMatch = content.match(/行动:(.+)/); const finalAnswerMatch = content.match(/最终答案:(.+)/s);
if (finalAnswerMatch) { return finalAnswerMatch[1].trim(); }
if (actionMatch) { const actionStr = actionMatch[1].trim(); const toolResult = await this.executeAction(actionStr); messages.push({ role: 'user', content: `观察:${JSON.stringify(toolResult)}`, }); } }
throw new Error('达到最大迭代次数,任务未完成'); }
private buildSystemPrompt(): string { const toolDescriptions = Array.from(this.tools.values()) .map(t => `- ${t.name}: ${t.description}`) .join('\n');
return `你是一个轨道交通监测AI助手。可用工具:${toolDescriptions}
请按以下格式工作:思考:[分析当前情况]行动:[工具名[参数]] 或 最终答案:[答案]`; }
private async executeAction(actionStr: string): Promise<any> { const match = actionStr.match(/(\w+)\[(.*)\]/); if (!match) return { error: '无法解析行动' };
const [_, toolName, paramsStr] = match; const tool = this.tools.get(toolName); if (!tool) return { error: `未知工具: ${toolName}` };
try { const params = JSON.parse(`{${paramsStr}}`); return await tool.execute(params); } catch (e) { return { error: `执行失败: ${e.message}` }; } }}
// 使用示例const agent = new ReActAgent([ { name: 'query_measurement', description: '查询测点测量数据', parameters: z.object({ point_id: z.string(), limit: z.number().optional() }), execute: async (params) => { // 查询数据库 return await db.query('SELECT * FROM measurements WHERE point_id = ? LIMIT ?', [params.point_id, params.limit || 10]); }, }, { name: 'analyze_deformation', description: '分析测点变形', parameters: z.object({ point_id: z.string(), baseline: z.string() }), execute: async (params) => { // 调用分析服务 return await analysisService.analyze(params.point_id, params.baseline); }, },]);
const result = await agent.run('分析测点MP-01最近7天的变形趋势');3. Plan-and-Solve模式
Section titled “3. Plan-and-Solve模式”3.1 模式原理
Section titled “3.1 模式原理”Plan-and-Solve模式将任务分为两个阶段:先制定计划(Plan),再逐步执行(Solve)。适用于需要多步骤协作的复杂监测任务。
3.2 Prompt结构
Section titled “3.2 Prompt结构”const PLAN_AND_SOLVE_PROMPT = `你是一个轨道交通监测任务规划专家。你的工作是:
## 阶段1:制定计划分析用户任务,制定详细的执行计划。
计划格式:计划: 步骤1:[具体行动] - 依赖:[无/步骤X] - 负责:[Agent类型] 步骤2:[具体行动] - 依赖:[步骤1] - 负责:[Agent类型] …
## 阶段2:执行计划按步骤执行,每完成一步报告结果。
执行格式:执行步骤N: 行动:[具体行动] 结果:[执行结果] 状态:[完成/失败/部分完成]
## 阶段3:汇总结果所有步骤完成后,汇总输出最终结果。
最终格式:最终结果: [综合所有步骤结果的最终输出]
规则:- 每个步骤必须明确输入、输出和完成标准- 依赖步骤必须等待前置步骤完成- 遇到失败时尝试替代方案或报告错误- 保持步骤之间的数据一致性`;3.3 完整实现示例
Section titled “3.3 完整实现示例”interface PlanStep { id: number; description: string; dependencies: number[]; agent: string; status: 'pending' | 'running' | 'completed' | 'failed'; result?: any;}
class PlanAndSolveAgent { private planner: ReActAgent; private executors: Map<string, ReActAgent>;
async execute(task: string): Promise<any> { // 阶段1:制定计划 const plan = await this.createPlan(task); console.log('执行计划:', plan);
// 阶段2:执行计划 const results = await this.executePlan(plan);
// 阶段3:汇总结果 return this.summarizeResults(results); }
private async createPlan(task: string): Promise<PlanStep[]> { const planPrompt = `请为以下任务制定详细执行计划:
任务:${task}
可用Agent:- SurveyAgent: 测量数据处理、坐标计算- MonitorAgent: 变形分析、趋势判断- ReportAgent: 报告生成、图表制作- DataAgent: 数据查询、格式转换
要求:1. 每个步骤有明确的目标和输出2. 标注步骤间的依赖关系3. 指定最适合的Agent4. 考虑错误处理和回退方案
请输出JSON格式计划:{ "steps": [ { "id": 1, "description": "步骤描述", "dependencies": [], "agent": "Agent名称", "expected_output": "期望输出描述" } ]}`;
const response = await this.planner.run(planPrompt); return JSON.parse(response).steps; }
private async executePlan(plan: PlanStep[]): Promise<PlanStep[]> { const completed = new Set<number>(); const running = new Set<number>();
while (completed.size < plan.length) { // 找出可执行的步骤(依赖已完成) const readySteps = plan.filter( step => step.status === 'pending' && step.dependencies.every(dep => completed.has(dep)) && !running.has(step.id) );
if (readySteps.length === 0 && running.size === 0) { // 可能存在循环依赖或无法执行的步骤 const stuck = plan.filter(s => s.status === 'pending'); throw new Error(`计划执行卡住,未完成的步骤: ${stuck.map(s => s.id).join(', ')}`); }
// 并行执行就绪步骤 await Promise.all( readySteps.map(async step => { running.add(step.id); step.status = 'running';
try { const executor = this.executors.get(step.agent); if (!executor) throw new Error(`未知Agent: ${step.agent}`);
step.result = await executor.run(step.description); step.status = 'completed'; completed.add(step.id); } catch (error) { step.status = 'failed'; step.result = { error: error.message }; // 尝试回退或替代方案 await this.handleFailure(step, plan); } finally { running.delete(step.id); } }) ); }
return plan; }
private async handleFailure(failedStep: PlanStep, plan: PlanStep[]): Promise<void> { // 实现回退逻辑:尝试替代方案或通知协调器 console.warn(`步骤 ${failedStep.id} 失败:`, failedStep.result); // 可以在这里实现重试、替代方案选择等逻辑 }
private summarizeResults(plan: PlanStep[]): any { const summaryPrompt = `请汇总以下各步骤的执行结果,生成最终输出:
${plan.map(s => `步骤${s.id} (${s.agent}): ${JSON.stringify(s.result)}`).join('\n')}
要求:1. 综合所有步骤的关键信息2. 保持数据一致性3. 突出重要发现和结论4. 格式清晰、专业`;
return this.planner.run(summaryPrompt); }}4. Reflection模式
Section titled “4. Reflection模式”4.1 模式原理
Section titled “4.1 模式原理”Reflection模式让Agent在执行任务后进行自我反思,检查结果的准确性、完整性和一致性,并进行修正。
4.2 Prompt结构
Section titled “4.2 Prompt结构”const REFLECTION_PROMPT = `你是一个严谨的质量控制专家。在给出最终答案前,请先进行自我反思。
## 反思流程
### 第1步:结果检查检查你的答案是否满足以下要求:- [ ] 是否回答了用户的全部问题?- [ ] 数据是否准确?(重新验证关键数值)- [ ] 逻辑是否自洽?- [ ] 格式是否符合要求?- [ ] 是否遗漏了重要信息?
### 第2步:错误识别如果发现错误,请明确指出:- 错误类型:计算错误/逻辑错误/遗漏/格式错误- 错误位置:具体在哪一步- 错误影响:对结果的影响程度
### 第3步:修正方案提出修正方案:- 如何修正错误- 修正后的结果- 如何避免类似错误
### 第4步:最终输出输出修正后的最终答案。
## 反思格式反思: 检查项1:✓/✗ - 说明 检查项2:✓/✗ - 说明 …
发现的问题:
- [问题描述] - 严重程度:[高/中/低]
修正方案:
- [修正措施]
最终答案: [修正后的完整答案]
## 重要规则- 必须完成全部检查项才能输出最终答案- 发现任何错误都必须修正- 不确定的地方要标注"[需人工确认]"- 不要隐瞒错误,诚实报告问题`;4.3 完整实现示例
Section titled “4.3 完整实现示例”class ReflectionAgent { private baseAgent: ReActAgent; private reflectionRounds: number = 2;
async runWithReflection(task: string): Promise<{ finalAnswer: string; reflections: ReflectionRecord[]; corrections: CorrectionRecord[]; }> { const reflections: ReflectionRecord[] = []; const corrections: CorrectionRecord[] = [];
// 初始执行 let currentAnswer = await this.baseAgent.run(task);
// 多轮反思 for (let round = 1; round <= this.reflectionRounds; round++) { const reflection = await this.reflect(currentAnswer, task); reflections.push(reflection);
if (reflection.issues.length === 0) { break; // 无问题,提前结束 }
// 修正 const correction = await this.correct(currentAnswer, reflection); corrections.push(correction); currentAnswer = correction.correctedAnswer; }
return { finalAnswer: currentAnswer, reflections, corrections, }; }
private async reflect(answer: string, originalTask: string): Promise<ReflectionRecord> { const reflectPrompt = `请对以下答案进行质量检查:
原始任务:${originalTask}
当前答案:${answer}
请按以下维度检查:1. 完整性:是否回答了所有问题?2. 准确性:关键数据是否正确?3. 一致性:内部逻辑是否自洽?4. 专业性:术语使用是否准确?5. 格式:是否符合要求的格式?
输出JSON格式:{ "round": 1, "checks": [ {"dimension": "完整性", "passed": true/false, "comment": ""} ], "issues": [ {"severity": "high/medium/low", "description": "", "location": ""} ], "overall_quality": "excellent/good/fair/poor"}`;
const response = await this.baseAgent.run(reflectPrompt); return JSON.parse(response); }
private async correct( answer: string, reflection: ReflectionRecord ): Promise<CorrectionRecord> { const correctPrompt = `请修正以下答案中的问题:
当前答案:${answer}
发现的问题:${reflection.issues.map(i => `- [${i.severity}] ${i.description} (${i.location})`).join('\n')}
请输出修正后的完整答案,并说明修正内容。
输出JSON格式:{ "corrections_made": [ {"issue": "", "fix": "", "location": ""} ], "corrected_answer": "", "confidence_improvement": 0.0}`;
const response = await this.baseAgent.run(correctPrompt); return JSON.parse(response); }}
interface ReflectionRecord { round: number; checks: Array<{ dimension: string; passed: boolean; comment: string; }>; issues: Array<{ severity: 'high' | 'medium' | 'low'; description: string; location: string; }>; overall_quality: 'excellent' | 'good' | 'fair' | 'poor';}
interface CorrectionRecord { corrections_made: Array<{ issue: string; fix: string; location: string; }>; corrected_answer: string; confidence_improvement: number;}5. Multi-Agent Debate模式
Section titled “5. Multi-Agent Debate模式”5.1 模式原理
Section titled “5.1 模式原理”多个Agent从不同角度分析同一问题,通过辩论达成共识,提高决策质量。
5.2 Prompt结构
Section titled “5.2 Prompt结构”const DEBATE_SYSTEM_PROMPT = `你是一位{{role}}专家。你的任务是从{{perspective}}角度分析问题,并与其他专家进行辩论。
## 你的角色{{roleDescription}}
## 辩论规则1. 首先独立分析,给出你的专业观点2. 听取其他专家的观点,找出分歧点3. 针对分歧点进行论证,支持或反驳4. 最终尝试达成共识或明确保留意见
## 输出格式阶段1 - 独立分析:观点:[你的分析结论] 论据:[支持论据1, 论据2, …] 置信度:0-1
阶段2 - 辩论回应:对其他专家观点的回应:
- 同意:[同意的点]
- 反驳:[反驳的点及理由]
- 补充:[新的论据]
阶段3 - 共识/结论:最终立场:[同意/部分同意/保留意见] 共识点:[达成一致的内容] 分歧点:[未达成一致的内容] 建议:[下一步行动]
`;5.3 完整实现示例
Section titled “5.3 完整实现示例”interface DebateAgent { role: string; perspective: string; systemPrompt: string; agent: ReActAgent;}
class MultiAgentDebate { private agents: DebateAgent[]; private maxRounds: number = 3;
constructor(agents: DebateAgent[]) { this.agents = agents; }
async debate(topic: string, context: string): Promise<DebateResult> { const rounds: DebateRound[] = [];
// 第一轮:独立分析 const initialViews = await Promise.all( this.agents.map(async agent => ({ role: agent.role, view: await agent.agent.run(`主题:${topic}背景:${context}
请从${agent.perspective}角度进行独立分析,给出你的观点、论据和置信度。`), })) );
rounds.push({ round: 1, type: 'independent', views: initialViews });
// 后续轮次:辩论 let currentViews = initialViews; for (let round = 2; round <= this.maxRounds; round++) { const debatedViews = await Promise.all( this.agents.map(async (agent, idx) => { const otherViews = currentViews.filter((_, i) => i !== idx); const debatePrompt = `你的角色:${agent.role}你的观点:${currentViews[idx].view}
其他专家观点:${otherViews.map(v => `--- ${v.role} ---\n${v.view}`).join('\n\n')}
请针对其他专家的观点进行回应,指出同意和分歧点,并进行论证。`; return { role: agent.role, view: await agent.agent.run(debatePrompt), }; }) );
rounds.push({ round, type: 'debate', views: debatedViews }); currentViews = debatedViews;
// 检查是否达成共识 const consensus = this.checkConsensus(debatedViews); if (consensus.reached) break; }
// 最终汇总 return this.synthesizeResult(rounds); }
private checkConsensus(views: Array<{ role: string; view: string }>): { reached: boolean; agreementLevel: number; } { // 使用LLM判断共识程度 // 简化实现:检查观点相似度 const agreementLevel = 0.7; // 示例值 return { reached: agreementLevel > 0.8, agreementLevel, }; }
private synthesizeResult(rounds: DebateRound[]): DebateResult { // 汇总所有轮次的结果,生成最终结论 return { topic: '', rounds, finalConsensus: '', dissentingOpinions: [], confidence: 0, recommendedAction: '', }; }}
// 使用示例:监测异常原因分析const debate = new MultiAgentDebate([ { role: '测量技术专家', perspective: '测量精度与仪器', systemPrompt: '你专注于测量技术,关注仪器精度、观测误差、环境因素对数据的影响', agent: new ReActAgent([/* 测量工具 */]), }, { role: '结构工程师', perspective: '结构力学与变形', systemPrompt: '你专注于结构工程,关注荷载变化、结构响应、变形机理', agent: new ReActAgent([/* 结构分析工具 */]), }, { role: '施工管理专家', perspective: '施工工艺与进度', systemPrompt: '你专注于施工管理,关注施工工序、荷载施加、时间关联性', agent: new ReActAgent([/* 施工数据工具 */]), },]);
const result = await debate.debate( '测点MP-05出现异常加速变形的原因', '最近3期数据显示MP-05水平位移从1mm增至4mm,速率明显加快');6. Chain-of-Verification模式
Section titled “6. Chain-of-Verification模式”6.1 模式原理
Section titled “6.1 模式原理”生成答案后,自动构建验证问题并回答,通过交叉验证抑制幻觉。
6.2 Prompt结构
Section titled “6.2 Prompt结构”const COV_PROMPT = `你是一个严谨的验证专家。在输出最终答案前,你必须验证答案中的每个关键事实。
## 验证流程
### 第1步:生成验证问题从答案中提取关键事实,为每个事实生成验证问题。
格式:关键事实1:[事实陈述] 验证问题1:[如何验证这个事实?]
关键事实2:[事实陈述] 验证问题2:[如何验证这个事实?]
### 第2步:回答验证问题独立回答每个验证问题,不参考原始答案。
### 第3步:对比验证将验证结果与原始答案对比:- 一致:✓ 确认- 不一致:✗ 标记错误- 无法验证:? 标注不确定性
### 第4步:修正输出基于验证结果修正最终答案。
## 输出格式验证报告: 事实1:[原始陈述] - 验证结果:✓/✗/? - 修正:[如有] 事实2:[原始陈述] - 验证结果:✓/✗/? - 修正:[如有]
修正后答案: [最终输出]
不确定性说明: [无法验证的内容及原因]
`;7. Tool-Former模式
Section titled “7. Tool-Former模式”7.1 模式原理
Section titled “7.1 模式原理”Agent动态学习何时以及如何使用工具,通过示例和反馈优化工具选择策略。
7.2 Prompt结构
Section titled “7.2 Prompt结构”const TOOL_FORMER_PROMPT = `你是一个智能工具使用专家。你需要根据任务需求,选择最合适的工具组合。
## 工具库{{#each tools}}### {{name}}- 功能:{{description}}- 适用场景:{{scenarios}}- 输入:{{input}}- 输出:{{output}}- 成本:{{cost}}- 延迟:{{latency}}{{/each}}
## 工具选择策略1. 分析任务需求,识别需要的功能2. 评估各工具的适用性3. 考虑成本和延迟约束4. 选择最优工具组合5. 确定执行顺序
## 输出格式任务分析:
- 核心需求:[需求描述]
- 约束条件:[成本/延迟/精度要求]
工具选择:
- [工具名] - 原因:[为什么选这个工具]
- [工具名] - 原因:[为什么选这个工具]
执行计划: 步骤1:[工具名] - 输入:[参数] - 预期输出:[描述] 步骤2:[工具名] - 输入:[参数] - 依赖:[步骤1]
备选方案: 若[工具名]失败,使用[替代工具]
`;8. 模式组合策略
Section titled “8. 模式组合策略”8.1 推荐组合
Section titled “8.1 推荐组合”| 场景 | 推荐模式组合 | 说明 |
|---|---|---|
| 简单数据查询 | ReAct | 单步工具调用即可 |
| 复杂分析报告 | Plan-and-Solve + Reflection | 先规划再执行,最后反思 |
| 异常原因诊断 | Multi-Agent Debate | 多视角分析 |
| 重要决策支持 | Plan-and-Solve + Multi-Agent Debate + Reflection | 全面保障 |
| 实时监测响应 | ReAct + Tool-Former | 快速响应,动态选工具 |
| 报告生成 | Plan-and-Solve + Chain-of-Verification | 确保准确性 |
8.2 组合实现示例
Section titled “8.2 组合实现示例”class HybridAgent { private planner: PlanAndSolveAgent; private debater: MultiAgentDebate; private reflector: ReflectionAgent;
async executeComplexTask(task: string): Promise<any> { // 阶段1:规划 const plan = await this.planner.createPlan(task);
// 阶段2:执行(对关键步骤使用辩论) const results = await this.executeWithDebate(plan);
// 阶段3:反思 const reflected = await this.reflector.runWithReflection( JSON.stringify(results) );
return reflected; }
private async executeWithDebate(plan: PlanStep[]): Promise<any> { // 对关键决策点启动辩论 return plan.map(async step => { if (step.requiresDecision) { const debateResult = await this.debater.debate( step.description, step.context ); return { ...step, decision: debateResult.finalConsensus }; } return step; }); }}9. 最佳实践
Section titled “9. 最佳实践”9.1 模式选择决策树
Section titled “9.1 模式选择决策树”任务开始 │ ├─ 是否需要多步骤? │ ├─ 是 → Plan-and-Solve │ └─ 否 → ReAct │ ├─ 是否涉及重要决策? │ ├─ 是 → Multi-Agent Debate │ └─ 否 → 继续 │ ├─ 是否需要高可靠性? │ ├─ 是 → Reflection + Chain-of-Verification │ └─ 否 → 继续 │ ├─ 是否需要动态工具选择? │ ├─ 是 → Tool-Former │ └─ 否 → 基础模式9.2 性能优化
Section titled “9.2 性能优化”| 优化策略 | 适用模式 | 效果 |
|---|---|---|
| Prompt缓存 | 所有 | 减少延迟30-50% |
| 并行执行 | Plan-and-Solve | 缩短总时间40-60% |
| 提前终止 | Reflection | 无问题时节省50% tokens |
| 工具结果缓存 | ReAct | 减少重复调用 |
| 模型分层 | 所有 | 简单任务用轻量模型 |
10. 限制与注意事项
Section titled “10. 限制与注意事项”10.1 已知限制
Section titled “10.1 已知限制”- 模式组合增加延迟,实时场景需谨慎
- 多Agent辩论可能产生“群体思维”
- Reflection无法发现所有类型的错误
- 工具调用失败时的回退策略需要完善
10.2 安全注意事项
Section titled “10.2 安全注意事项”⚠️ 警告
- 涉及安全关键决策时,必须人工复核Agent输出
- 多Agent辩论不能替代专家评审
- 定期审计Agent决策日志
- 设置最大迭代次数和token预算,防止无限循环
11. 常见问题
Section titled “11. 常见问题”Q: 如何选择合适的Prompt模式?
A: 参考第9.1节的决策树。基本原则:简单任务用ReAct,复杂任务用Plan-and-Solve,重要决策加Debate,高可靠性要求加Reflection。
Q: 多Agent系统的延迟如何优化?
A: 使用并行执行、Prompt缓存、工具结果缓存、模型分层(简单任务用小模型)。详见第9.2节。
Q: 如何防止Agent幻觉?
A: 使用Chain-of-Verification模式,强制结构化输出,结合工具验证,设置人工复核节点。
Q: 支持自定义模式吗?
A: 支持。可以通过组合基础模式或定义新的System Prompt来实现自定义模式。详见RAILWISE-CLI开发指南。
12. 相关文档
Section titled “12. 相关文档”- Prompt工程指南 — Prompt设计原则与优化
- Prompt模板库 — 预置模板集合
- RAILWISE-CLI开发指南 — CLI工具开发
- MCP Server概述 — MCP工具集成
13. 更新日志
Section titled “13. 更新日志”| 版本 | 日期 | 变更内容 |
|---|---|---|
| 1.0.0 | 2026-07-08 | 初始版本,包含6种核心Prompt模式及实现示例 |
本文档由RailWise技术团队维护,如有疑问请联系技术支持:support@railwise.cn
