prism-agent 0.2.1__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 (46) hide show
  1. prism_agent-0.2.1/LICENSE +21 -0
  2. prism_agent-0.2.1/PKG-INFO +223 -0
  3. prism_agent-0.2.1/README.md +154 -0
  4. prism_agent-0.2.1/prism/__init__.py +5 -0
  5. prism_agent-0.2.1/prism/acp/__init__.py +5 -0
  6. prism_agent-0.2.1/prism/acp/client.py +63 -0
  7. prism_agent-0.2.1/prism/agent.py +144 -0
  8. prism_agent-0.2.1/prism/cli.py +419 -0
  9. prism_agent-0.2.1/prism/config.py +150 -0
  10. prism_agent-0.2.1/prism/gateway/__init__.py +91 -0
  11. prism_agent-0.2.1/prism/gateway/base.py +39 -0
  12. prism_agent-0.2.1/prism/gateway/discord.py +149 -0
  13. prism_agent-0.2.1/prism/gateway/feishu.py +242 -0
  14. prism_agent-0.2.1/prism/gateway/telegram.py +200 -0
  15. prism_agent-0.2.1/prism/mcp/__init__.py +202 -0
  16. prism_agent-0.2.1/prism/mcp/config_loader.py +96 -0
  17. prism_agent-0.2.1/prism/mcp/http_client.py +124 -0
  18. prism_agent-0.2.1/prism/providers/__init__.py +13 -0
  19. prism_agent-0.2.1/prism/providers/fallback.py +25 -0
  20. prism_agent-0.2.1/prism/providers/manager.py +158 -0
  21. prism_agent-0.2.1/prism/providers/pool.py +28 -0
  22. prism_agent-0.2.1/prism/skills/__init__.py +233 -0
  23. prism_agent-0.2.1/prism/tools/__init__.py +1 -0
  24. prism_agent-0.2.1/prism/tools/browser.py +389 -0
  25. prism_agent-0.2.1/prism/tools/browser_bridge.py +34 -0
  26. prism_agent-0.2.1/prism/tools/browser_echo.py +36 -0
  27. prism_agent-0.2.1/prism/tools/code_executor.py +160 -0
  28. prism_agent-0.2.1/prism/tools/registry.py +272 -0
  29. prism_agent-0.2.1/prism-desktop/prism_desktop/__init__.py +5 -0
  30. prism_agent-0.2.1/prism-desktop/prism_desktop/main.py +187 -0
  31. prism_agent-0.2.1/prism-desktop/prism_desktop/version.py +1 -0
  32. prism_agent-0.2.1/prism_agent.egg-info/PKG-INFO +223 -0
  33. prism_agent-0.2.1/prism_agent.egg-info/SOURCES.txt +44 -0
  34. prism_agent-0.2.1/prism_agent.egg-info/dependency_links.txt +1 -0
  35. prism_agent-0.2.1/prism_agent.egg-info/entry_points.txt +2 -0
  36. prism_agent-0.2.1/prism_agent.egg-info/requires.txt +22 -0
  37. prism_agent-0.2.1/prism_agent.egg-info/top_level.txt +2 -0
  38. prism_agent-0.2.1/pyproject.toml +78 -0
  39. prism_agent-0.2.1/setup.cfg +4 -0
  40. prism_agent-0.2.1/tests/test_browser.py +22 -0
  41. prism_agent-0.2.1/tests/test_browser_minimal.py +27 -0
  42. prism_agent-0.2.1/tests/test_code_executor.py +12 -0
  43. prism_agent-0.2.1/tests/test_full_smoke.py +34 -0
  44. prism_agent-0.2.1/tests/test_mcp_client.py +12 -0
  45. prism_agent-0.2.1/tests/test_mcp_config_loader.py +30 -0
  46. prism_agent-0.2.1/tests/test_mcp_connect.py +17 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PRISM Agent
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,223 @@
1
+ Metadata-Version: 2.4
2
+ Name: prism-agent
3
+ Version: 0.2.1
4
+ Summary: 统一 AI Agent CLI:整合 Hermes/Codex/OpenClaw 能力
5
+ Author-email: PRISM Agent <prism@example.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 PRISM Agent
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/jz616059669/prism-agent
29
+ Project-URL: Documentation, https://github.com/jz616059669/prism-agent#readme
30
+ Project-URL: Repository, https://github.com/jz616059669/prism-agent.git
31
+ Project-URL: Issues, https://github.com/jz616059669/prism-agent/issues
32
+ Project-URL: Changelog, https://github.com/jz616059669/prism-agent/blob/master/CHANGELOG.md
33
+ Keywords: ai,agent,cli,llm,openai,playwright,mcp,gateway
34
+ Classifier: Development Status :: 4 - Beta
35
+ Classifier: Environment :: Console
36
+ Classifier: Environment :: X11 Applications :: Qt
37
+ Classifier: Intended Audience :: Developers
38
+ Classifier: Intended Audience :: End Users/Desktop
39
+ Classifier: License :: OSI Approved :: MIT License
40
+ Classifier: Operating System :: OS Independent
41
+ Classifier: Programming Language :: Python :: 3
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
45
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
46
+ Classifier: Topic :: System :: Distributed Computing
47
+ Requires-Python: >=3.11
48
+ Description-Content-Type: text/markdown
49
+ License-File: LICENSE
50
+ Requires-Dist: rich>=13.0
51
+ Requires-Dist: pyyaml>=6.0
52
+ Requires-Dist: python-dotenv>=1.0
53
+ Requires-Dist: openai>=1.0
54
+ Requires-Dist: httpx>=0.27
55
+ Requires-Dist: click>=8.1
56
+ Requires-Dist: prompt-toolkit>=3.0
57
+ Provides-Extra: browser
58
+ Requires-Dist: playwright>=1.60.0; extra == "browser"
59
+ Requires-Dist: nest-asyncio>=1.6.0; extra == "browser"
60
+ Provides-Extra: desktop
61
+ Requires-Dist: flet>=0.24.0; extra == "desktop"
62
+ Provides-Extra: dev
63
+ Requires-Dist: pytest>=9.1.1; extra == "dev"
64
+ Requires-Dist: playwright>=1.60.0; extra == "dev"
65
+ Requires-Dist: nest-asyncio>=1.6.0; extra == "dev"
66
+ Provides-Extra: all
67
+ Requires-Dist: prism-agent[browser,desktop]; extra == "all"
68
+ Dynamic: license-file
69
+
70
+ # PRISM Agent
71
+
72
+ **统一 AI Agent CLI + 桌面客户端 — 整合 Hermes + Codex + OpenClaw 能力**
73
+
74
+ ## 一键安装
75
+
76
+ **Windows:**
77
+ ```powershell
78
+ git clone https://github.com/jz616059669/prism-agent.git
79
+ cd prism-agent
80
+ .\scripts\install.ps1
81
+ ```
82
+
83
+ Windows 额外支持:
84
+ ```powershell
85
+ # 打包桌面客户端
86
+ .\scripts\build-windows.ps1
87
+
88
+ # 后台运行 Gateway(NSSM)
89
+ nssm install PrismGateway "C:\path\to\prism.exe" "gateway start"
90
+ nssm start PrismGateway
91
+ ```
92
+
93
+ **macOS:**
94
+ ```bash
95
+ git clone https://github.com/jz616059669/prism-agent.git
96
+ cd prism-agent
97
+ bash scripts/install.sh
98
+ ```
99
+
100
+ macOS 额外支持:
101
+ ```bash
102
+ # 打包桌面客户端
103
+ bash scripts/build-macos.sh
104
+
105
+ # 安装 launchd 服务(后台运行 Gateway)
106
+ cp scripts/com.prism.gateway.plist ~/Library/LaunchAgents/
107
+ launchctl load ~/Library/LaunchAgents/com.prism.gateway.plist
108
+ launchctl list | grep prism
109
+ ```
110
+
111
+ **Linux(Ubuntu/Debian/Fedora/Arch):**
112
+ ```bash
113
+ git clone https://github.com/jz616059669/prism-agent.git
114
+ cd prism-agent
115
+ bash scripts/install.sh
116
+ ```
117
+
118
+ Linux 额外支持:
119
+ ```bash
120
+ # 打包桌面客户端
121
+ bash scripts/build-linux.sh
122
+
123
+ # 安装 systemd 服务(后台运行 Gateway)
124
+ sudo cp scripts/prism-gateway.service /etc/systemd/system/
125
+ sudo systemctl enable prism-gateway
126
+ sudo systemctl start prism-gateway
127
+ ```
128
+
129
+ 安装完成后:
130
+ ```bash
131
+ prism --help # CLI
132
+ prism-desktop # 桌面客户端
133
+ ```
134
+
135
+ ## 手动安装
136
+
137
+ 见 [INSTALL.md](INSTALL.md)
138
+
139
+ ## 当前能力
140
+
141
+ | 能力 | 状态 | 说明 |
142
+ |---|---|---|
143
+ | 统一模型接口 | ✅ | 一个命令切换任意模型,自动降级 |
144
+ | 多 Key 轮转 | ✅ | 凭证池自动轮转,不怕单 Key 失效 |
145
+ | 文件/终端工具 | ✅ | 读写、补丁、shell、后台任务 |
146
+ | 浏览器控制 | ✅ | Playwright 驱动,支持导航、快照、点击、输入、截图 |
147
+ | 代码执行沙箱 | ✅ | Python 代码执行,支持超时和输出捕获 |
148
+ | MCP 客户端 | ✅ | stdio / HTTP 双模式 |
149
+ | Skills 系统 | ✅ | 6 个内置 skill,支持安装/移除 |
150
+ | Gateway | ✅ | 飞书 / Telegram / Discord 适配器 |
151
+ | CLI 子命令 | ✅ | gateway / skill / browser / config / chat / ask / tools |
152
+
153
+ ## 快速开始
154
+
155
+ ```bash
156
+ # 查看版本
157
+ prism version
158
+
159
+ # 列出工具
160
+ prism tools
161
+
162
+ # 列出 skills
163
+ prism skill list
164
+
165
+ # 打开网页
166
+ prism browser open https://example.com
167
+
168
+ # 单次提问
169
+ prism ask "用 Python 写一个快速排序"
170
+
171
+ # 交互聊天
172
+ prism chat
173
+
174
+ # 启动桌面客户端
175
+ prism-desktop
176
+ ```
177
+
178
+ ## Gateway
179
+
180
+ ```bash
181
+ # 查看状态
182
+ prism gateway status
183
+
184
+ # 前台运行
185
+ prism gateway start --platform telegram --token <TOKEN>
186
+ prism gateway start --platform feishu --app-id <ID> --app-secret <SECRET>
187
+
188
+ # Linux 后台运行(systemd)
189
+ sudo cp scripts/prism-gateway.service /etc/systemd/system/
190
+ sudo systemctl enable prism-gateway
191
+ sudo systemctl start prism-gateway
192
+ sudo systemctl status prism-gateway
193
+
194
+ # macOS 后台运行(launchd)
195
+ cp scripts/com.prism.gateway.plist ~/Library/LaunchAgents/
196
+ launchctl load ~/Library/LaunchAgents/com.prism.gateway.plist
197
+ launchctl list | grep prism
198
+ ```
199
+
200
+ ## 配置
201
+
202
+ ```bash
203
+ prism config set model.default step-3.7-flash
204
+ prism config get model.default
205
+ prism config get
206
+ ```
207
+
208
+ ## 开发
209
+
210
+ ```bash
211
+ git clone https://github.com/jz616059669/prism-agent.git
212
+ cd prism-agent
213
+ pip install -e .
214
+ pytest
215
+ ```
216
+
217
+ ## 路线图
218
+
219
+ - 飞书 / Telegram / Discord 真实连接验证
220
+ - MCP 服务器连接测试
221
+ - Skills 市场 / 一键安装
222
+ - 浏览器测试套件完善
223
+ - ACP 协议支持
@@ -0,0 +1,154 @@
1
+ # PRISM Agent
2
+
3
+ **统一 AI Agent CLI + 桌面客户端 — 整合 Hermes + Codex + OpenClaw 能力**
4
+
5
+ ## 一键安装
6
+
7
+ **Windows:**
8
+ ```powershell
9
+ git clone https://github.com/jz616059669/prism-agent.git
10
+ cd prism-agent
11
+ .\scripts\install.ps1
12
+ ```
13
+
14
+ Windows 额外支持:
15
+ ```powershell
16
+ # 打包桌面客户端
17
+ .\scripts\build-windows.ps1
18
+
19
+ # 后台运行 Gateway(NSSM)
20
+ nssm install PrismGateway "C:\path\to\prism.exe" "gateway start"
21
+ nssm start PrismGateway
22
+ ```
23
+
24
+ **macOS:**
25
+ ```bash
26
+ git clone https://github.com/jz616059669/prism-agent.git
27
+ cd prism-agent
28
+ bash scripts/install.sh
29
+ ```
30
+
31
+ macOS 额外支持:
32
+ ```bash
33
+ # 打包桌面客户端
34
+ bash scripts/build-macos.sh
35
+
36
+ # 安装 launchd 服务(后台运行 Gateway)
37
+ cp scripts/com.prism.gateway.plist ~/Library/LaunchAgents/
38
+ launchctl load ~/Library/LaunchAgents/com.prism.gateway.plist
39
+ launchctl list | grep prism
40
+ ```
41
+
42
+ **Linux(Ubuntu/Debian/Fedora/Arch):**
43
+ ```bash
44
+ git clone https://github.com/jz616059669/prism-agent.git
45
+ cd prism-agent
46
+ bash scripts/install.sh
47
+ ```
48
+
49
+ Linux 额外支持:
50
+ ```bash
51
+ # 打包桌面客户端
52
+ bash scripts/build-linux.sh
53
+
54
+ # 安装 systemd 服务(后台运行 Gateway)
55
+ sudo cp scripts/prism-gateway.service /etc/systemd/system/
56
+ sudo systemctl enable prism-gateway
57
+ sudo systemctl start prism-gateway
58
+ ```
59
+
60
+ 安装完成后:
61
+ ```bash
62
+ prism --help # CLI
63
+ prism-desktop # 桌面客户端
64
+ ```
65
+
66
+ ## 手动安装
67
+
68
+ 见 [INSTALL.md](INSTALL.md)
69
+
70
+ ## 当前能力
71
+
72
+ | 能力 | 状态 | 说明 |
73
+ |---|---|---|
74
+ | 统一模型接口 | ✅ | 一个命令切换任意模型,自动降级 |
75
+ | 多 Key 轮转 | ✅ | 凭证池自动轮转,不怕单 Key 失效 |
76
+ | 文件/终端工具 | ✅ | 读写、补丁、shell、后台任务 |
77
+ | 浏览器控制 | ✅ | Playwright 驱动,支持导航、快照、点击、输入、截图 |
78
+ | 代码执行沙箱 | ✅ | Python 代码执行,支持超时和输出捕获 |
79
+ | MCP 客户端 | ✅ | stdio / HTTP 双模式 |
80
+ | Skills 系统 | ✅ | 6 个内置 skill,支持安装/移除 |
81
+ | Gateway | ✅ | 飞书 / Telegram / Discord 适配器 |
82
+ | CLI 子命令 | ✅ | gateway / skill / browser / config / chat / ask / tools |
83
+
84
+ ## 快速开始
85
+
86
+ ```bash
87
+ # 查看版本
88
+ prism version
89
+
90
+ # 列出工具
91
+ prism tools
92
+
93
+ # 列出 skills
94
+ prism skill list
95
+
96
+ # 打开网页
97
+ prism browser open https://example.com
98
+
99
+ # 单次提问
100
+ prism ask "用 Python 写一个快速排序"
101
+
102
+ # 交互聊天
103
+ prism chat
104
+
105
+ # 启动桌面客户端
106
+ prism-desktop
107
+ ```
108
+
109
+ ## Gateway
110
+
111
+ ```bash
112
+ # 查看状态
113
+ prism gateway status
114
+
115
+ # 前台运行
116
+ prism gateway start --platform telegram --token <TOKEN>
117
+ prism gateway start --platform feishu --app-id <ID> --app-secret <SECRET>
118
+
119
+ # Linux 后台运行(systemd)
120
+ sudo cp scripts/prism-gateway.service /etc/systemd/system/
121
+ sudo systemctl enable prism-gateway
122
+ sudo systemctl start prism-gateway
123
+ sudo systemctl status prism-gateway
124
+
125
+ # macOS 后台运行(launchd)
126
+ cp scripts/com.prism.gateway.plist ~/Library/LaunchAgents/
127
+ launchctl load ~/Library/LaunchAgents/com.prism.gateway.plist
128
+ launchctl list | grep prism
129
+ ```
130
+
131
+ ## 配置
132
+
133
+ ```bash
134
+ prism config set model.default step-3.7-flash
135
+ prism config get model.default
136
+ prism config get
137
+ ```
138
+
139
+ ## 开发
140
+
141
+ ```bash
142
+ git clone https://github.com/jz616059669/prism-agent.git
143
+ cd prism-agent
144
+ pip install -e .
145
+ pytest
146
+ ```
147
+
148
+ ## 路线图
149
+
150
+ - 飞书 / Telegram / Discord 真实连接验证
151
+ - MCP 服务器连接测试
152
+ - Skills 市场 / 一键安装
153
+ - 浏览器测试套件完善
154
+ - ACP 协议支持
@@ -0,0 +1,5 @@
1
+ """
2
+ PRISM Agent - 统一 AI Agent CLI
3
+ """
4
+
5
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ """PRISM ACP"""
2
+
3
+ from prism.acp.client import ACPClient
4
+
5
+ __all__ = ['ACPClient']
@@ -0,0 +1,63 @@
1
+ """
2
+ PRISM Agent - ACP (Agent Communication Protocol) 客户端
3
+ 提供与 ACP 兼容 agent 通信的能力
4
+ """
5
+
6
+ import json
7
+ import subprocess
8
+ from typing import Any, Dict, Optional
9
+
10
+
11
+ class ACPClient:
12
+ """
13
+ ACP 客户端
14
+ 通过 stdio 与 ACP 兼容 agent 通信
15
+ """
16
+
17
+ def __init__(self, command: str, args: Optional[list] = None):
18
+ self.command = command
19
+ self.args = args or []
20
+ self.process: Optional[subprocess.Popen] = None
21
+
22
+ def start(self) -> Dict[str, Any]:
23
+ try:
24
+ self.process = subprocess.Popen(
25
+ [self.command] + self.args,
26
+ stdin=subprocess.PIPE,
27
+ stdout=subprocess.PIPE,
28
+ stderr=subprocess.PIPE,
29
+ text=True,
30
+ bufsize=1,
31
+ )
32
+ return {'success': True}
33
+ except Exception as e:
34
+ return {'success': False, 'error': str(e)}
35
+
36
+ def send(self, payload: Dict[str, Any]) -> Dict[str, Any]:
37
+ if not self.process:
38
+ return {'success': False, 'error': 'ACP client not started'}
39
+
40
+ try:
41
+ request = json.dumps({'jsonrpc': '2.0', 'id': 1, **payload}) + '\n'
42
+ self.process.stdin.write(request)
43
+ self.process.stdin.flush()
44
+ response_line = self.process.stdout.readline()
45
+ if not response_line:
46
+ return {'success': False, 'error': 'No response from ACP agent'}
47
+ response = json.loads(response_line)
48
+ if 'result' in response:
49
+ return {'success': True, 'result': response['result']}
50
+ if 'error' in response:
51
+ return {'success': False, 'error': response['error'].get('message', 'Unknown error')}
52
+ return {'success': False, 'error': 'Invalid ACP response'}
53
+ except Exception as e:
54
+ return {'success': False, 'error': str(e)}
55
+
56
+ def close(self):
57
+ if self.process:
58
+ try:
59
+ self.process.terminate()
60
+ self.process.wait(timeout=5)
61
+ except Exception:
62
+ pass
63
+ self.process = None
@@ -0,0 +1,144 @@
1
+ """
2
+ PRISM Agent - 核心Agent循环
3
+ 整合 Hermes 的上下文压缩 + Codex 的工具调用 + OpenClaw 的浏览器控制
4
+ """
5
+
6
+ import json
7
+ import os
8
+ import logging
9
+ from typing import List, Dict, Any, Optional, Callable
10
+ from dataclasses import dataclass, field
11
+ from datetime import datetime
12
+
13
+ from prism.providers.manager import provider_pool
14
+ from prism.tools.registry import registry
15
+
16
+ logger = logging.getLogger("prism.agent")
17
+
18
+
19
+ @dataclass
20
+ class Message:
21
+ """消息结构"""
22
+ role: str # system | user | assistant | tool
23
+ content: str
24
+ timestamp: datetime = field(default_factory=datetime.now)
25
+ metadata: Dict[str, Any] = field(default_factory=dict)
26
+
27
+
28
+ @dataclass
29
+ class ToolCall:
30
+ """工具调用"""
31
+ id: str
32
+ name: str
33
+ arguments: Dict[str, Any]
34
+ result: Optional[Dict[str, Any]] = None
35
+
36
+
37
+ class Agent:
38
+ """
39
+ PRISM Agent 核心
40
+ 整合:
41
+ - Hermes 的 Skills 系统
42
+ - Codex 的代码执行能力
43
+ - OpenClaw 的浏览器自动化
44
+ - 统一的模型调用接口
45
+ """
46
+
47
+ def __init__(self, system_prompt: Optional[str] = None):
48
+ self.messages: List[Message] = []
49
+ self.tool_calls: List[ToolCall] = []
50
+ self.system_prompt = system_prompt or self._default_system_prompt()
51
+ self.max_turns = 150
52
+ self.tools_enabled = True
53
+
54
+ # 初始化系统消息
55
+ self.messages.append(Message(
56
+ role="system",
57
+ content=self.system_prompt,
58
+ ))
59
+
60
+ def _default_system_prompt(self) -> str:
61
+ """默认系统提示词"""
62
+ return """你是 PRISM Agent,一个强大的 AI 助手。
63
+
64
+ 你可以:
65
+ 1. 读写文件、执行命令
66
+ 2. 搜索网页、控制浏览器
67
+ 3. 执行 Python 代码
68
+ 4. 管理定时任务
69
+ 5. 发送消息到 Telegram/Discord/飞书
70
+
71
+ 原则:
72
+ - 先理解用户需求,再执行
73
+ - 复杂任务拆成步骤
74
+ - 遇到问题主动报告,不要隐瞒
75
+ - 安全第一,危险操作先确认
76
+ """
77
+
78
+ def chat(self, user_message: str) -> str:
79
+ """
80
+ 发送消息并获取回复
81
+ 整合了:
82
+ - Hermes 的上下文管理
83
+ - Codex 的函数调用
84
+ - OpenClaw 的工具执行
85
+ """
86
+ # 添加用户消息
87
+ self.messages.append(Message(role="user", content=user_message))
88
+
89
+ # 构建 API 消息格式
90
+ api_messages = [
91
+ {"role": m.role, "content": m.content}
92
+ for m in self.messages
93
+ ]
94
+
95
+ # 调用模型
96
+ result = provider_pool.chat(api_messages)
97
+
98
+ if not result.get('success'):
99
+ logger.warning("chat failed: %s", result.get('error'))
100
+ return f"Error: {result.get('error', 'Unknown error')}"
101
+
102
+ assistant_content = result.get('content', '')
103
+ logger.info("chat success model=%s", result.get('model'))
104
+
105
+ # 添加助手回复
106
+ self.messages.append(Message(role="assistant", content=assistant_content))
107
+
108
+ return assistant_content
109
+
110
+ def execute_tool(self, tool_name: str, **kwargs) -> Dict[str, Any]:
111
+ """
112
+ 执行工具
113
+ 整合了 Codex 的终端执行 + OpenClaw 的浏览器控制
114
+ """
115
+ if not self.tools_enabled:
116
+ return {'success': False, 'error': 'Tools disabled'}
117
+
118
+ logger.info("execute tool=%s args=%s", tool_name, kwargs)
119
+ result = registry.execute(tool_name, **kwargs)
120
+ logger.info("execute tool=%s result=%s", tool_name, result.get('success'))
121
+
122
+ # 记录工具调用
123
+ self.tool_calls.append(ToolCall(
124
+ id=f"call_{len(self.tool_calls)}",
125
+ name=tool_name,
126
+ arguments=kwargs,
127
+ result=result,
128
+ ))
129
+
130
+ return result
131
+
132
+ def list_tools(self) -> List[Dict[str, str]]:
133
+ """列出可用工具"""
134
+ return registry.list_tools()
135
+
136
+ def clear_history(self):
137
+ """清空对话历史"""
138
+ self.messages = [self.messages[0]] # 保留系统消息
139
+ self.tool_calls = []
140
+
141
+
142
+ def create_agent(system_prompt: Optional[str] = None) -> Agent:
143
+ """创建 Agent 实例"""
144
+ return Agent(system_prompt=system_prompt)