|
@@ -113,8 +113,6 @@ class RunConfig:
|
|
|
|
|
|
|
|
# --- 框架层参数 ---
|
|
# --- 框架层参数 ---
|
|
|
agent_type: str = "default"
|
|
agent_type: str = "default"
|
|
|
- # Agent 实例标识(用于知识 owner 兜底);为空时回退到 uid
|
|
|
|
|
- agent_id: Optional[str] = None
|
|
|
|
|
uid: Optional[str] = None
|
|
uid: Optional[str] = None
|
|
|
system_prompt: Optional[str] = None # None = 从 skills 自动构建
|
|
system_prompt: Optional[str] = None # None = 从 skills 自动构建
|
|
|
skills: Optional[List[str]] = None # 注入 system prompt 的 skill 名称列表;None = 按 preset 决定
|
|
skills: Optional[List[str]] = None # 注入 system prompt 的 skill 名称列表;None = 按 preset 决定
|
|
@@ -1109,7 +1107,6 @@ class AgentRunner:
|
|
|
|
|
|
|
|
if not has_context_call:
|
|
if not has_context_call:
|
|
|
# 手动添加 get_current_context 工具调用
|
|
# 手动添加 get_current_context 工具调用
|
|
|
- import uuid
|
|
|
|
|
context_call_id = f"call_context_{uuid.uuid4().hex[:8]}"
|
|
context_call_id = f"call_context_{uuid.uuid4().hex[:8]}"
|
|
|
tool_calls.append({
|
|
tool_calls.append({
|
|
|
"id": context_call_id,
|
|
"id": context_call_id,
|
|
@@ -1346,23 +1343,6 @@ class AgentRunner:
|
|
|
elif tool_args is None:
|
|
elif tool_args is None:
|
|
|
tool_args = {}
|
|
tool_args = {}
|
|
|
|
|
|
|
|
- # 注入知识管理工具的默认字段
|
|
|
|
|
- if tool_name == "knowledge_save":
|
|
|
|
|
- run_agent_id = config.agent_id or config.uid or "agent"
|
|
|
|
|
- tool_args.setdefault("owner", config.knowledge.get_owner(run_agent_id))
|
|
|
|
|
- if config.knowledge.default_tags:
|
|
|
|
|
- existing_tags = tool_args.get("tags") or {}
|
|
|
|
|
- merged_tags = {**config.knowledge.default_tags, **existing_tags}
|
|
|
|
|
- tool_args["tags"] = merged_tags
|
|
|
|
|
- if config.knowledge.default_scopes:
|
|
|
|
|
- existing_scopes = tool_args.get("scopes") or []
|
|
|
|
|
- tool_args["scopes"] = existing_scopes + config.knowledge.default_scopes
|
|
|
|
|
- elif tool_name == "knowledge_search":
|
|
|
|
|
- if config.knowledge.default_search_types and "types" not in tool_args:
|
|
|
|
|
- tool_args["types"] = config.knowledge.default_search_types
|
|
|
|
|
- if config.knowledge.default_search_owner and "owner" not in tool_args:
|
|
|
|
|
- tool_args["owner"] = config.knowledge.default_search_owner
|
|
|
|
|
-
|
|
|
|
|
# 记录工具调用(INFO 级别,显示参数)
|
|
# 记录工具调用(INFO 级别,显示参数)
|
|
|
args_str = json.dumps(tool_args, ensure_ascii=False)
|
|
args_str = json.dumps(tool_args, ensure_ascii=False)
|
|
|
args_display = args_str[:100] + "..." if len(args_str) > 100 else args_str
|
|
args_display = args_str[:100] + "..." if len(args_str) > 100 else args_str
|
|
@@ -1593,69 +1573,7 @@ class AgentRunner:
|
|
|
preview = str(content)
|
|
preview = str(content)
|
|
|
logger.info(f" {label}后[{idx}] {role}: {preview}")
|
|
logger.info(f" {label}后[{idx}] {role}: {preview}")
|
|
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
|
return new_history
|
|
return new_history
|
|
|
-=======
|
|
|
|
|
- tool_calls = reflect_result.get("tool_calls") or []
|
|
|
|
|
- if not tool_calls:
|
|
|
|
|
- logger.info("反思阶段无经验保存 (source=%s)", source_name)
|
|
|
|
|
- return
|
|
|
|
|
-
|
|
|
|
|
- saved_count = 0
|
|
|
|
|
- for tc in tool_calls:
|
|
|
|
|
- tool_name = tc.get("function", {}).get("name")
|
|
|
|
|
- if tool_name != "knowledge_save":
|
|
|
|
|
- continue
|
|
|
|
|
-
|
|
|
|
|
- tool_args = tc.get("function", {}).get("arguments") or {}
|
|
|
|
|
- if isinstance(tool_args, str):
|
|
|
|
|
- tool_args = json.loads(tool_args) if tool_args.strip() else {}
|
|
|
|
|
-
|
|
|
|
|
- # 注入来源信息(LLM 不需要填写这些字段)
|
|
|
|
|
- tool_args.setdefault("source_name", source_name)
|
|
|
|
|
- tool_args.setdefault("source_category", "exp")
|
|
|
|
|
- tool_args.setdefault("message_id", trace_id)
|
|
|
|
|
-
|
|
|
|
|
- # 注入知识管理默认字段
|
|
|
|
|
- run_agent_id = config.agent_id or config.uid or "agent"
|
|
|
|
|
- tool_args.setdefault("owner", config.knowledge.get_owner(run_agent_id))
|
|
|
|
|
- if config.knowledge.default_tags:
|
|
|
|
|
- existing_tags = tool_args.get("tags") or {}
|
|
|
|
|
- merged_tags = {**config.knowledge.default_tags, **existing_tags}
|
|
|
|
|
- tool_args["tags"] = merged_tags
|
|
|
|
|
- if config.knowledge.default_scopes:
|
|
|
|
|
- tool_args.setdefault("scopes", config.knowledge.default_scopes)
|
|
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- await self.tools.execute(
|
|
|
|
|
- "knowledge_save",
|
|
|
|
|
- tool_args,
|
|
|
|
|
- uid=config.uid or "",
|
|
|
|
|
- context={"store": self.trace_store, "trace_id": trace_id},
|
|
|
|
|
- )
|
|
|
|
|
- saved_count += 1
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- logger.warning("保存经验失败: %s", e)
|
|
|
|
|
-
|
|
|
|
|
- logger.info("已提取并保存 %d 条经验 (source=%s)", saved_count, source_name)
|
|
|
|
|
-
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- logger.error("知识反思提取失败 (source=%s): %s", source_name, e)
|
|
|
|
|
-
|
|
|
|
|
- async def _extract_knowledge_on_completion(
|
|
|
|
|
- self,
|
|
|
|
|
- trace_id: str,
|
|
|
|
|
- history: List[Dict],
|
|
|
|
|
- config: RunConfig,
|
|
|
|
|
- ) -> None:
|
|
|
|
|
- """任务完成后执行全局复盘,提取经验保存到知识库。"""
|
|
|
|
|
- logger.info("任务完成后复盘提取: trace=%s", trace_id)
|
|
|
|
|
- await self._run_reflect(
|
|
|
|
|
- trace_id, history, config,
|
|
|
|
|
- reflect_prompt=config.knowledge.get_completion_reflect_prompt(),
|
|
|
|
|
- source_name="completion_reflection",
|
|
|
|
|
- )
|
|
|
|
|
->>>>>>> 0a8d3f1 (修改远程库地址和新流程)
|
|
|
|
|
|
|
|
|
|
# ===== 回溯(Rewind)=====
|
|
# ===== 回溯(Rewind)=====
|
|
|
|
|
|
|
@@ -1906,7 +1824,8 @@ class AgentRunner:
|
|
|
goal_tree: Optional[GoalTree],
|
|
goal_tree: Optional[GoalTree],
|
|
|
) -> str:
|
|
) -> str:
|
|
|
"""构建周期性注入的上下文(GoalTree + Active Collaborators + Focus 提醒)"""
|
|
"""构建周期性注入的上下文(GoalTree + Active Collaborators + Focus 提醒)"""
|
|
|
- parts = []
|
|
|
|
|
|
|
+ from datetime import datetime
|
|
|
|
|
+ parts = [f"## Current Time\n\n{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"]
|
|
|
|
|
|
|
|
# GoalTree
|
|
# GoalTree
|
|
|
if goal_tree and goal_tree.goals:
|
|
if goal_tree and goal_tree.goals:
|