sra-agent 1.2.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.
- sra_agent-1.2.0/LICENSE +21 -0
- sra_agent-1.2.0/PKG-INFO +338 -0
- sra_agent-1.2.0/README.md +311 -0
- sra_agent-1.2.0/pyproject.toml +52 -0
- sra_agent-1.2.0/setup.cfg +4 -0
- sra_agent-1.2.0/setup.py +19 -0
- sra_agent-1.2.0/skill_advisor/__init__.py +17 -0
- sra_agent-1.2.0/skill_advisor/adapters/__init__.py +316 -0
- sra_agent-1.2.0/skill_advisor/advisor.py +196 -0
- sra_agent-1.2.0/skill_advisor/cli.py +412 -0
- sra_agent-1.2.0/skill_advisor/indexer.py +189 -0
- sra_agent-1.2.0/skill_advisor/matcher.py +215 -0
- sra_agent-1.2.0/skill_advisor/memory.py +122 -0
- sra_agent-1.2.0/skill_advisor/runtime/daemon.py +742 -0
- sra_agent-1.2.0/skill_advisor/synonyms.py +127 -0
- sra_agent-1.2.0/sra_agent.egg-info/PKG-INFO +338 -0
- sra_agent-1.2.0/sra_agent.egg-info/SOURCES.txt +23 -0
- sra_agent-1.2.0/sra_agent.egg-info/dependency_links.txt +1 -0
- sra_agent-1.2.0/sra_agent.egg-info/entry_points.txt +3 -0
- sra_agent-1.2.0/sra_agent.egg-info/requires.txt +5 -0
- sra_agent-1.2.0/sra_agent.egg-info/top_level.txt +1 -0
- sra_agent-1.2.0/tests/test_benchmark.py +75 -0
- sra_agent-1.2.0/tests/test_coverage.py +229 -0
- sra_agent-1.2.0/tests/test_indexer.py +122 -0
- sra_agent-1.2.0/tests/test_matcher.py +229 -0
sra_agent-1.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SRA Team
|
|
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.
|
sra_agent-1.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sra-agent
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Skill Runtime Advisor — 让 AI Agent 知道自己有什么能力,以及什么时候该用什么能力。带守护进程、多 Agent 适配器、完整 CLI、消息前置推理中间件。
|
|
5
|
+
Author: Emma (SRA Team), Kei
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/JackSmith111977/Hermes-Skill-View
|
|
8
|
+
Project-URL: Repository, https://github.com/JackSmith111977/Hermes-Skill-View.git
|
|
9
|
+
Project-URL: Documentation, https://github.com/JackSmith111977/Hermes-Skill-View#readme
|
|
10
|
+
Keywords: ai-agent,skill-management,runtime-advisor,hermes,llm,daemon
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pyyaml>=5.1
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# SRA — Skill Runtime Advisor 🎯
|
|
29
|
+
|
|
30
|
+
[](https://www.python.org/)
|
|
31
|
+
[](https://github.com/JackSmith111977/Hermes-Skill-View/actions/workflows/ci.yml)
|
|
32
|
+
[](./LICENSE)
|
|
33
|
+
[](https://github.com/JackSmith111977/Hermes-Skill-View)
|
|
34
|
+
[](https://pypi.org/project/sra-agent/)
|
|
35
|
+
|
|
36
|
+
> **为 Hermes Agent 解决技能发现痛点的运行时消息前置推理中间件。**
|
|
37
|
+
> 每次用户消息到达 Agent 之前,先经过 SRA Proxy 语义分析,自动注入最匹配技能(SKILL.md)的 RAG 上下文——让 Agent 永远知道当前任务该用什么能力。
|
|
38
|
+
|
|
39
|
+
🌐 [English README](README_en.md) · 📖 [Runtime Design](./RUNTIME.md) · ⚡ [Quick Install](#安装) · 🩺 [Integration Guide](./docs/INTEGRATION.md)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 📐 架构总览
|
|
44
|
+
|
|
45
|
+
### 消息流时序图
|
|
46
|
+
|
|
47
|
+
```mermaid
|
|
48
|
+
sequenceDiagram
|
|
49
|
+
participant U as 👤 User
|
|
50
|
+
participant SRA as 🎯 SRA Proxy :8536
|
|
51
|
+
participant IDX as 📚 Skill Index
|
|
52
|
+
participant H as 🤖 Hermes Agent
|
|
53
|
+
participant SK as 📁 ~/.hermes/skills/
|
|
54
|
+
|
|
55
|
+
U->>+H: "画个架构图"
|
|
56
|
+
H->>+SRA: POST /recommend {"message":"..."}
|
|
57
|
+
SRA->>+IDX: 语义匹配 (TF-IDF + 同义词)
|
|
58
|
+
IDX-->>-SRA: architecture-diagram (score: 92)
|
|
59
|
+
SRA->>+SK: 读取 SKILL.md 元数据
|
|
60
|
+
SK-->>-SRA: triggers, description, usage
|
|
61
|
+
SRA-->>-H: rag_context + top_skill + should_auto_load
|
|
62
|
+
Note over H: 注入 RAG 上下文到系统提示
|
|
63
|
+
H-->>-U: "好的,为你生成架构图..." + 正确工具调用
|
|
64
|
+
```
|
|
65
|
+
### 组件架构图
|
|
66
|
+
|
|
67
|
+
```mermaid
|
|
68
|
+
flowchart LR
|
|
69
|
+
subgraph Input["📥 输入层"]
|
|
70
|
+
U[User Message<br/>自然语言查询]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
subgraph SRA_MW["🎯 SRA 中间件层"]
|
|
74
|
+
direction TB
|
|
75
|
+
P[SRA Proxy :8536<br/>Unix Socket + HTTP]
|
|
76
|
+
M[匹配引擎<br/>TF-IDF + 同义词 + 共现矩阵]
|
|
77
|
+
I[(Skill Index Store<br/>275+ skills indexed)]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
subgraph Agent["🤖 Agent 消费层"]
|
|
81
|
+
direction TB
|
|
82
|
+
H[Hermes Agent<br/>注入 rag_context]
|
|
83
|
+
T[工具执行<br/>terminal / file / web]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
subgraph Output["📤 输出层"]
|
|
87
|
+
R[Agent Response<br/>正确的技能 + 工具调用]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
SK[~/.hermes/skills/<br/>SKILL.md files]
|
|
91
|
+
|
|
92
|
+
U -->|POST /recommend| P
|
|
93
|
+
P -->|lookup| M
|
|
94
|
+
M -->|query| I
|
|
95
|
+
I -->|scan| SK
|
|
96
|
+
P -->|rag_context + top_skill| H
|
|
97
|
+
H -->|enhanced context| T
|
|
98
|
+
T --> R
|
|
99
|
+
|
|
100
|
+
classDef input fill:#e0f2fe,stroke:#0284c7,color:#0c4a6e
|
|
101
|
+
classDef sra fill:#f0fdf4,stroke:#16a34a,color:#14532d
|
|
102
|
+
classDef agent fill:#fefce8,stroke:#ca8a04,color:#713f12
|
|
103
|
+
classDef output fill:#fce7f3,stroke:#db2777,color:#831843
|
|
104
|
+
classDef storage fill:#f3e8ff,stroke:#9333ea,color:#581c87
|
|
105
|
+
|
|
106
|
+
class U input
|
|
107
|
+
class P,M sra
|
|
108
|
+
class I,SK storage
|
|
109
|
+
class H,T agent
|
|
110
|
+
class R output
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**一句话解释**:用户说"画个架构图" → SRA 在 < 5ms 内找到 `architecture-diagram` 技能 → 把技能的触发词和使用方法注入到 Agent 的上下文 → Agent 立刻知道该用哪个工具。
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 🎯 核心能力
|
|
118
|
+
|
|
119
|
+
| 能力 | 说明 |
|
|
120
|
+
|------|------|
|
|
121
|
+
| **消息前置推理** | 每次用户消息到达 Agent,自动查询最匹配的技能并注入 RAG 上下文 |
|
|
122
|
+
| **语义匹配引擎** | 同义词扩展 + TF-IDF + 共现矩阵混合匹配,不是简单的关键词搜索 |
|
|
123
|
+
| **守护进程** | 7x24 后台运行,Unix Socket + HTTP 双协议,自动定时刷新技能索引 |
|
|
124
|
+
| **覆盖率分析** | 统计哪些技能能被识别、哪些是盲区,驱动技能库质量改进 |
|
|
125
|
+
| **Agent 适配器** | 为 Hermes / Claude / Codex 等 Agent 提供原生格式的输出 |
|
|
126
|
+
| **零侵入集成** | SRA 不修改 Agent 代码,只在消息路径上增加一个 HTTP 调用 |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 🤔 为什么要用 SRA?
|
|
131
|
+
|
|
132
|
+
Hermes Agent 的技能库(`~/.hermes/skills/`)越来越大(60+),但 Agent 面临这些问题:
|
|
133
|
+
|
|
134
|
+
1. **静态列表失效** — `<available_skills>` 列表太长,Agent 经常忽略最合适的技能
|
|
135
|
+
2. **新技能不可见** — 添加一个新的 SKILL.md 后,Agent 不会自动知道它的存在
|
|
136
|
+
3. **没有反馈闭环** — Agent 用了哪个技能、效果如何,完全不可追踪
|
|
137
|
+
4. **发现成本高** — Agent 需要遍历所有技能的 triggers 和 description 才能做出选择
|
|
138
|
+
|
|
139
|
+
**SRA 的解决方案**:在消息路径上插入一个**语义感知层**,用 TF-IDF + 同义词 + 共现矩阵做实时匹配,把最相关的技能上下文在消息处理前就注入给 Agent。
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## ⚡ 安装
|
|
144
|
+
|
|
145
|
+
### 方式一:pip 安装(推荐)
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pip install sra-agent
|
|
149
|
+
sra version # 验证安装
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 方式二:一键脚本(自动配置)
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
curl -fsSL https://raw.githubusercontent.com/JackSmith111977/Hermes-Skill-View/main/scripts/install.sh | bash
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 方式三:源码安装
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
git clone https://github.com/JackSmith111977/Hermes-Skill-View.git
|
|
162
|
+
cd Hermes-Skill-View
|
|
163
|
+
pip install -e .
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 方式四:Proxy 模式(消息前置推理)
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
bash scripts/install.sh --proxy
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 🚀 快速开始
|
|
175
|
+
|
|
176
|
+
### 1. 启动守护进程
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
sra start
|
|
180
|
+
# 预期输出: SRA Daemon 运行中...
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 2. 查询技能推荐
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
sra recommend "画个架构图"
|
|
187
|
+
# 预期输出: -> 推荐技能: architecture-diagram, 得分: 92, 置信度: high
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 3. 检查状态
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
sra status
|
|
194
|
+
# 预期输出: 运行状态、技能数量、版本
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### 4. Proxy 模式(消息前置推理)
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
curl -s -X POST http://127.0.0.1:8536/recommend \
|
|
201
|
+
-H "Content-Type: application/json" \
|
|
202
|
+
-d '{"message": "画个架构图"}'
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
返回示例:
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"top_skill": "architecture-diagram",
|
|
209
|
+
"should_auto_load": true,
|
|
210
|
+
"rag_context": "[SRA] 推荐加载 architecture-diagram 技能:用于生成暗色主题的系统架构图...",
|
|
211
|
+
"recommendations": [
|
|
212
|
+
{"name": "architecture-diagram", "score": 92, "confidence": "high"},
|
|
213
|
+
{"name": "excalidraw", "score": 67, "confidence": "medium"}
|
|
214
|
+
],
|
|
215
|
+
"timing_ms": 4.2
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 5. 集成到 Hermes Agent
|
|
220
|
+
|
|
221
|
+
在 SOUL.md 或 AGENTS.md 中添加消息前置推理规则:
|
|
222
|
+
|
|
223
|
+
```yaml
|
|
224
|
+
# 每条用户消息到达 Agent 前,先调 SRA
|
|
225
|
+
pre_process:
|
|
226
|
+
- curl -s -X POST http://127.0.0.1:8536/recommend
|
|
227
|
+
-H "Content-Type: application/json"
|
|
228
|
+
-d '{"message": "<用户消息原文>"}'
|
|
229
|
+
- 将返回的 rag_context 注入到 Agent 的系统提示中
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## 🔧 命令大全
|
|
235
|
+
|
|
236
|
+
| 命令 | 说明 |
|
|
237
|
+
|------|------|
|
|
238
|
+
| `sra start` | 启动守护进程 |
|
|
239
|
+
| `sra stop` | 停止守护进程 |
|
|
240
|
+
| `sra status` | 查看运行状态 |
|
|
241
|
+
| `sra restart` | 重启守护进程 |
|
|
242
|
+
| `sra attach` | 前台运行(调试用) |
|
|
243
|
+
| `sra recommend <输入>` | 查询技能推荐 |
|
|
244
|
+
| `sra query <输入>` | 同 recommend |
|
|
245
|
+
| `sra coverage` | 分析技能识别覆盖率 |
|
|
246
|
+
| `sra stats` | 查看运行统计 |
|
|
247
|
+
| `sra refresh` | 刷新技能索引 |
|
|
248
|
+
| `sra record <技能> <输入>` | 记录技能使用 |
|
|
249
|
+
| `sra config [show\|set\|reset]` | 配置管理 |
|
|
250
|
+
| `sra adapters` | 列出支持的 Agent 类型 |
|
|
251
|
+
| `sra install <agent>` | 安装到指定 Agent |
|
|
252
|
+
| `sra version` | 显示版本 |
|
|
253
|
+
| `sra help` | 显示帮助 |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## 🔌 Proxy API
|
|
258
|
+
|
|
259
|
+
| 端点 | 方法 | 说明 |
|
|
260
|
+
|------|------|------|
|
|
261
|
+
| `/health` | GET | 健康检查 |
|
|
262
|
+
| `/status` | GET | 详细运行状态 |
|
|
263
|
+
| `/stats` | GET | 统计信息 |
|
|
264
|
+
| `/recommend?q=<查询>` | GET | 技能推荐(GET 方式) |
|
|
265
|
+
| `/recommend` | POST | 技能推荐(POST 方式,JSON body) |
|
|
266
|
+
| `/record` | POST | 记录技能使用 |
|
|
267
|
+
| `/refresh` | POST | 刷新技能索引 |
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## 💡 设计哲学
|
|
272
|
+
|
|
273
|
+
SRA 以三个原则指导其作为运行时的设计:
|
|
274
|
+
|
|
275
|
+
1. **消息优先于工具** — SRA 不是 Agent 主动加载的"技能",而是 Agent 收到每条消息时**被动触发**的中间件。它不改变 Agent 的行为,只增强 Agent 的上下文。
|
|
276
|
+
2. **AI 可观测性优先** — 每个组件必须有状态反馈(ok / warn / error),AI 永远知道"当前状态是什么"和"下一步该怎么做"
|
|
277
|
+
3. **渐进式披露** — README(入口)→ RUNTIME.md(运行时设计)→ docs/(详细文档),按需深入
|
|
278
|
+
|
|
279
|
+
> 📖 完整的运行时设计文档请看 [RUNTIME.md](./RUNTIME.md)
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## 📊 环境检查
|
|
284
|
+
|
|
285
|
+
安装后运行以下命令确认全部就绪:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
python3 scripts/check-sra.py
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
预期输出:
|
|
292
|
+
```
|
|
293
|
+
python: ok (3.11.5)
|
|
294
|
+
sra cli: ok (sra v1.1.0)
|
|
295
|
+
sra daemon: ok (port 8536, 275 skills indexed)
|
|
296
|
+
skills dir: ok (~/.hermes/skills, 62 skills)
|
|
297
|
+
sra config: ok (~/.sra/config.json)
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## 🗺️ 路线图
|
|
303
|
+
|
|
304
|
+
| 优先级 | 改进项 | 目标 |
|
|
305
|
+
|--------|--------|------|
|
|
306
|
+
| 🔴 P0 | 修复 watch_skills_dir 文件监听 | 新技能秒级感知 |
|
|
307
|
+
| 🔴 P0 | 改进中文匹配精度 | 覆盖率提升至 95%+ |
|
|
308
|
+
| 🟡 P1 | 自动 Agent 集成脚本 | 一条命令完成所有配置 |
|
|
309
|
+
| 🟡 P1 | 推荐反馈闭环自动化 | Agent 使用技能后自动记录 |
|
|
310
|
+
| 🟢 P2 | 推荐质量仪表盘 | 可视化展示推荐命中率 |
|
|
311
|
+
|
|
312
|
+
### 远期愿景
|
|
313
|
+
|
|
314
|
+
- **主动学习**:根据场景记忆自动调整推荐权重,高频场景更快匹配
|
|
315
|
+
- **多级推荐**:不仅是 skill 级别,还能推荐 skill 内的具体章节
|
|
316
|
+
- **Agent 反馈回路**:Agent 用了推荐技能后自动反馈结果给 SRA
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## ❓ FAQ
|
|
321
|
+
|
|
322
|
+
**Q: sra 命令找不到?**
|
|
323
|
+
检查 PATH 是否包含 `~/.local/bin`,或运行 `pip install sra-agent` 重试。
|
|
324
|
+
|
|
325
|
+
**Q: 守护进程启动失败?**
|
|
326
|
+
先运行 `python3 scripts/check-sra.py` 诊断环境,针对未通过项修复。
|
|
327
|
+
|
|
328
|
+
**Q: Proxy 模式不工作?**
|
|
329
|
+
确认守护进程运行中,端口 8536 可用。运行 `sra status` 检查。
|
|
330
|
+
|
|
331
|
+
**Q: 支持哪些 Agent?**
|
|
332
|
+
目前支持 Hermes Agent(原生适配),也兼容任何能通过 HTTP 调用的 Agent(Claude Code、Codex CLI 等)。
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 📝 许可证
|
|
337
|
+
|
|
338
|
+
MIT — 详见 [LICENSE](./LICENSE)
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# SRA — Skill Runtime Advisor 🎯
|
|
2
|
+
|
|
3
|
+
[](https://www.python.org/)
|
|
4
|
+
[](https://github.com/JackSmith111977/Hermes-Skill-View/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](https://github.com/JackSmith111977/Hermes-Skill-View)
|
|
7
|
+
[](https://pypi.org/project/sra-agent/)
|
|
8
|
+
|
|
9
|
+
> **为 Hermes Agent 解决技能发现痛点的运行时消息前置推理中间件。**
|
|
10
|
+
> 每次用户消息到达 Agent 之前,先经过 SRA Proxy 语义分析,自动注入最匹配技能(SKILL.md)的 RAG 上下文——让 Agent 永远知道当前任务该用什么能力。
|
|
11
|
+
|
|
12
|
+
🌐 [English README](README_en.md) · 📖 [Runtime Design](./RUNTIME.md) · ⚡ [Quick Install](#安装) · 🩺 [Integration Guide](./docs/INTEGRATION.md)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 📐 架构总览
|
|
17
|
+
|
|
18
|
+
### 消息流时序图
|
|
19
|
+
|
|
20
|
+
```mermaid
|
|
21
|
+
sequenceDiagram
|
|
22
|
+
participant U as 👤 User
|
|
23
|
+
participant SRA as 🎯 SRA Proxy :8536
|
|
24
|
+
participant IDX as 📚 Skill Index
|
|
25
|
+
participant H as 🤖 Hermes Agent
|
|
26
|
+
participant SK as 📁 ~/.hermes/skills/
|
|
27
|
+
|
|
28
|
+
U->>+H: "画个架构图"
|
|
29
|
+
H->>+SRA: POST /recommend {"message":"..."}
|
|
30
|
+
SRA->>+IDX: 语义匹配 (TF-IDF + 同义词)
|
|
31
|
+
IDX-->>-SRA: architecture-diagram (score: 92)
|
|
32
|
+
SRA->>+SK: 读取 SKILL.md 元数据
|
|
33
|
+
SK-->>-SRA: triggers, description, usage
|
|
34
|
+
SRA-->>-H: rag_context + top_skill + should_auto_load
|
|
35
|
+
Note over H: 注入 RAG 上下文到系统提示
|
|
36
|
+
H-->>-U: "好的,为你生成架构图..." + 正确工具调用
|
|
37
|
+
```
|
|
38
|
+
### 组件架构图
|
|
39
|
+
|
|
40
|
+
```mermaid
|
|
41
|
+
flowchart LR
|
|
42
|
+
subgraph Input["📥 输入层"]
|
|
43
|
+
U[User Message<br/>自然语言查询]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
subgraph SRA_MW["🎯 SRA 中间件层"]
|
|
47
|
+
direction TB
|
|
48
|
+
P[SRA Proxy :8536<br/>Unix Socket + HTTP]
|
|
49
|
+
M[匹配引擎<br/>TF-IDF + 同义词 + 共现矩阵]
|
|
50
|
+
I[(Skill Index Store<br/>275+ skills indexed)]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
subgraph Agent["🤖 Agent 消费层"]
|
|
54
|
+
direction TB
|
|
55
|
+
H[Hermes Agent<br/>注入 rag_context]
|
|
56
|
+
T[工具执行<br/>terminal / file / web]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
subgraph Output["📤 输出层"]
|
|
60
|
+
R[Agent Response<br/>正确的技能 + 工具调用]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
SK[~/.hermes/skills/<br/>SKILL.md files]
|
|
64
|
+
|
|
65
|
+
U -->|POST /recommend| P
|
|
66
|
+
P -->|lookup| M
|
|
67
|
+
M -->|query| I
|
|
68
|
+
I -->|scan| SK
|
|
69
|
+
P -->|rag_context + top_skill| H
|
|
70
|
+
H -->|enhanced context| T
|
|
71
|
+
T --> R
|
|
72
|
+
|
|
73
|
+
classDef input fill:#e0f2fe,stroke:#0284c7,color:#0c4a6e
|
|
74
|
+
classDef sra fill:#f0fdf4,stroke:#16a34a,color:#14532d
|
|
75
|
+
classDef agent fill:#fefce8,stroke:#ca8a04,color:#713f12
|
|
76
|
+
classDef output fill:#fce7f3,stroke:#db2777,color:#831843
|
|
77
|
+
classDef storage fill:#f3e8ff,stroke:#9333ea,color:#581c87
|
|
78
|
+
|
|
79
|
+
class U input
|
|
80
|
+
class P,M sra
|
|
81
|
+
class I,SK storage
|
|
82
|
+
class H,T agent
|
|
83
|
+
class R output
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**一句话解释**:用户说"画个架构图" → SRA 在 < 5ms 内找到 `architecture-diagram` 技能 → 把技能的触发词和使用方法注入到 Agent 的上下文 → Agent 立刻知道该用哪个工具。
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## 🎯 核心能力
|
|
91
|
+
|
|
92
|
+
| 能力 | 说明 |
|
|
93
|
+
|------|------|
|
|
94
|
+
| **消息前置推理** | 每次用户消息到达 Agent,自动查询最匹配的技能并注入 RAG 上下文 |
|
|
95
|
+
| **语义匹配引擎** | 同义词扩展 + TF-IDF + 共现矩阵混合匹配,不是简单的关键词搜索 |
|
|
96
|
+
| **守护进程** | 7x24 后台运行,Unix Socket + HTTP 双协议,自动定时刷新技能索引 |
|
|
97
|
+
| **覆盖率分析** | 统计哪些技能能被识别、哪些是盲区,驱动技能库质量改进 |
|
|
98
|
+
| **Agent 适配器** | 为 Hermes / Claude / Codex 等 Agent 提供原生格式的输出 |
|
|
99
|
+
| **零侵入集成** | SRA 不修改 Agent 代码,只在消息路径上增加一个 HTTP 调用 |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 🤔 为什么要用 SRA?
|
|
104
|
+
|
|
105
|
+
Hermes Agent 的技能库(`~/.hermes/skills/`)越来越大(60+),但 Agent 面临这些问题:
|
|
106
|
+
|
|
107
|
+
1. **静态列表失效** — `<available_skills>` 列表太长,Agent 经常忽略最合适的技能
|
|
108
|
+
2. **新技能不可见** — 添加一个新的 SKILL.md 后,Agent 不会自动知道它的存在
|
|
109
|
+
3. **没有反馈闭环** — Agent 用了哪个技能、效果如何,完全不可追踪
|
|
110
|
+
4. **发现成本高** — Agent 需要遍历所有技能的 triggers 和 description 才能做出选择
|
|
111
|
+
|
|
112
|
+
**SRA 的解决方案**:在消息路径上插入一个**语义感知层**,用 TF-IDF + 同义词 + 共现矩阵做实时匹配,把最相关的技能上下文在消息处理前就注入给 Agent。
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## ⚡ 安装
|
|
117
|
+
|
|
118
|
+
### 方式一:pip 安装(推荐)
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install sra-agent
|
|
122
|
+
sra version # 验证安装
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 方式二:一键脚本(自动配置)
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
curl -fsSL https://raw.githubusercontent.com/JackSmith111977/Hermes-Skill-View/main/scripts/install.sh | bash
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 方式三:源码安装
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
git clone https://github.com/JackSmith111977/Hermes-Skill-View.git
|
|
135
|
+
cd Hermes-Skill-View
|
|
136
|
+
pip install -e .
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 方式四:Proxy 模式(消息前置推理)
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
bash scripts/install.sh --proxy
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 🚀 快速开始
|
|
148
|
+
|
|
149
|
+
### 1. 启动守护进程
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
sra start
|
|
153
|
+
# 预期输出: SRA Daemon 运行中...
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 2. 查询技能推荐
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
sra recommend "画个架构图"
|
|
160
|
+
# 预期输出: -> 推荐技能: architecture-diagram, 得分: 92, 置信度: high
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 3. 检查状态
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
sra status
|
|
167
|
+
# 预期输出: 运行状态、技能数量、版本
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 4. Proxy 模式(消息前置推理)
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
curl -s -X POST http://127.0.0.1:8536/recommend \
|
|
174
|
+
-H "Content-Type: application/json" \
|
|
175
|
+
-d '{"message": "画个架构图"}'
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
返回示例:
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"top_skill": "architecture-diagram",
|
|
182
|
+
"should_auto_load": true,
|
|
183
|
+
"rag_context": "[SRA] 推荐加载 architecture-diagram 技能:用于生成暗色主题的系统架构图...",
|
|
184
|
+
"recommendations": [
|
|
185
|
+
{"name": "architecture-diagram", "score": 92, "confidence": "high"},
|
|
186
|
+
{"name": "excalidraw", "score": 67, "confidence": "medium"}
|
|
187
|
+
],
|
|
188
|
+
"timing_ms": 4.2
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### 5. 集成到 Hermes Agent
|
|
193
|
+
|
|
194
|
+
在 SOUL.md 或 AGENTS.md 中添加消息前置推理规则:
|
|
195
|
+
|
|
196
|
+
```yaml
|
|
197
|
+
# 每条用户消息到达 Agent 前,先调 SRA
|
|
198
|
+
pre_process:
|
|
199
|
+
- curl -s -X POST http://127.0.0.1:8536/recommend
|
|
200
|
+
-H "Content-Type: application/json"
|
|
201
|
+
-d '{"message": "<用户消息原文>"}'
|
|
202
|
+
- 将返回的 rag_context 注入到 Agent 的系统提示中
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 🔧 命令大全
|
|
208
|
+
|
|
209
|
+
| 命令 | 说明 |
|
|
210
|
+
|------|------|
|
|
211
|
+
| `sra start` | 启动守护进程 |
|
|
212
|
+
| `sra stop` | 停止守护进程 |
|
|
213
|
+
| `sra status` | 查看运行状态 |
|
|
214
|
+
| `sra restart` | 重启守护进程 |
|
|
215
|
+
| `sra attach` | 前台运行(调试用) |
|
|
216
|
+
| `sra recommend <输入>` | 查询技能推荐 |
|
|
217
|
+
| `sra query <输入>` | 同 recommend |
|
|
218
|
+
| `sra coverage` | 分析技能识别覆盖率 |
|
|
219
|
+
| `sra stats` | 查看运行统计 |
|
|
220
|
+
| `sra refresh` | 刷新技能索引 |
|
|
221
|
+
| `sra record <技能> <输入>` | 记录技能使用 |
|
|
222
|
+
| `sra config [show\|set\|reset]` | 配置管理 |
|
|
223
|
+
| `sra adapters` | 列出支持的 Agent 类型 |
|
|
224
|
+
| `sra install <agent>` | 安装到指定 Agent |
|
|
225
|
+
| `sra version` | 显示版本 |
|
|
226
|
+
| `sra help` | 显示帮助 |
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 🔌 Proxy API
|
|
231
|
+
|
|
232
|
+
| 端点 | 方法 | 说明 |
|
|
233
|
+
|------|------|------|
|
|
234
|
+
| `/health` | GET | 健康检查 |
|
|
235
|
+
| `/status` | GET | 详细运行状态 |
|
|
236
|
+
| `/stats` | GET | 统计信息 |
|
|
237
|
+
| `/recommend?q=<查询>` | GET | 技能推荐(GET 方式) |
|
|
238
|
+
| `/recommend` | POST | 技能推荐(POST 方式,JSON body) |
|
|
239
|
+
| `/record` | POST | 记录技能使用 |
|
|
240
|
+
| `/refresh` | POST | 刷新技能索引 |
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## 💡 设计哲学
|
|
245
|
+
|
|
246
|
+
SRA 以三个原则指导其作为运行时的设计:
|
|
247
|
+
|
|
248
|
+
1. **消息优先于工具** — SRA 不是 Agent 主动加载的"技能",而是 Agent 收到每条消息时**被动触发**的中间件。它不改变 Agent 的行为,只增强 Agent 的上下文。
|
|
249
|
+
2. **AI 可观测性优先** — 每个组件必须有状态反馈(ok / warn / error),AI 永远知道"当前状态是什么"和"下一步该怎么做"
|
|
250
|
+
3. **渐进式披露** — README(入口)→ RUNTIME.md(运行时设计)→ docs/(详细文档),按需深入
|
|
251
|
+
|
|
252
|
+
> 📖 完整的运行时设计文档请看 [RUNTIME.md](./RUNTIME.md)
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 📊 环境检查
|
|
257
|
+
|
|
258
|
+
安装后运行以下命令确认全部就绪:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
python3 scripts/check-sra.py
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
预期输出:
|
|
265
|
+
```
|
|
266
|
+
python: ok (3.11.5)
|
|
267
|
+
sra cli: ok (sra v1.1.0)
|
|
268
|
+
sra daemon: ok (port 8536, 275 skills indexed)
|
|
269
|
+
skills dir: ok (~/.hermes/skills, 62 skills)
|
|
270
|
+
sra config: ok (~/.sra/config.json)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 🗺️ 路线图
|
|
276
|
+
|
|
277
|
+
| 优先级 | 改进项 | 目标 |
|
|
278
|
+
|--------|--------|------|
|
|
279
|
+
| 🔴 P0 | 修复 watch_skills_dir 文件监听 | 新技能秒级感知 |
|
|
280
|
+
| 🔴 P0 | 改进中文匹配精度 | 覆盖率提升至 95%+ |
|
|
281
|
+
| 🟡 P1 | 自动 Agent 集成脚本 | 一条命令完成所有配置 |
|
|
282
|
+
| 🟡 P1 | 推荐反馈闭环自动化 | Agent 使用技能后自动记录 |
|
|
283
|
+
| 🟢 P2 | 推荐质量仪表盘 | 可视化展示推荐命中率 |
|
|
284
|
+
|
|
285
|
+
### 远期愿景
|
|
286
|
+
|
|
287
|
+
- **主动学习**:根据场景记忆自动调整推荐权重,高频场景更快匹配
|
|
288
|
+
- **多级推荐**:不仅是 skill 级别,还能推荐 skill 内的具体章节
|
|
289
|
+
- **Agent 反馈回路**:Agent 用了推荐技能后自动反馈结果给 SRA
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## ❓ FAQ
|
|
294
|
+
|
|
295
|
+
**Q: sra 命令找不到?**
|
|
296
|
+
检查 PATH 是否包含 `~/.local/bin`,或运行 `pip install sra-agent` 重试。
|
|
297
|
+
|
|
298
|
+
**Q: 守护进程启动失败?**
|
|
299
|
+
先运行 `python3 scripts/check-sra.py` 诊断环境,针对未通过项修复。
|
|
300
|
+
|
|
301
|
+
**Q: Proxy 模式不工作?**
|
|
302
|
+
确认守护进程运行中,端口 8536 可用。运行 `sra status` 检查。
|
|
303
|
+
|
|
304
|
+
**Q: 支持哪些 Agent?**
|
|
305
|
+
目前支持 Hermes Agent(原生适配),也兼容任何能通过 HTTP 调用的 Agent(Claude Code、Codex CLI 等)。
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## 📝 许可证
|
|
310
|
+
|
|
311
|
+
MIT — 详见 [LICENSE](./LICENSE)
|