Coverage for merco/agents/profile.py: 93%

28 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-07 14:04 +0800

1"""AgentProfile data model and registry""" 

2from __future__ import annotations 

3 

4from dataclasses import dataclass, field 

5 

6 

7@dataclass 

8class AgentProfile: 

9 """Professional role configuration for sub-agents""" 

10 name: str 

11 description: str 

12 prompt: str 

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

14 model: dict | None = None 

15 limits: dict = field(default_factory=dict) 

16 

17 

18class AgentProfileRegistry: 

19 """Registry for AgentProfile instances""" 

20 

21 def __init__(self): 

22 self._profiles: dict[str, AgentProfile] = {} 

23 

24 def register(self, profile: AgentProfile) -> None: 

25 self._profiles[profile.name] = profile 

26 

27 def get(self, name: str) -> AgentProfile | None: 

28 return self._profiles.get(name) 

29 

30 def list(self) -> list[AgentProfile]: 

31 return list(self._profiles.values()) 

32 

33 

34class ProfilePromptChunk: 

35 """Prompt chunk that injects agent role from profile""" 

36 name = "agent_profile" 

37 

38 def __init__(self, profile: AgentProfile): 

39 self.profile = profile 

40 

41 def enabled(self, agent) -> bool: 

42 return True 

43 

44 def build(self, agent) -> str: 

45 return f"## Agent Role: {self.profile.name}\n{self.profile.prompt}" 

46 

47 

48BUILTIN_PROFILES: list[AgentProfile] = [ 

49 AgentProfile( 

50 name="default", 

51 description="普通子代理,继承父代理全部能力", 

52 prompt="你是 merco 子代理。完成父代理委派的任务,返回简洁明确的结果。", 

53 ), 

54 AgentProfile( 

55 name="researcher", 

56 description="代码搜索、资料收集、架构理解", 

57 prompt="你是代码研究员。专注于阅读代码、搜索资料、归纳结构,不做大规模修改。输出清晰的发现和证据。", 

58 tools=["read_file", "web_fetch", "web_search"], 

59 limits={"max_tool_calls": 30}, 

60 ), 

61 AgentProfile( 

62 name="reviewer", 

63 description="代码审查、bug 风险识别、质量检查", 

64 prompt="你是代码审查专家。专注于发现 correctness bug、边界条件、测试缺口和架构问题。只报告高置信问题。", 

65 tools=["read_file", "grep", "bash"], 

66 limits={"max_tool_calls": 25}, 

67 ), 

68 AgentProfile( 

69 name="debugger", 

70 description="系统调试、根因分析、失败复现", 

71 prompt="你是系统调试专家。先定位症状,再建立假设,最后用测试/日志验证。不要盲改。", 

72 tools=["read_file", "bash", "grep"], 

73 limits={"max_tool_calls": 40}, 

74 ), 

75]