Sfoglia il codice sorgente

整理execution_record

TanJingyu 8 ore fa
parent
commit
2a61fe5cad
1 ha cambiato i file con 21 aggiunte e 1 eliminazioni
  1. 21 1
      knowledge_v2/function_knowledge.py

+ 21 - 1
knowledge_v2/function_knowledge.py

@@ -209,7 +209,8 @@ class FunctionKnowledge:
             # 加载prompt
             prompt_template = self._load_prompt("function_knowledge_extract_tool_params_prompt.md")
             prompt = prompt_template.format(
-                query=query,
+                tool_mcp_name=tool_id,
+                tool_instructions=tool_instructions,
                 all_tool_params=tool_params
             )
 
@@ -294,6 +295,24 @@ class FunctionKnowledge:
         except Exception as e:
             logger.error(f"✗ 保存知识失败: {e}")
 
+    def organize_tool_result(self, tool_result: dict) -> dict:
+        """
+        组织工具调用结果,确保包含必要字段
+
+        Args:
+            tool_result: 原始工具调用结果
+
+        Returns:
+            dict: 组织后的工具调用结果
+        """
+        prompt_template = self._load_prompt("tool_result_prettify_prompt.md")
+        prompt = prompt_template.format(
+            input=tool_result,
+        )
+        organized_result = generate_text(prompt=prompt)
+        organized_result = organized_result.strip()
+        return organized_result
+
     def get_knowledge(self, question: str, post_info: str, persona_info: str) -> dict:
         """
         获取方法知识的主流程(重构后)
@@ -341,6 +360,7 @@ class FunctionKnowledge:
                     else:
                         logger.info(f"  → 调用工具,参数: {arguments}")
                         tool_result = call_tool(tool_id, arguments)
+                        tool_result = self.organize_tool_result(tool_result)
                         # 保存工具调用信息(包含工具名、入参、结果)
                         tool_call_data = {
                             "tool_name": tool_id,