1"""

2 AgentOS v0.30 Agent技能市场 — 可复用的Agent技能模板。

3 预置24个专业Agent技能。

4"""

5

6 from dataclasses import dataclass, field

7 from enum import Enum

8 from typing import Optional

9

10

11 class AgentCategory(str, Enum):

12

13 """Agent 分类。"""

14

15 CODE = "code"

16 DATA = "data"

17 SECURITY = "security"

18 WRITING = "writing"

19 ANALYSIS = "analysis"

20 AUTOMATION = "automation"

21 CREATIVE = "creative"

22 DEVOPS = "devops"

23

24

25@dataclass

26 class AgentSkill:

27 """Agent 技能定义。"""

28 name: str

29 category: AgentCategory

30 description: str

31 system_prompt: str

32 tools: list[str] = field(default_factory=list)

33 model_preference: str = "auto"

34 tags: list[str] = field(default_factory=list)

35 version: str = "1.0.0"

36 author: str = "AgentOS"

37

38

39 class AgentMarket:

40 """v0.30 Agent技能市场 — 24个预置技能。"""

41

42 def __init__(self):

43 self._skills: dict[str, AgentSkill] = {}

44 self._register_defaults()

45

46 def _register_defaults(self):

47 skills = [

48 # CODE (6)

49 AgentSkill("code-reviewer", AgentCategory.CODE, "代码审查，发现bug/安全漏洞/风格问题",

50 "你是一个资深代码审查员。审查代码的：1)逻辑错误 2)安全漏洞 3)性能问题 4)代码风格。输出结构化报告。",

51 ["read_text", "write_file", "shell_executor"], "kimi-k2.6", ["code", "review", "quality"]),

52 AgentSkill("architect", AgentCategory.CODE, "软件架构设计，系统拆分、技术选型",

53 "你是一个软件架构师。设计可扩展、高性能的系统架构。输出架构图(ASCII)+关键决策+技术栈推荐。",

54 ["read_text", "web_search"], "deepseek-r1", ["architecture", "design", "system"]),

55 AgentSkill("refactor-expert", AgentCategory.CODE, "代码重构，提升可读性和性能",

56 "你是一个重构专家。重构代码：1)提取方法 2)消除重复 3)优化数据结构 4)保持向后兼容。",

57 ["read_text", "write_file", "edit_file", "shell_executor"], "kimi-k2.6", ["refactor", "clean-code"]),

58 AgentSkill("test-generator", AgentCategory.CODE, "自动生成单元测试/集成测试",

59 "你是一个测试工程师。为给定代码生成全面的测试用例：1)边界条件 2)异常路径 3)Mock外部依赖。",

60 ["read_text", "write_file", "shell_executor"], "deepseek-v3.1", ["testing", "pytest"]),

61 AgentSkill("debug-helper", AgentCategory.CODE, "调试助手，分析错误日志定位根因",

62 "你是一个调试专家。分析错误栈/日志，定位根因，给出修复方案。",

63 ["read_text", "shell_executor"], "deepseek-r1", ["debug", "troubleshoot"]),

64 AgentSkill("doc-generator", AgentCategory.CODE, "API文档/README自动生成",

65 "你是一个文档工程师。从代码生成清晰的API文档、README、使用示例。",

66 ["read_text", "write_file"], "deepseek-v3.1", ["docs", "api"]),

67

68 # DATA (4)

69 AgentSkill("data-analyst", AgentCategory.DATA, "数据分析，统计/可视化/洞察",

70 "你是一个数据分析师。分析数据：1)描述性统计 2)趋势发现 3)异常检测 4)可视化建议。",

71 ["python_executor", "read_text", "write_file"], "deepseek-r1", ["data", "analytics"]),

72 AgentSkill("sql-master", AgentCategory.DATA, "SQL查询优化/数据库设计",

73 "你是一个数据库专家。编写高效SQL、设计表结构、优化查询性能。",

74 ["python_executor", "read_text"], "deepseek-v3.1", ["sql", "database"]),

75 AgentSkill("etl-engineer", AgentCategory.DATA, "数据清洗/ETL管道构建",

76 "你是一个数据工程师。构建可靠的数据管道：抽取-转换-加载。处理脏数据、格式转换。",

77 ["python_executor", "read_text", "write_file", "shell_executor"], "kimi-k2.6", ["etl", "pipeline"]),

78 AgentSkill("ml-consultant", AgentCategory.DATA, "机器学习方案咨询，特征工程建议",

79 "你是一个ML顾问。推荐合适的模型、特征工程策略、评估指标。",

80 ["web_search", "python_executor"], "deepseek-r1", ["ml", "ai"]),

81

82 # SECURITY (3)

83 AgentSkill("security-auditor", AgentCategory.SECURITY, "安全审计，OWASP Top 10检查",

84 "你是一个安全审计员。检查：1)注入攻击 2)认证缺陷 3)敏感数据暴露 4)XXE 5)访问控制。",

85 ["read_text", "shell_executor"], "deepseek-r1", ["security", "audit"]),

86 AgentSkill("pentest-advisor", AgentCategory.SECURITY, "渗透测试建议，漏洞利用分析",

87 "你是一个渗透测试顾问。分析系统弱点，提供测试向量。仅用于授权测试。",

88 ["shell_executor", "web_search"], "deepseek-r1", ["pentest", "vulnerability"]),

89 AgentSkill("crypto-reviewer", AgentCategory.SECURITY, "密码学实现审查",

90 "你是一个密码学专家。审查加密实现：算法选择、密钥管理、随机数生成。",

91 ["read_text"], "deepseek-r1", ["crypto", "encryption"]),

92

93 # WRITING (3)

94 AgentSkill("technical-writer", AgentCategory.WRITING, "技术文章/博客/白皮书撰写",

95 "你是一个技术写作专家。撰写清晰、准确的技术文档：白皮书、技术博客、教程。",

96 ["web_search", "write_file"], "kimi-k2.6", ["writing", "blog"]),

97 AgentSkill("spec-writer", AgentCategory.WRITING, "PRD/技术规格文档撰写",

98 "你是一个产品规格撰写人。输出结构化PRD：背景、目标、用户故事、验收标准、非功能需求。",

99 ["web_search", "write_file"], "deepseek-v3.1", ["prd", "specification"]),

100 AgentSkill("translator-pro", AgentCategory.WRITING, "专业文档翻译（中英互译+技术术语准确）",

101 "你是一个专业翻译。翻译技术文档，保持术语一致性，保留代码片段和格式。",

102 ["read_text", "write_file"], "deepseek-v3.1", ["translate", "i18n"]),

103

104 # ANALYSIS (3)

105 AgentSkill("competitor-analyst", AgentCategory.ANALYSIS, "竞品分析，SWOT/五力模型",

106 "你是一个竞品分析师。输出SWOT分析、功能对比矩阵、市场定位分析。",

107 ["web_search", "write_file"], "deepseek-r1", ["competitive", "market"]),

108 AgentSkill("decision-analyst", AgentCategory.ANALYSIS, "决策分析，多维度权衡/决策矩阵",

109 "你是一个决策分析师。构建决策矩阵：列出选项、加权维度、敏感性分析。",

110 ["write_file"], "deepseek-r1", ["decision", "tradeoff"]),

111 AgentSkill("trend-watcher", AgentCategory.ANALYSIS, "技术趋势追踪，科技前沿洞察",

112 "你是一个趋势分析师。追踪技术趋势：1)论文解读 2)开源项目热度 3)行业动态。",

113 ["web_search", "web_fetch", "write_file"], "kimi-k2.6", ["trends", "research"]),

114

115 # AUTOMATION (2)

116 AgentSkill("workflow-designer", AgentCategory.AUTOMATION, "工作流自动化方案设计",

117 "你是一个自动化专家。设计端到端工作流：触发器→步骤→错误处理→通知。",

118 ["write_file"], "kimi-k2.6", ["workflow", "automation"]),

119 AgentSkill("script-writer", AgentCategory.AUTOMATION, "Shell/Python运维脚本编写",

120 "你是一个脚本专家。编写健壮的自动化脚本：错误处理、日志、幂等性。",

121 ["shell_executor", "python_executor", "write_file"], "kimi-k2.6", ["script", "ops"]),

122

123 # CREATIVE (2)

124 AgentSkill("canvas-designer", AgentCategory.CREATIVE, "视觉设计/海报/Logo生成",

125 "调用canvas-design skill进行视觉创作。",

126 ["use_skill", "write_file"], "deepseek-v3.1", ["design", "visual"]),

127 AgentSkill("frontend-builder", AgentCategory.CREATIVE, "前端界面/Web页面构建",

128 "调用frontend-design skill构建生产级界面。",

129 ["use_skill", "write_file"], "kimi-k2.6", ["frontend", "ui"]),

130

131 # DEVOPS (1)

132 AgentSkill("devops-architect", AgentCategory.DEVOPS, "CI/CD/容器化/监控方案",

133 "你是一个DevOps架构师。设计：1)CI/CD Pipeline 2)容器编排 3)监控告警 4)日志聚合。",

134 ["shell_executor", "write_file", "web_search"], "kimi-k2.6", ["devops", "cloud"]),

135 ]

136 for s in skills:

137 self._skills[s.name] = s

138

139 @property

140 def skills(self) -> dict[str, AgentSkill]:

141 return dict(self._skills)

142

143 def get(self, name: str) -> AgentSkill | None:

144 return self._skills.get(name)

145

146 def list_by_category(self, category: AgentCategory) -> list[AgentSkill]:

147 return [s for s in self._skills.values() if s.category == category]

148

149 def search(self, query: str) -> list[AgentSkill]:

150 q = query.lower()

151 results = []

152 for s in self._skills.values():

153 score = 0

154 if q in s.name.lower(): score += 3

155 if q in s.description.lower(): score += 2

156 if any(q in t.lower() for t in s.tags): score += 2

157 if q in s.category.value: score += 1

158 if score > 0:

159 results.append((s, score))

160 results.sort(key=lambda x: x[1], reverse=True)

161 return [s for s, _ in results]

162

163 def register(self, skill: AgentSkill):

164 self._skills[skill.name] = skill

165

166 def stats(self) -> dict:

167 cats = {}

168 for s in self._skills.values():

169 cats[s.category.value] = cats.get(s.category.value, 0) + 1

170 return {"total": len(self._skills), "by_category": cats}