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