@saber2pr/ai-agent 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/agent-chain.js +39 -11
  2. package/package.json +1 -1
@@ -204,19 +204,34 @@ class McpChainAgent {
204
204
  const prompt = prompts_1.PromptTemplate.fromTemplate(`
205
205
  {system_prompt}
206
206
 
207
- TOOLS:
208
- ------
209
- You can use the following tools:
207
+ ### 🛠 可用工具列表 (TOOLS)
208
+ --------------------
210
209
  {tools}
211
210
 
212
- To use a tool, please use the following format:
213
- Thought: Do I need to use a tool? Yes
214
- Action: the action to take, should be one of [{tool_names}]
215
- Action Input: the input to the action (JSON format)
216
- Observation: the result of the action
217
- ... (repeat N times)
218
- Thought: I now know the final answer
219
- Final Answer: the final answer to the original input question
211
+ ### 📝 交互协议格式 (PROTOCOL)
212
+ --------------------
213
+ 为了确保任务成功,你必须【严格】遵守以下 ReAct 交互格式:
214
+
215
+ 1. **思考与行动阶段 (Thought & Action)**:
216
+ Thought: 我需要执行什么操作?
217
+ Action: 工具名称 (必须是 [{tool_names}] 之一)
218
+ Action Input: 工具的 JSON 参数 (例如: {{"filePath": "src/index.ts"}})
219
+
220
+ 【⚠️ 极其重要】:当你输出 "Action Input" 后,必须【立即停止】输出,静静等待 Observation(工具返回结果)。严禁在此阶段输出 "Final Answer"。
221
+
222
+ 2. **反馈阶段 (Observation)**:
223
+ Observation: 工具返回的真实数据。
224
+
225
+ 3. **最终结论阶段 (Final Answer)**:
226
+ 当且仅当你已经从工具中获得了足够信息并完成所有审计任务时:
227
+ Thought: 我已经完成了所有分析,可以生成最终报告。
228
+ Final Answer: 任务总结陈述。
229
+
230
+ ### 🚫 强制禁止行为 (STRICT PROHIBITIONS)
231
+ --------------------
232
+ - **严禁虚构**:禁止使用 'path/to/file' 等占位符,必须使用 'get_repo_map' 返回的真实路径。
233
+ - **严禁冲突**:严禁在同一次回复中同时出现 "Action" 和 "Final Answer"。
234
+ - **严禁对话**:不要向用户提问或进行闲聊,你的唯一目标是完成审计并调用 'generate_review'。
220
235
 
221
236
  Begin!
222
237
  Question: {input}
@@ -242,6 +257,19 @@ Thought: {agent_scratchpad}`);
242
257
  const response = await this.executor.invoke({
243
258
  input: input,
244
259
  system_prompt: this.messages[0].content,
260
+ }, {
261
+ // --- 新增:使用回调函数捕获 Thought ---
262
+ callbacks: [{
263
+ handleAgentAction: (action, runId) => {
264
+ // 在 ReAct Agent 中,thought 通常包含在 log 字段中,且在 Action 之前
265
+ if (action.log) {
266
+ const thought = action.log.split('Action:')[0].trim();
267
+ if (thought) {
268
+ console.log(`\n💭 [思考]: ${thought.replace('Thought:', '').trim()}`);
269
+ }
270
+ }
271
+ }
272
+ }]
245
273
  });
246
274
  let output = response.output;
247
275
  // 清洗 ReAct 冗余标签
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saber2pr/ai-agent",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "AI Assistant CLI.",
5
5
  "author": "saber2pr",
6
6
  "license": "ISC",