rootengine-core 0.5.0__tar.gz

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.
Files changed (41) hide show
  1. rootengine_core-0.5.0/LICENSE +21 -0
  2. rootengine_core-0.5.0/PKG-INFO +152 -0
  3. rootengine_core-0.5.0/README.md +134 -0
  4. rootengine_core-0.5.0/pyproject.toml +38 -0
  5. rootengine_core-0.5.0/rootengine_core/__init__.py +5 -0
  6. rootengine_core-0.5.0/rootengine_core/constants/__init__.py +0 -0
  7. rootengine_core-0.5.0/rootengine_core/constants/conversation.py +5 -0
  8. rootengine_core-0.5.0/rootengine_core/constants/framework.py +17 -0
  9. rootengine_core-0.5.0/rootengine_core/constants/tool.py +0 -0
  10. rootengine_core-0.5.0/rootengine_core/conversation/__init__.py +1 -0
  11. rootengine_core-0.5.0/rootengine_core/conversation/no_tool_conversation.py +106 -0
  12. rootengine_core-0.5.0/rootengine_core/llm/__init__.py +2 -0
  13. rootengine_core-0.5.0/rootengine_core/llm/llm.py +37 -0
  14. rootengine_core-0.5.0/rootengine_core/llm/openai_adapter.py +235 -0
  15. rootengine_core-0.5.0/rootengine_core/schema/source/conversation/no_tool_conversation.json +40 -0
  16. rootengine_core-0.5.0/rootengine_core/schema/source/llm/llm_message.json +96 -0
  17. rootengine_core-0.5.0/rootengine_core/schema/source/llm/llm_output.json +50 -0
  18. rootengine_core-0.5.0/rootengine_core/schema/source/llm/tool_choice.json +39 -0
  19. rootengine_core-0.5.0/rootengine_core/schema/source/reif_entry.json +70 -0
  20. rootengine_core-0.5.0/rootengine_core/schema/source/tool/tool_call.json +55 -0
  21. rootengine_core-0.5.0/rootengine_core/schema/source/tool/tool_func_map.json +15 -0
  22. rootengine_core-0.5.0/rootengine_core/schema/source/tool/tool_registry.json +37 -0
  23. rootengine_core-0.5.0/rootengine_core/schema/source/tool/tool_result.json +68 -0
  24. rootengine_core-0.5.0/rootengine_core/schema_runtime/reif_schema.py +338 -0
  25. rootengine_core-0.5.0/rootengine_core/tool/__init__.py +1 -0
  26. rootengine_core-0.5.0/rootengine_core/tool/adapter.py +19 -0
  27. rootengine_core-0.5.0/rootengine_core/tool/tool.py +141 -0
  28. rootengine_core-0.5.0/rootengine_core/utils/__init__.py +0 -0
  29. rootengine_core-0.5.0/rootengine_core/utils/generate_json_dict.py +291 -0
  30. rootengine_core-0.5.0/rootengine_core/utils/helpers.py +43 -0
  31. rootengine_core-0.5.0/rootengine_core/utils/path.py +20 -0
  32. rootengine_core-0.5.0/rootengine_core/utils/registrar.py +55 -0
  33. rootengine_core-0.5.0/rootengine_core/utils/reif_adapter.py +9 -0
  34. rootengine_core-0.5.0/rootengine_core/utils/reif_func.py +149 -0
  35. rootengine_core-0.5.0/rootengine_core/utils/time.py +9 -0
  36. rootengine_core-0.5.0/rootengine_core.egg-info/PKG-INFO +152 -0
  37. rootengine_core-0.5.0/rootengine_core.egg-info/SOURCES.txt +39 -0
  38. rootengine_core-0.5.0/rootengine_core.egg-info/dependency_links.txt +1 -0
  39. rootengine_core-0.5.0/rootengine_core.egg-info/requires.txt +1 -0
  40. rootengine_core-0.5.0/rootengine_core.egg-info/top_level.txt +1 -0
  41. rootengine_core-0.5.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 zimvir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: rootengine-core
