""" Agent Presets - Agent 类型预设配置 定义不同类型 Agent 的工具权限和运行参数。 用户可通过 .agent/presets.json 覆盖或添加预设。 """ from dataclasses import dataclass, field from typing import Optional, List @dataclass class AgentPreset: """Agent 预设配置""" # 工具权限 allowed_tools: Optional[List[str]] = None # None 表示允许全部 denied_tools: Optional[List[str]] = None # 黑名单 # 运行参数 max_iterations: int = 30 temperature: Optional[float] = None # Skills(注入 system prompt 的 skill 名称列表;None = 加载全部) skills: Optional[List[str]] = None # 描述 description: Optional[str] = None # 内置预设 _DEFAULT_SKILLS = ["planning", "research", "browser"] AGENT_PRESETS = { "default": AgentPreset( allowed_tools=None, max_iterations=30, skills=_DEFAULT_SKILLS, description="默认 Agent,拥有全部工具权限", ), "delegate": AgentPreset( allowed_tools=None, max_iterations=30, skills=_DEFAULT_SKILLS, description="委托子 Agent,拥有全部工具权限(由 agent 工具创建)", ), "explore": AgentPreset( allowed_tools=["read", "glob", "grep", "list_files"], denied_tools=["write", "edit", "bash", "task"], max_iterations=15, skills=["planning"], description="探索型 Agent,只读权限,用于代码分析", ), "evaluate": AgentPreset( allowed_tools=["read_file", "grep_content", "glob_files", "goal"], max_iterations=10, skills=["planning"], description="评估型 Agent,只读权限,用于结果评估", ), } def get_preset(name: str) -> AgentPreset: """获取预设配置""" if name not in AGENT_PRESETS: raise ValueError(f"Unknown preset: {name}. Available: {list(AGENT_PRESETS.keys())}") return AGENT_PRESETS[name] def register_preset(name: str, preset: AgentPreset) -> None: """注册自定义预设""" AGENT_PRESETS[name] = preset