config.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. """
  2. Agent skill 共享配置
  3. =====================
  4. 这是 /Users/sunlit/.claude/skills/agent/ 的本地 agent 运行配置,所有项目共用。
  5. 如果某个项目需要不同的 RUN_CONFIG / presets / tools,在那个项目里放一份自己的
  6. config.py 并显式传 `--project_root=<项目目录>`,CLI 会用项目 config 覆盖这份默认。
  7. 字段来源:
  8. - RunConfig → agent/core/runner.py:97
  9. - KnowledgeConfig → agent/tools/builtin/knowledge.py:26
  10. - MemoryConfig → agent/core/memory.py(可选,默认 None = 无长期记忆)
  11. - FileSystemTraceStore(base_path=TRACE_STORE_PATH) → agent/trace/store.py:36
  12. 调用方式:
  13. python invoke.py --agent_type=<type> --task="..." # 自动使用本 config
  14. python invoke.py --agent_type=<type> --task="..." \
  15. --project_root=/path/to/project # 改用项目 config
  16. 注:CLI 传入的 --agent_type / --skills / --continue_from 会在加载 config 后
  17. 覆盖 RUN_CONFIG 的对应字段(见 agent/client.py:172-176)。
  18. """
  19. import os
  20. from pathlib import Path
  21. from agent.core.runner import RunConfig
  22. from agent.tools.builtin.knowledge import KnowledgeConfig
  23. # 如果需要 memory-bearing agent,取消下一行注释:
  24. # from agent.core.memory import MemoryConfig
  25. # =============================================================================
  26. # Agent 运行配置(RUN_CONFIG)
  27. # =============================================================================
  28. # 所有字段都有默认值。仅列出"值得关注或常被调"的字段;完整字段见 runner.py:97。
  29. # agent_type / skills / trace_id 会被 CLI 覆盖,这里写什么都行(留占位符即可)。
  30. RUN_CONFIG = RunConfig(
  31. # --- 模型层 -------------------------------------------------------------
  32. model="qwen3.5-plus", # LLM 模型名。常用:"gpt-4o" / "qwen3.5-plus" / "claude-sonnet-4-6"
  33. temperature=0.3, # 采样温度。调研/规划建议 0.3;创意任务可升到 0.7
  34. max_iterations=1000, # 单次 run 的最大工具调用轮数。远端 agent 一般够用,复杂本地任务可调大
  35. # 传给 LLM 的额外参数(OpenAI SDK kwargs)。
  36. # 常用例子:阿里 Qwen 的 thinking 模式、Claude 的 thinking budget。
  37. extra_llm_params={
  38. "extra_body": {"enable_thinking": True}, # 启用 Qwen thinking(仅对 qwen 生效,其他模型忽略)
  39. },
  40. # --- 工具选择 -----------------------------------------------------------
  41. # tools=None 时按 tool_groups 白名单过滤;显式列 tool name 则精确指定。
  42. tools=None,
  43. tool_groups=["core"], # 只开核心工具组;需要 knowledge/browser 工具时加 "knowledge" / "browser"
  44. exclude_tools=[], # 即使在 groups 里命中,也从最终集合里剔除的工具名
  45. # --- 框架层 -------------------------------------------------------------
  46. agent_type="default", # 被 CLI --agent_type 覆盖,这里写啥都行
  47. skills=None, # 被 CLI --skills 覆盖;None 时按 preset 决定 skill 注入
  48. name=None, # Trace 显示名。None 让 utility_llm 基于 task 自动生成
  49. enable_memory=True, # 是否把 goal tree / collaborators 周期性注入(每 5 轮)
  50. auto_execute_tools=True, # False 则每个 tool call 需外部确认后才执行(人工审核场景)
  51. enable_prompt_caching=True, # Anthropic prompt caching,仅 Claude 模型有效
  52. # --- Goal / 压缩 --------------------------------------------------------
  53. goal_compression="on_overflow", # "none" | "on_complete" | "on_overflow";on_overflow 最省 token
  54. side_branch_max_turns=5, # 压缩/反思等侧分支的最大轮数
  55. # --- Trace 续跑控制 -----------------------------------------------------
  56. trace_id=None, # 被 CLI --continue_from 覆盖。None = 新 trace
  57. parent_trace_id=None, # 子 agent 调用时由上游注入,人工一般不填
  58. parent_goal_id=None,
  59. after_sequence=None, # 指定从哪条 message sequence 后续跑(回溯重跑)
  60. # --- 研究流程 -----------------------------------------------------------
  61. # True = 自动跑"知识检索 → 经验检索 → 调研 → 计划"前置流程;
  62. # 如果 agent 本身就是 research 性质,关掉避免双重调研。
  63. enable_research_flow=True,
  64. # --- 知识管理(KnowledgeConfig,详见 knowledge.py:26)-------------------
  65. knowledge=KnowledgeConfig(
  66. # 压缩触发时的反思提取
  67. enable_extraction=False, # True 在压缩时反思并落知识库
  68. reflect_prompt="", # 自定义 prompt,空则用默认 REFLECT_PROMPT
  69. reflect_auto_commit=False, # True 自动提交反思产物(风险:知识库污染)
  70. # 运行完成后的复盘提取
  71. enable_completion_extraction=False, # True 在 agent 结束时复盘
  72. completion_reflect_prompt="",
  73. # 知识注入(focus goal 时自动拉相关知识进 context)
  74. enable_injection=False,
  75. # 默认字段(保存/搜索时自动带上)
  76. owner="sunlit.howard@gmail.com", # 空则 fallback 到 git user.email 再到 agent:{agent_id}
  77. default_tags={}, # 例如 {"project": "xyz", "domain": "ai_agent"}
  78. default_scopes=["org:cybertogether"],
  79. default_search_types=None, # 搜索时默认的 type 过滤,如 ["strategy"]
  80. default_search_owner="", # 空 = 不按 owner 过滤
  81. ),
  82. # --- Memory(长期记忆,可选)-------------------------------------------
  83. # None = 无长期记忆。若要启用:
  84. # from agent.core.memory import MemoryConfig
  85. # memory=MemoryConfig(...) # 详见 agent/docs/memory.md
  86. memory=None,
  87. # --- 额外上下文(自定义元数据,透传给工具) -----------------------------
  88. context={},
  89. )
  90. # =============================================================================
  91. # 基础设施路径
  92. # =============================================================================
  93. # --- Trace 存储 -------------------------------------------------------------
  94. # 锚在**调用方 CWD**,每个项目有独立的 trace 目录。
  95. # 用绝对路径是为了绕过 client.py:203-204 的 "非绝对路径 → rebase 到 project_root" 逻辑。
  96. # 如果想所有项目共享一个 trace 目录,把它改成任意绝对路径即可(如 Path.home() / ".agent_trace")。
  97. _CALLER_CWD = Path(os.getcwd()).resolve()
  98. _TRACE_DIR = _CALLER_CWD / ".cache" / "trace"
  99. # FileSystemTraceStore 只做 mkdir(exist_ok=True) 不带 parents,这里预先兜底创建父目录。
  100. _TRACE_DIR.mkdir(parents=True, exist_ok=True)
  101. TRACE_STORE_PATH = str(_TRACE_DIR)
  102. # --- Skills 目录 ------------------------------------------------------------
  103. # agent 会从这里加载 @skill 声明的技能定义。默认指向本 skill 目录本身,
  104. # 空着也没关系(SDK 容错);有自定义 skill 时把路径改到放 skill 的目录。
  105. SKILLS_DIR = str(Path(__file__).resolve().parent)
  106. # =============================================================================
  107. # 日志 / 调试
  108. # =============================================================================
  109. DEBUG = False # True 会打开更多调试输出(SDK 自己读这个标志)
  110. LOG_LEVEL = "INFO" # "DEBUG" / "INFO" / "WARNING" / "ERROR"
  111. LOG_FILE = None # 设置为文件路径可同时输出到文件,None = 仅 stderr
  112. # =============================================================================
  113. # 浏览器配置(仅当启用 browser 工具组时生效)
  114. # =============================================================================
  115. # 使用场景:agent 需要访问网页(搜索、抓取、登录等)。不用时这段可忽略。
  116. BROWSER_TYPE = "local" # "local"(本地 Chrome)/ "cloud"(云端)/ "container"(容器内账户)
  117. HEADLESS = False # True 无头(CI / 服务器);False 有界面(本地调试观察)