3
+ Version: 0.5.0
4
+ Summary: RootEngine AI Agent Framework Core
5
+ Author-email: zimvir <zimvir@qq.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/zimvir/RootEngine
8
+ Project-URL: Repository, https://github.com/zimvir/RootEngine
9
+ Keywords: ai,agent,rootengine
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: jsonschema>=4.0.0
17
+ Dynamic: license-file
18
+
19
+ # RootEngine Core
20
+
21
+ AI Agent 框架的底层组件库。
22
+
23
+ ## 这是什么
24
+
25
+ RootEngine Core 是一个用于**构建 Agent 框架的框架**。它提供:
26
+
27
+ - **REIF 格式** - 结构化的 Agent 信息交换格式,统一对话、工具调用、结果的规范
28
+ - **核心组件** - 对话管理、工具系统、LLM 适配器
29
+ - **可组合** - 自由组合这些组件来构建你自己的 Agent
30
+
31
+ 如果你想从零搭建一个 Agent 系统,这是一个不错的起点。如果你想要一个开箱即用的 Agent,可能还不适合你。
32
+
33
+ ## 安装
34
+
35
+ ```bash
36
+ pip install rootengine-core
37
+ ```
38
+
39
+ 要求:Python >= 3.8
40
+
41
+ ## REIF 是什么
42
+
43
+ REIF(RootEngine Information Format)是一套信息格式规范,定义了 Agent 内部和组件之间如何交换数据:
44
+
45
+ - **conversation** - 对话历史
46
+ - **tool_registry** - 工具注册表
47
+ - **tool_call** - 工具调用请求
48
+ - **tool_result** - 工具执行结果
49
+
50
+ 使用统一格式的好处是:组件之间接口稳定,方便替换和扩展。
51
+
52
+ ## 快速开始
53
+
54
+ ### 对话管理
55
+
56
+ ```python
57
+ from rootengine_core import NoToolConversation
58
+
59
+ conv = NoToolConversation()
60
+ conv.add("system", "你是一个有帮助的助手")
61
+ conv.add("user", "你好")
62
+
63
+ print(conv.messages)
64
+ # [
65
+ # {"role": "system", "content": "你是一个有帮助的助手", "created_at": "..."},
66
+ # {"role": "user", "content": "你好", "created_at": "..."}
67
+ # ]
68
+ ```
69
+
70
+ ### 工具调用
71
+
72
+ ```python
73
+ from rootengine_core import Tool
74
+ from rootengine_core.utils.reif_func import reif_create
75
+
76
+ # 定义一个工具
77
+ def greeting(name, agent=None):
78
+ return f"Hello, {name}!"
79
+
80
+ # 工具注册表(REIF 格式)
81
+ registry = reif_create({"category": "tool_registry"})
82
+ registry["reif_content"] = {
83
+ "a1b2c3d4e5f6789012345678abcdef01": {
84
+ "name": "greeting",
85
+ "type": "function",
86
+ "function": {
87
+ "name": "greeting",
88
+ "description": "打招呼",
89
+ "parameters": {
90
+ "type": "object",
91
+ "properties": {"name": {"type": "string"}},
92
+ "required": ["name"]
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ # 初始化工具
99
+ tool = Tool(
100
+ tool_registry_entry=registry,
101
+ agent=None,
102
+ tool_func_map={"a1b2c3d4e5f6789012345678abcdef01": greeting}
103
+ )
104
+
105
+ # 执行工具调用
106
+ result = tool.execute({
107
+ "id": "call_001",
108
+ "type": "function",
109
+ "function": {
110
+ "registry_id": "a1b2c3d4e5f6789012345678abcdef01",
111
+ "arguments": {"name": "Alice"}
112
+ },
113
+ "created_at": "2024-01-01T00:00:00Z"
114
+ })
115
+
116
+ print(result)
117
+ # {"call_id": "call_001", "type": "function",
118
+ # "function": {"result_content": "Hello, Alice!", "status": "success"},
119
+ # "created_at": "..."}
120
+ ```
121
+
122
+ ### LLM 适配器
123
+
124
+ ```python
125
+ from rootengine_core import OpenAIAdapter
126
+
127
+ adapter = OpenAIAdapter(model="gpt-4o-mini")
128
+ # adapter.from_provider(llm_response) # 解析 LLM 返回
129
+ ```
130
+
131
+ ## 状态
132
+
133
+ 这是一个早期项目,核心组件可用,但:
134
+ - 文档还不完整
135
+ - 工具系统示例较少
136
+ - 尚未经过大规模生产验证
137
+
138
+ ## 模块一览
139
+
140
+ | 模块 | 说明 |
141
+ |------|------|
142
+ | `conversation` | 对话管理 |
143
+ | `tool` | 工具注册与执行 |
144
+ | `llm` | LLM 适配器 |
145
+ | `utils/reif_func` | REIF 格式创建与验证 |
146
+
147
+ ## 其他
148
+ - 版本: 虽然这是发出的第一版,但其在内部已有多次迭代,故以 0.5.0 为版号发布
149
+ - utils 里有很多好玩的东西
150
+ ## 许可证
151
+
152
+ MIT
@@ -0,0 +1,134 @@
1
+ # RootEngine Core
2
+
3
+ AI Agent 框架的底层组件库。
4
+
5
+ ## 这是什么
6
+
7
+ RootEngine Core 是一个用于**构建 Agent 框架的框架**。它提供:
8
+
9
+ - **REIF 格式** - 结构化的 Agent 信息交换格式,统一对话、工具调用、结果的规范
10
+ - **核心组件** - 对话管理、工具系统、LLM 适配器
11
+ - **可组合** - 自由组合这些组件来构建你自己的 Agent
12
+
13
+ 如果你想从零搭建一个 Agent 系统,这是一个不错的起点。如果你想要一个开箱即用的 Agent,可能还不适合你。
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ pip install rootengine-core
19
+ ```
20
+
21
+ 要求:Python >= 3.8
22
+
23
+ ## REIF 是什么
24
+
25
+ REIF(RootEngine Information Format)是一套信息格式规范,定义了 Agent 内部和组件之间如何交换数据:
26
+
27
+ - **conversation** - 对话历史
28
+ - **tool_registry** - 工具注册表
29
+ - **tool_call** - 工具调用请求
30
+ - **tool_result** - 工具执行结果
31
+
32
+ 使用统一格式的好处是:组件之间接口稳定,方便替换和扩展。
33
+
34
+ ## 快速开始
35
+
36
+ ### 对话管理
37
+
38
+ ```python
39
+ from rootengine_core import NoToolConversation
40
+
41
+ conv = NoToolConversation()
42
+ conv.add("system", "你是一个有帮助的助手")
43
+ conv.add("user", "你好")
44
+
45
+ print(conv.messages)
46
+ # [
47
+ # {"role": "system", "content": "你是一个有帮助的助手", "created_at": "..."},
48
+ # {"role": "user", "content": "你好", "created_at": "..."}
49
+ # ]
50
+ ```
51
+
52
+ ### 工具调用
53
+
54
+ ```python
55
+ from rootengine_core import Tool
56
+ from rootengine_core.utils.reif_func import reif_create
57
+
58
+ # 定义一个工具
59
+ def greeting(name, agent=None):
60
+ return f"Hello, {name}!"
61
+
62
+ # 工具注册表(REIF 格式)
63
+ registry = reif_create({"category": "tool_registry"})
64
+ registry["reif_content"] = {
65
+ "a1b2c3d4e5f6789012345678abcdef01": {
66
+ "name": "greeting",
67
+ "type": "function",
68
+ "function": {
69
+ "name": "greeting",
70
+ "description": "打招呼",
71
+ "parameters": {
72
+ "type": "object",
73
+ "properties": {"name": {"type": "string"}},
74
+ "required": ["name"]
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ # 初始化工具
81
+ tool = Tool(
82
+ tool_registry_entry=registry,
83
+ agent=None,
84
+ tool_func_map={"a1b2c3d4e5f6789012345678abcdef01": greeting}
85
+ )
86
+
87
+ # 执行工具调用
88
+ result = tool.execute({
89
+ "id": "call_001",
90
+ "type": "function",
91
+ "function": {
92
+ "registry_id": "a1b2c3d4e5f6789012345678abcdef01",
93
+ "arguments": {"name": "Alice"}
94
+ },
95
+ "created_at": "2024-01-01T00:00:00Z"
96
+ })
97
+
98
+ print(result)
99
+ # {"call_id": "call_001", "type": "function",
100
+ # "function": {"result_content": "Hello, Alice!", "status": "success"},
101
+ # "created_at": "..."}
102
+ ```
103
+
104
+ ### LLM 适配器
105
+
106
+ ```python
107
+ from rootengine_core import OpenAIAdapter
108
+
109
+ adapter = OpenAIAdapter(model="gpt-4o-mini")
110
+ # adapter.from_provider(llm_response) # 解析 LLM 返回
111
+ ```
112
+
113
+ ## 状态
114
+
115
+ 这是一个早期项目,核心组件可用,但:
116
+ - 文档还不完整
117
+ - 工具系统示例较少
118
+ - 尚未经过大规模生产验证
119
+
120
+ ## 模块一览
121
+
122
+ | 模块 | 说明 |
123
+ |------|------|
124
+ | `conversation` | 对话管理 |
125
+ | `tool` | 工具注册与执行 |
126
+ | `llm` | LLM 适配器 |
127
+ | `utils/reif_func` | REIF 格式创建与验证 |
128
+
129
+ ## 其他
130
+ - 版本: 虽然这是发出的第一版,但其在内部已有多次迭代,故以 0.5.0 为版号发布
131
+ - utils 里有很多好玩的东西
132
+ ## 许可证
133
+
134
+ MIT
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rootengine-core"
7
+ version = "0.5.0"
8
+ description = "RootEngine AI Agent Framework Core"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "zimvir", email = "zimvir@qq.com"}
14
+ ]
15
+ keywords = ["ai", "agent", "rootengine"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ ]
21
+ dependencies = [
22
+ "jsonschema>=4.0.0",
23
+ ]
24
+
25
+ [project.urls]
26
+ Homepage = "https://github.com/zimvir/RootEngine"
27
+ Repository = "https://github.com/zimvir/RootEngine"
28
+
29
+ [tool.setuptools.packages.find]
30
+ where = ["."]
31
+ include = ["rootengine_core*"]
32
+ exclude = ["rootengine_core.test*"]
33
+
34
+ [tool.setuptools.package-data]
35
+ rootengine_core = [
36
+ "schema/source/**/*.json",
37
+ "schema_runtime/*.py",
38
+ ]
@@ -0,0 +1,5 @@
1
+
2
+ from .conversation import NoToolConversation
3
+ from .tool import Tool
4
+ from .llm import BaseLLM
5
+ from .llm.openai_adapter import OpenAIAdapter,BaseLLMAdapter
@@ -0,0 +1,5 @@
1
+ CONVERSATION_ROLE = [
2
+ "system",
3
+ "user",
4
+ "assistant"
5
+ ]
@@ -0,0 +1,17 @@
1
+ VERSION = {
2
+ "reif_version":"1.0",
3
+ "conversation":"0.1.0",
4
+ "tool_registry":"0.1.0",
5
+ "tool_call":"0.1.0",
6
+ "tool_results":"0.1.0",
7
+ "tool_record":"0.1.0",
8
+
9
+ }
10
+
11
+ REIF_CATEGORY = [
12
+ "agent_card",
13
+ "conversation",
14
+ "tool_registry",
15
+ "tool_record"
16
+
17
+ ]
@@ -0,0 +1 @@
1
+ from .no_tool_conversation import NoToolConversation
@@ -0,0 +1,106 @@
1
+
2
+ from ..constants.conversation import CONVERSATION_ROLE
3
+ from pathlib import Path
4
+ from ..utils.reif_func import reif_create,reif_validate
5
+ from ..utils.time import get_iso_timestamp
6
+
7
+
8
+ from jsonschema import validate
9
+
10
+
11
+ from ..schema_runtime.reif_schema import get_json
12
+ SCHEMA = get_json("conversation.no_tool_conversation")
13
+
14
+ class NoToolConversation:
15
+ def __init__(self, conversation_entry: dict = None):
16
+ # 如果未传自动创建新的
17
+ if conversation_entry is None:
18
+ self.create()
19
+ else:
20
+ self.entry = conversation_entry
21
+
22
+ self.messages = self.entry["reif_content"]
23
+
24
+
25
+ def create(self) -> NoToolConversation:
26
+ """创建新会话"""
27
+ self.entry = reif_create({"category": "conversation"})
28
+ # 确保 reif_content 存在且为空列表
29
+ self.entry["reif_content"] = []
30
+ # 链接
31
+ self.messages = self.entry["reif_content"]
32
+
33
+ return self
34
+
35
+ def add(
36
+ self ,
37
+ role: str,
38
+ content: str = None,
39
+ created_at: str = None,
40
+ extra: dict = None,
41
+ ) -> NoToolConversation :
42
+
43
+ """
44
+ 向会话添加一条消息。
45
+
46
+ :param role: 消息角色,必须为 system/user/assistant/tool 之一。
47
+ :param content: 文本内容(对 system/user/assistant 必填,对 tool 可选)。
48
+
49
+ :param extra: 可选的扩展字典,任意附加信息。
50
+ :param created_at: 可选时间戳,若不提供则自动生成。
51
+ :return: self,支持链式调用。
52
+ """
53
+ #检验角色
54
+ if role not in CONVERSATION_ROLE:
55
+ raise ValueError(f"未知角色: {role}")
56
+
57
+ # 生成时间戳
58
+ if created_at is None:
59
+ created_at = get_iso_timestamp()
60
+
61
+
62
+ # 构造消息字典
63
+ item = {
64
+ "role": role,
65
+ "content": content,
66
+ "created_at": created_at
67
+ }
68
+
69
+ if extra:
70
+ item["extra"] = extra
71
+
72
+ self.messages.append(item)
73
+ return self
74
+
75
+ def delete(self, index: int = None):
76
+ """
77
+
78
+ :param index: 索引,若不填默认删除最后一个
79
+ :return:
80
+ """
81
+
82
+ if index is None:
83
+ self.messages.pop()
84
+ else:
85
+ self.messages.pop(index)
86
+ return self
87
+
88
+
89
+
90
+ def load_entry(self,entry: dict) -> NoToolConversation :
91
+ """加载整个 conversation 条目"""
92
+ self.entry = entry
93
+ self.messages = self.entry["reif_content"]
94
+ return self
95
+ def load_messages(self,messages: list) -> NoToolConversation :
96
+ self.messages = messages
97
+ self.entry["reif_content"] = self.messages
98
+ return self
99
+
100
+ def validate_schema(self) -> bool:
101
+ if self.reif_entry is None:
102
+ raise RuntimeError("无会话可校验")
103
+ reif_validate(self.entry)
104
+ validate(instance=self.messages, schema = SCHEMA)
105
+ return True
106
+
@@ -0,0 +1,2 @@
1
+ from .llm import BaseLLM
2
+ from .openai_adapter import BaseLLMAdapter,OpenAIAdapter
@@ -0,0 +1,37 @@
1
+ from typing import Optional,Dict,List,Any
2
+
3
+ from abc import ABC,abstractmethod
4
+
5
+
6
+ class BaseLLM(ABC):
7
+
8
+
9
+ @abstractmethod
10
+
11
+ def call(self,
12
+ messages:List[dict[str,Any]],
13
+ tool_registry:Optional[List[Dict[str, Any]]],
14
+ tool_choice: Optional[str],
15
+ **kwargs)\
16
+ -> Dict[str, Any]:
17
+ """
18
+
19
+ :param messages: 消息列表 参考 ../schema/source/llm/llm_message.json
20
+ :param tool_registry: 工具注册表 参考 ../schema/source/tool/tool_registry.json
21
+ :param tool_choice: 工具选择策略 参考 ../schema/source/llm/tool_choice.json
22
+ :param kwargs: 拓展任意字段
23
+ :return: 参考 ../schema/source/llm/llm_output.json
24
+
25
+ """
26
+ pass
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+