agentmatrix-core 0.7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentmatrix/core/__init__.py +0 -0
- agentmatrix/core/action.py +62 -0
- agentmatrix/core/agent_shell.py +99 -0
- agentmatrix/core/backends/__init__.py +1 -0
- agentmatrix/core/backends/llm_client.py +1320 -0
- agentmatrix/core/backends/mock_llm.py +35 -0
- agentmatrix/core/cerebellum.py +184 -0
- agentmatrix/core/events.py +27 -0
- agentmatrix/core/exceptions.py +113 -0
- agentmatrix/core/id_generator.py +213 -0
- agentmatrix/core/interfaces.py +46 -0
- agentmatrix/core/log_config.py +71 -0
- agentmatrix/core/log_util.py +212 -0
- agentmatrix/core/message.py +61 -0
- agentmatrix/core/micro_agent.py +1538 -0
- agentmatrix/core/prompt_templates.py +61 -0
- agentmatrix/core/readable_id_generator.py +80 -0
- agentmatrix/core/session_store.py +27 -0
- agentmatrix/core/signals.py +135 -0
- agentmatrix/core/skills/__init__.py +5 -0
- agentmatrix/core/skills/base.py +40 -0
- agentmatrix/core/skills/registry.py +629 -0
- agentmatrix/core/state_manager.py +96 -0
- agentmatrix/core/utils/__init__.py +17 -0
- agentmatrix/core/utils/micro_agent_utils.py +573 -0
- agentmatrix/core/utils/parser_utils.py +67 -0
- agentmatrix/core/utils/skill_parser_utils.py +330 -0
- agentmatrix/core/utils/token_utils.py +91 -0
- agentmatrix_core-0.7.0.0.dist-info/METADATA +309 -0
- agentmatrix_core-0.7.0.0.dist-info/RECORD +33 -0
- agentmatrix_core-0.7.0.0.dist-info/WHEEL +5 -0
- agentmatrix_core-0.7.0.0.dist-info/licenses/LICENSE +190 -0
- agentmatrix_core-0.7.0.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Any, Dict, Optional, Callable
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SkillType(Enum):
|
|
8
|
+
"""Skill 类型"""
|
|
9
|
+
PYTHON_METHOD = "python_method" # Python 可执行方法
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class ActionMetadata:
|
|
14
|
+
name: str
|
|
15
|
+
description: str
|
|
16
|
+
# 存储生成的 JSON Schema,给 SLM 看
|
|
17
|
+
json_schema: Dict[str, Any]
|
|
18
|
+
|
|
19
|
+
# 🆕 新架构字段
|
|
20
|
+
skill_type: SkillType = SkillType.PYTHON_METHOD
|
|
21
|
+
implementation: Optional[Callable] = None # Python 实现(仅 PYTHON_METHOD)
|
|
22
|
+
|
|
23
|
+
def register_action(
|
|
24
|
+
short_desc: str,
|
|
25
|
+
description: str,
|
|
26
|
+
param_infos: Dict[str, str] = None,
|
|
27
|
+
skill_type: SkillType = SkillType.PYTHON_METHOD # 🆕 新参数(默认向后兼容)
|
|
28
|
+
):
|
|
29
|
+
"""
|
|
30
|
+
Args:
|
|
31
|
+
description: 函数功能的自然语言描述
|
|
32
|
+
param_infos: 参数名 -> 参数含义的映射 (e.g. {"to": "目标Agent名字"})
|
|
33
|
+
skill_type: 技能类型(PYTHON_METHOD 或 MD_DOCUMENT)
|
|
34
|
+
"""
|
|
35
|
+
if param_infos is None:
|
|
36
|
+
param_infos = {}
|
|
37
|
+
|
|
38
|
+
def decorator(func):
|
|
39
|
+
func._is_action = True
|
|
40
|
+
func._action_short_desc = short_desc # 🆕 保存简短描述
|
|
41
|
+
func._action_desc = description
|
|
42
|
+
func._action_param_infos = param_infos
|
|
43
|
+
func._skill_type = skill_type # 🆕
|
|
44
|
+
return func
|
|
45
|
+
return decorator
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class ActionDef:
|
|
49
|
+
name: str
|
|
50
|
+
description: str
|
|
51
|
+
parameters: Dict[str, str]
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_dict(cls, data: Dict[str, Any]):
|
|
55
|
+
return cls(
|
|
56
|
+
name=data["name"],
|
|
57
|
+
description=data["description"],
|
|
58
|
+
parameters=data.get("parameters", {})
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def to_prompt(self):
|
|
62
|
+
return f"- {self.name}: {self.description} | Params: {json.dumps(self.parameters, ensure_ascii=False)}"
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AgentShell — Agent 的外层壳接口。
|
|
3
|
+
|
|
4
|
+
Agent = AgentShell + AgentCore(一对一)
|
|
5
|
+
不同应用形态实现这个接口,Core 通过它与外部世界交互。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
import logging
|
|
10
|
+
from typing import List, Dict, Protocol, runtime_checkable
|
|
11
|
+
|
|
12
|
+
from .interfaces import BrainProtocol, CerebellumProtocol
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@runtime_checkable
|
|
16
|
+
class AgentShell(Protocol):
|
|
17
|
+
"""
|
|
18
|
+
AgentCore 的宿主接口。
|
|
19
|
+
|
|
20
|
+
不同应用形态实现这个接口,Core 通过它与外部世界交互。
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
brain: BrainProtocol
|
|
24
|
+
cerebellum: CerebellumProtocol
|
|
25
|
+
logger: logging.Logger
|
|
26
|
+
|
|
27
|
+
def get_prompt_template(self, name: str) -> str:
|
|
28
|
+
"""获取 prompt 模板。
|
|
29
|
+
|
|
30
|
+
Core 通过此方法访问模板,不直接接触文件系统或配置。
|
|
31
|
+
不同 Shell 实现可以用不同方式加载模板(文件系统、数据库、内存等)。
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
name: 模板名称(如 "SYSTEM_PROMPT", "COLLAB_MODE")
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
模板文本
|
|
38
|
+
"""
|
|
39
|
+
...
|
|
40
|
+
|
|
41
|
+
async def generate_working_notes(
|
|
42
|
+
self, messages: List[Dict[str, str]], focus_hint: str = ""
|
|
43
|
+
) -> str:
|
|
44
|
+
"""从对话历史生成 Working Notes(工作笔记)。
|
|
45
|
+
|
|
46
|
+
不同 Shell 实现可根据通信模式定制 prompt(邮件、聊天、纯任务等)。
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
messages: 当前对话历史
|
|
50
|
+
focus_hint: 可选,指导 LLM 重点关注某方面
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
Markdown 格式的 Working Notes
|
|
54
|
+
"""
|
|
55
|
+
...
|
|
56
|
+
|
|
57
|
+
async def compress_messages(self, agent) -> None:
|
|
58
|
+
"""压缩 agent 的 messages(保留 system + 用 working notes 重建 user message)。
|
|
59
|
+
|
|
60
|
+
Core 在 token 超阈值时调用此方法。默认实现:
|
|
61
|
+
- 调用 generate_working_notes() 生成工作笔记
|
|
62
|
+
- 保留 system message,用原始 user message + working notes 重建
|
|
63
|
+
- 清空 scratchpad
|
|
64
|
+
|
|
65
|
+
Shell 实现可覆盖此方法以自定义压缩策略(如保留邮件历史等)。
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
agent: MicroAgent 实例(可访问 messages, scratchpad, session 等)
|
|
69
|
+
"""
|
|
70
|
+
...
|
|
71
|
+
|
|
72
|
+
async def checkpoint(self) -> None:
|
|
73
|
+
"""协作式检查点:Core 在关键位置调用,Shell 决定是否暂停/停止。
|
|
74
|
+
|
|
75
|
+
典型实现:检查 paused/stopped 标志,必要时 await 等待恢复。
|
|
76
|
+
"""
|
|
77
|
+
...
|
|
78
|
+
|
|
79
|
+
def get_md_skill_prompt(self, skill_names: List[str]) -> str:
|
|
80
|
+
"""获取 MD Skill 的 prompt 文本。
|
|
81
|
+
|
|
82
|
+
Shell 决定如何读取 SKILL.md、如何组装 prompt。
|
|
83
|
+
Core 只提供 skill 名字列表。
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
skill_names: skill 名字列表(如 ["git-workflow", "memory"])
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
完整的 MD Skill prompt 文本,用于注入 system prompt
|
|
90
|
+
"""
|
|
91
|
+
...
|
|
92
|
+
|
|
93
|
+
def is_llm_available(self) -> bool:
|
|
94
|
+
"""检查 LLM 服务是否可用。"""
|
|
95
|
+
...
|
|
96
|
+
|
|
97
|
+
async def wait_for_llm_recovery(self) -> None:
|
|
98
|
+
"""等待 LLM 服务恢复。"""
|
|
99
|
+
...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Backends module for Agent-Matrix framework."""
|