actflare 0.1.3__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.
- actflare-0.1.3/PKG-INFO +363 -0
- actflare-0.1.3/README.md +329 -0
- actflare-0.1.3/actflare/__init__.py +14 -0
- actflare-0.1.3/actflare/agent.py +88 -0
- actflare-0.1.3/actflare/cli.py +166 -0
- actflare-0.1.3/actflare/config.example.yml +77 -0
- actflare-0.1.3/actflare/config.py +144 -0
- actflare-0.1.3/actflare/crypto.py +141 -0
- actflare-0.1.3/actflare/dispatcher.py +429 -0
- actflare-0.1.3/actflare/main.py +81 -0
- actflare-0.1.3/actflare/memory.py +177 -0
- actflare-0.1.3/actflare/skills/data_io.md +106 -0
- actflare-0.1.3/actflare/skills.py +161 -0
- actflare-0.1.3/actflare/task_db.py +134 -0
- actflare-0.1.3/actflare/tasks.py +65 -0
- actflare-0.1.3/actflare/tools.example.yml +44 -0
- actflare-0.1.3/actflare/wechat.py +76 -0
- actflare-0.1.3/pyproject.toml +53 -0
actflare-0.1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: actflare
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: WeChat Work callback service powered by Claude Agent SDK
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: wechat,wecom,claude,agent,chatbot
|
|
7
|
+
Author: Zan Yuan
|
|
8
|
+
Author-email: yfinddream@gmail.com
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Framework :: FastAPI
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Communications :: Chat
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Dist: claude-agent-sdk (>=0.1.0)
|
|
23
|
+
Requires-Dist: click (>=8.0,<9.0)
|
|
24
|
+
Requires-Dist: fastapi (>=0.110.0,<0.111.0)
|
|
25
|
+
Requires-Dist: httpx (>=0.27.0,<0.28.0)
|
|
26
|
+
Requires-Dist: huey (>=2.5.0,<3.0.0)
|
|
27
|
+
Requires-Dist: pycryptodome (>=3.20.0,<4.0.0)
|
|
28
|
+
Requires-Dist: pyyaml (>=6.0,<7.0)
|
|
29
|
+
Requires-Dist: uvicorn (>=0.29.0,<0.30.0)
|
|
30
|
+
Project-URL: Bug Tracker, https://github.com/seqyuan/actflare/issues
|
|
31
|
+
Project-URL: Homepage, https://github.com/seqyuan/actflare
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# ActFlare
|
|
35
|
+
|
|
36
|
+
企业微信 (WeChat Work) 回调服务,基于 Claude Agent SDK。接收用户消息,通过 Claude CLI 异步处理,将回复推送回企业微信。
|
|
37
|
+
|
|
38
|
+
## 特性
|
|
39
|
+
|
|
40
|
+
- **企业微信对接** — AES-256-CBC 消息加解密、签名校验、回调 URL 验证
|
|
41
|
+
- **异步任务队列** — SQLite 驱动的 Huey 队列,无需 Redis
|
|
42
|
+
- **Claude Agent SDK** — 可配置工具、系统提示词、环境变量和 CLI 参数
|
|
43
|
+
- **记忆系统** — 自动保存多轮成功案例,后续相似问题时注入历史参考
|
|
44
|
+
- **代理友好** — 支持自定义 `ANTHROPIC_BASE_URL` 和模型映射
|
|
45
|
+
- **工具调度** — 通过 YAML 注册表将生物信息学工具调度到 annoeva 或 annotask 执行
|
|
46
|
+
- **Skills 系统** — 可编辑的领域知识文件,注入 Agent 上下文,支持自改进
|
|
47
|
+
|
|
48
|
+
## 架构
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
用户消息 → 企业微信(加密 POST) → FastAPI(解密验签) → Huey 队列 → 立即响应微信
|
|
52
|
+
|
|
53
|
+
Worker 取任务 → 查询记忆库 → 拼接历史案例 → 调用 Claude CLI
|
|
54
|
+
→ 收集结果 → 截断至 2000 字 → 推送至企业微信 → 用户收到回复
|
|
55
|
+
→ 多轮成功案例自动存入记忆库
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 安装
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install actflare
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
从源码安装:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
git clone https://github.com/seqyuan/actflare.git
|
|
68
|
+
cd actflare
|
|
69
|
+
poetry install
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 快速开始
|
|
73
|
+
|
|
74
|
+
### 1. 首次运行
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
actflare server
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
首次运行会自动在 `~/.config/actflare/config.yml` 创建默认配置文件,然后编辑它:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
vim ~/.config/actflare/config.yml
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. 配置必填项
|
|
87
|
+
|
|
88
|
+
以下字段**必须**修改为你的实际值:
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
paths:
|
|
92
|
+
claude_cli: "/path/to/claude" # Claude CLI 可执行文件路径
|
|
93
|
+
|
|
94
|
+
wechat:
|
|
95
|
+
corpid: "ww1234567890abcdef" # 企业 ID
|
|
96
|
+
token: "your_callback_token" # 回调 Token
|
|
97
|
+
encoding_aes_key: "43位Base64编码AES密钥" # 回调 EncodingAESKey
|
|
98
|
+
agent_id: 1000002 # 应用 AgentID
|
|
99
|
+
corpsecret: "your_corpsecret" # 应用 Secret
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
如果使用代理服务器访问 Claude API,还需配置:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
agent:
|
|
106
|
+
env:
|
|
107
|
+
ANTHROPIC_BASE_URL: "http://your-proxy:3001"
|
|
108
|
+
ANTHROPIC_AUTH_TOKEN: "your-api-key"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 3. 启动服务
|
|
112
|
+
|
|
113
|
+
需要同时运行两个进程:API 服务器和任务 Worker。
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# 终端 1 — API 服务器
|
|
117
|
+
actflare server
|
|
118
|
+
|
|
119
|
+
# 终端 2 — 任务 Worker
|
|
120
|
+
actflare worker
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 4. 配置企业微信回调
|
|
124
|
+
|
|
125
|
+
在[企业微信管理后台](https://work.weixin.qq.com/)中,将回调 URL 设为:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
http://your-server:8001/callback
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Token 和 EncodingAESKey 填写与配置文件中相同的值。
|
|
132
|
+
|
|
133
|
+
## 命令参考
|
|
134
|
+
|
|
135
|
+
### `actflare server`
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
actflare server # 使用默认配置
|
|
139
|
+
actflare server -c /path/to/config.yml # 指定配置文件
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### `actflare worker`
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
actflare worker # 使用默认配置
|
|
146
|
+
actflare worker -c /path/to/config.yml # 指定配置文件
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### `actflare tools`
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
actflare tools # 列出所有已注册的工具
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `actflare dispatch`
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
actflare dispatch scrna_pipeline # annoeva 工具(无需输入文件)
|
|
159
|
+
actflare dispatch bindiff /data/tasks.sh # annotask 工具(需要输入文件)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### `actflare status`
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
actflare status <task_id> # 查询任务运行状态
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### `actflare skills`
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
actflare skills # 列出已加载的 skill 文件
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
配置文件查找顺序:
|
|
175
|
+
|
|
176
|
+
1. `-c` 参数指定的路径
|
|
177
|
+
2. `ACTFLARE_CONFIG` 环境变量
|
|
178
|
+
3. `~/.config/actflare/config.yml`
|
|
179
|
+
|
|
180
|
+
## 工具注册与调度
|
|
181
|
+
|
|
182
|
+
actflare 通过 YAML 注册表管理可调度的生物信息学工具。Claude Agent 自动识别已注册工具,用户通过自然语言请求即可触发执行。
|
|
183
|
+
|
|
184
|
+
### 注册表位置
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
~/.config/actflare/tools.yml
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
首次运行 `actflare tools` 或 `actflare dispatch` 时从模板自动创建。
|
|
191
|
+
|
|
192
|
+
### 工具分类
|
|
193
|
+
|
|
194
|
+
工具只有两种后端:
|
|
195
|
+
|
|
196
|
+
| 后端 | 执行命令 | 说明 |
|
|
197
|
+
|------|---------|------|
|
|
198
|
+
| `annoeva` | `annoeva addproject -p <task_id> -t <type> -d <workdir>` | 项目级流水线管理 |
|
|
199
|
+
| `annotask` | `annotask qsubsge/local <tool_path> -i <infile> ...` | 并行任务执行 |
|
|
200
|
+
|
|
201
|
+
### 注册新工具
|
|
202
|
+
|
|
203
|
+
编辑 `tools.yml`,在 `tools:` 下添加条目:
|
|
204
|
+
|
|
205
|
+
**annoeva 工具** — 只需 `description`、`backend`、`type`:
|
|
206
|
+
|
|
207
|
+
```yaml
|
|
208
|
+
tools:
|
|
209
|
+
scrna_pipeline:
|
|
210
|
+
description: "单细胞 RNA-seq 全流程分析"
|
|
211
|
+
backend: annoeva
|
|
212
|
+
type: scrna
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**annotask 工具 (qsubsge)** — 需要 `tool_path`,固定参数 `line`、`cpu`、`h_vmem`:
|
|
216
|
+
|
|
217
|
+
```yaml
|
|
218
|
+
bindiff:
|
|
219
|
+
description: "差异基因分析(SGE 集群并行)"
|
|
220
|
+
backend: annotask
|
|
221
|
+
tool_path: "/path/to/bindiff"
|
|
222
|
+
mode: qsubsge
|
|
223
|
+
line: 2
|
|
224
|
+
cpu: 2
|
|
225
|
+
h_vmem: 8
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**annotask 工具 (local)** — 需要 `tool_path`,固定参数 `line`、`thread`:
|
|
229
|
+
|
|
230
|
+
```yaml
|
|
231
|
+
bindiff_local:
|
|
232
|
+
description: "差异基因分析(本地并行)"
|
|
233
|
+
backend: annotask
|
|
234
|
+
tool_path: "/path/to/bindiff"
|
|
235
|
+
mode: local
|
|
236
|
+
line: 1
|
|
237
|
+
thread: 4
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 目录自动创建
|
|
241
|
+
|
|
242
|
+
调度任务时自动创建工作目录(基于 `config.yml` 中的 `workdir` 配置):
|
|
243
|
+
|
|
244
|
+
- **annoeva 任务**: `{workdir}/annoeva/{task_id}/` 含 `Analysis/`、`info/info.xls`、`Filter/GO.sign`
|
|
245
|
+
- **annotask 任务**: `{workdir}/annotask/{task_id}/`
|
|
246
|
+
|
|
247
|
+
### 任务跟踪
|
|
248
|
+
|
|
249
|
+
每次调度自动生成唯一任务 ID(如 `scrna_pipeline_20260223_a1b2c3`)并记录到 SQLite 数据库,支持状态查询:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
actflare status scrna_pipeline_20260223_a1b2c3
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 调度方式
|
|
256
|
+
|
|
257
|
+
**CLI 手动调度:**
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
actflare dispatch scrna_pipeline # annoeva 流水线
|
|
261
|
+
actflare dispatch bindiff /data/tasks.sh # annotask 集群任务
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Agent 自动调度:**
|
|
265
|
+
|
|
266
|
+
已注册工具会自动注入 Agent 的系统提示词。用户在企业微信中发送类似「帮我跑一下单细胞分析」的消息,Agent 会自动识别并调用对应工具。
|
|
267
|
+
|
|
268
|
+
## Skills 系统
|
|
269
|
+
|
|
270
|
+
Skills 是可编辑的 Markdown 知识文件,自动注入 Agent 的 system prompt,让 Agent 掌握公司特有的数据目录规范、路径模式等领域知识。
|
|
271
|
+
|
|
272
|
+
### 加载顺序
|
|
273
|
+
|
|
274
|
+
Skills 从两个目录加载(同名文件以全局目录为准):
|
|
275
|
+
|
|
276
|
+
1. `~/.config/actflare/skills/` — 全局 skills(默认优先)
|
|
277
|
+
2. `{workspace}/skills/` — 项目级 skills(补充)
|
|
278
|
+
|
|
279
|
+
首次运行时自动从模板创建全局 skills 目录。
|
|
280
|
+
|
|
281
|
+
### 内置 Skill
|
|
282
|
+
|
|
283
|
+
| 文件 | 内容 |
|
|
284
|
+
|------|------|
|
|
285
|
+
| `data_io.md` | 数据 I/O 规范:项目目录结构、分析/过滤目录位置、云端路径、CellRanger 数据 |
|
|
286
|
+
|
|
287
|
+
### 自改进机制
|
|
288
|
+
|
|
289
|
+
Agent 拥有 Edit/Write 权限,可以直接修改 skill 文件。当 Agent 在实践中发现更准确的规律(如新的路径模式、目录结构变更),会自动更新对应的 skill 文件,形成 **memory 记住具体案例 + skill 记住通用规律** 的双层知识体系。
|
|
290
|
+
|
|
291
|
+
### 添加新 Skill
|
|
292
|
+
|
|
293
|
+
在 `~/.config/actflare/skills/` 目录下创建 `.md` 文件即可:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
vim ~/.config/actflare/skills/my_knowledge.md
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**注意**: skills 文件可能包含公司内部路径等敏感信息,已在 `.gitignore` 中排除。
|
|
300
|
+
|
|
301
|
+
## 配置说明
|
|
302
|
+
|
|
303
|
+
完整示例见 [`config.example.yml`](config.example.yml)。
|
|
304
|
+
|
|
305
|
+
`paths` 中的相对路径基于配置文件所在目录解析(即 `~/.config/actflare/`)。
|
|
306
|
+
|
|
307
|
+
### paths
|
|
308
|
+
|
|
309
|
+
| 字段 | 默认值 | 说明 |
|
|
310
|
+
|------|--------|------|
|
|
311
|
+
| `claude_cli` | (必填) | Claude CLI 可执行文件的绝对路径 |
|
|
312
|
+
| `huey_db` | `./data/huey.db` | Huey 任务队列 SQLite 数据库 |
|
|
313
|
+
| `memory_db` | `./data/memory.db` | 记忆系统 SQLite 数据库 |
|
|
314
|
+
| `workspace` | `./workspace` | Claude Agent 文件操作的工作目录 |
|
|
315
|
+
| `tools_yml` | (空) | 工具注册表路径,空则使用 `~/.config/actflare/tools.yml` |
|
|
316
|
+
| `workdir` | `./workdir` | 任务根目录(annoeva/annotask 任务在此创建) |
|
|
317
|
+
| `task_db` | `./data/task.db` | 任务跟踪 SQLite 数据库 |
|
|
318
|
+
|
|
319
|
+
### wechat
|
|
320
|
+
|
|
321
|
+
| 字段 | 说明 |
|
|
322
|
+
|------|------|
|
|
323
|
+
| `corpid` | 企业微信 Corp ID |
|
|
324
|
+
| `token` | 回调验证 Token |
|
|
325
|
+
| `encoding_aes_key` | 43 位 Base64 编码 AES 密钥 |
|
|
326
|
+
| `agent_id` | 应用 AgentID (整数) |
|
|
327
|
+
| `corpsecret` | 应用 Secret |
|
|
328
|
+
|
|
329
|
+
### agent
|
|
330
|
+
|
|
331
|
+
| 字段 | 默认值 | 说明 |
|
|
332
|
+
|------|--------|------|
|
|
333
|
+
| `max_turns` | `10` | 单次请求最大 Agent 轮次 |
|
|
334
|
+
| `allowed_tools` | `[Read, Glob, Grep, Bash, Edit, Write]` | Agent 可用工具列表 |
|
|
335
|
+
| `system_prompt` | `你是企业内部开发助手...` | 系统提示词 |
|
|
336
|
+
| `permission_mode` | `bypassPermissions` | 权限模式 |
|
|
337
|
+
| `model` | `null` | 模型覆盖,`null` 使用 SDK 默认值 |
|
|
338
|
+
| `env` | `{}` | 注入 Claude CLI 子进程的环境变量 |
|
|
339
|
+
| `cli_args` | `[]` | 追加到 Claude CLI 的额外参数 |
|
|
340
|
+
|
|
341
|
+
### server / worker
|
|
342
|
+
|
|
343
|
+
| 字段 | 默认值 | 说明 |
|
|
344
|
+
|------|--------|------|
|
|
345
|
+
| `server.host` | `0.0.0.0` | 服务器绑定地址 |
|
|
346
|
+
| `server.port` | `8001` | 服务器端口 |
|
|
347
|
+
| `worker.concurrency` | `2` | Worker 并发数 |
|
|
348
|
+
| `worker.worker_type` | `process` | `process` 或 `thread` |
|
|
349
|
+
|
|
350
|
+
## 开发
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
git clone https://github.com/seqyuan/actflare.git
|
|
354
|
+
cd actflare
|
|
355
|
+
poetry install
|
|
356
|
+
poetry run pytest
|
|
357
|
+
poetry run black actflare/
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## License
|
|
361
|
+
|
|
362
|
+
MIT
|
|
363
|
+
|
actflare-0.1.3/README.md
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# ActFlare
|
|
2
|
+
|
|
3
|
+
企业微信 (WeChat Work) 回调服务,基于 Claude Agent SDK。接收用户消息,通过 Claude CLI 异步处理,将回复推送回企业微信。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- **企业微信对接** — AES-256-CBC 消息加解密、签名校验、回调 URL 验证
|
|
8
|
+
- **异步任务队列** — SQLite 驱动的 Huey 队列,无需 Redis
|
|
9
|
+
- **Claude Agent SDK** — 可配置工具、系统提示词、环境变量和 CLI 参数
|
|
10
|
+
- **记忆系统** — 自动保存多轮成功案例,后续相似问题时注入历史参考
|
|
11
|
+
- **代理友好** — 支持自定义 `ANTHROPIC_BASE_URL` 和模型映射
|
|
12
|
+
- **工具调度** — 通过 YAML 注册表将生物信息学工具调度到 annoeva 或 annotask 执行
|
|
13
|
+
- **Skills 系统** — 可编辑的领域知识文件,注入 Agent 上下文,支持自改进
|
|
14
|
+
|
|
15
|
+
## 架构
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
用户消息 → 企业微信(加密 POST) → FastAPI(解密验签) → Huey 队列 → 立即响应微信
|
|
19
|
+
|
|
20
|
+
Worker 取任务 → 查询记忆库 → 拼接历史案例 → 调用 Claude CLI
|
|
21
|
+
→ 收集结果 → 截断至 2000 字 → 推送至企业微信 → 用户收到回复
|
|
22
|
+
→ 多轮成功案例自动存入记忆库
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install actflare
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
从源码安装:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/seqyuan/actflare.git
|
|
35
|
+
cd actflare
|
|
36
|
+
poetry install
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 快速开始
|
|
40
|
+
|
|
41
|
+
### 1. 首次运行
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
actflare server
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
首次运行会自动在 `~/.config/actflare/config.yml` 创建默认配置文件,然后编辑它:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
vim ~/.config/actflare/config.yml
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. 配置必填项
|
|
54
|
+
|
|
55
|
+
以下字段**必须**修改为你的实际值:
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
paths:
|
|
59
|
+
claude_cli: "/path/to/claude" # Claude CLI 可执行文件路径
|
|
60
|
+
|
|
61
|
+
wechat:
|
|
62
|
+
corpid: "ww1234567890abcdef" # 企业 ID
|
|
63
|
+
token: "your_callback_token" # 回调 Token
|
|
64
|
+
encoding_aes_key: "43位Base64编码AES密钥" # 回调 EncodingAESKey
|
|
65
|
+
agent_id: 1000002 # 应用 AgentID
|
|
66
|
+
corpsecret: "your_corpsecret" # 应用 Secret
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
如果使用代理服务器访问 Claude API,还需配置:
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
agent:
|
|
73
|
+
env:
|
|
74
|
+
ANTHROPIC_BASE_URL: "http://your-proxy:3001"
|
|
75
|
+
ANTHROPIC_AUTH_TOKEN: "your-api-key"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. 启动服务
|
|
79
|
+
|
|
80
|
+
需要同时运行两个进程:API 服务器和任务 Worker。
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# 终端 1 — API 服务器
|
|
84
|
+
actflare server
|
|
85
|
+
|
|
86
|
+
# 终端 2 — 任务 Worker
|
|
87
|
+
actflare worker
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. 配置企业微信回调
|
|
91
|
+
|
|
92
|
+
在[企业微信管理后台](https://work.weixin.qq.com/)中,将回调 URL 设为:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
http://your-server:8001/callback
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Token 和 EncodingAESKey 填写与配置文件中相同的值。
|
|
99
|
+
|
|
100
|
+
## 命令参考
|
|
101
|
+
|
|
102
|
+
### `actflare server`
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
actflare server # 使用默认配置
|
|
106
|
+
actflare server -c /path/to/config.yml # 指定配置文件
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `actflare worker`
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
actflare worker # 使用默认配置
|
|
113
|
+
actflare worker -c /path/to/config.yml # 指定配置文件
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `actflare tools`
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
actflare tools # 列出所有已注册的工具
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `actflare dispatch`
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
actflare dispatch scrna_pipeline # annoeva 工具(无需输入文件)
|
|
126
|
+
actflare dispatch bindiff /data/tasks.sh # annotask 工具(需要输入文件)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### `actflare status`
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
actflare status <task_id> # 查询任务运行状态
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `actflare skills`
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
actflare skills # 列出已加载的 skill 文件
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
配置文件查找顺序:
|
|
142
|
+
|
|
143
|
+
1. `-c` 参数指定的路径
|
|
144
|
+
2. `ACTFLARE_CONFIG` 环境变量
|
|
145
|
+
3. `~/.config/actflare/config.yml`
|
|
146
|
+
|
|
147
|
+
## 工具注册与调度
|
|
148
|
+
|
|
149
|
+
actflare 通过 YAML 注册表管理可调度的生物信息学工具。Claude Agent 自动识别已注册工具,用户通过自然语言请求即可触发执行。
|
|
150
|
+
|
|
151
|
+
### 注册表位置
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
~/.config/actflare/tools.yml
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
首次运行 `actflare tools` 或 `actflare dispatch` 时从模板自动创建。
|
|
158
|
+
|
|
159
|
+
### 工具分类
|
|
160
|
+
|
|
161
|
+
工具只有两种后端:
|
|
162
|
+
|
|
163
|
+
| 后端 | 执行命令 | 说明 |
|
|
164
|
+
|------|---------|------|
|
|
165
|
+
| `annoeva` | `annoeva addproject -p <task_id> -t <type> -d <workdir>` | 项目级流水线管理 |
|
|
166
|
+
| `annotask` | `annotask qsubsge/local <tool_path> -i <infile> ...` | 并行任务执行 |
|
|
167
|
+
|
|
168
|
+
### 注册新工具
|
|
169
|
+
|
|
170
|
+
编辑 `tools.yml`,在 `tools:` 下添加条目:
|
|
171
|
+
|
|
172
|
+
**annoeva 工具** — 只需 `description`、`backend`、`type`:
|
|
173
|
+
|
|
174
|
+
```yaml
|
|
175
|
+
tools:
|
|
176
|
+
scrna_pipeline:
|
|
177
|
+
description: "单细胞 RNA-seq 全流程分析"
|
|
178
|
+
backend: annoeva
|
|
179
|
+
type: scrna
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**annotask 工具 (qsubsge)** — 需要 `tool_path`,固定参数 `line`、`cpu`、`h_vmem`:
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
bindiff:
|
|
186
|
+
description: "差异基因分析(SGE 集群并行)"
|
|
187
|
+
backend: annotask
|
|
188
|
+
tool_path: "/path/to/bindiff"
|
|
189
|
+
mode: qsubsge
|
|
190
|
+
line: 2
|
|
191
|
+
cpu: 2
|
|
192
|
+
h_vmem: 8
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**annotask 工具 (local)** — 需要 `tool_path`,固定参数 `line`、`thread`:
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
bindiff_local:
|
|
199
|
+
description: "差异基因分析(本地并行)"
|
|
200
|
+
backend: annotask
|
|
201
|
+
tool_path: "/path/to/bindiff"
|
|
202
|
+
mode: local
|
|
203
|
+
line: 1
|
|
204
|
+
thread: 4
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### 目录自动创建
|
|
208
|
+
|
|
209
|
+
调度任务时自动创建工作目录(基于 `config.yml` 中的 `workdir` 配置):
|
|
210
|
+
|
|
211
|
+
- **annoeva 任务**: `{workdir}/annoeva/{task_id}/` 含 `Analysis/`、`info/info.xls`、`Filter/GO.sign`
|
|
212
|
+
- **annotask 任务**: `{workdir}/annotask/{task_id}/`
|
|
213
|
+
|
|
214
|
+
### 任务跟踪
|
|
215
|
+
|
|
216
|
+
每次调度自动生成唯一任务 ID(如 `scrna_pipeline_20260223_a1b2c3`)并记录到 SQLite 数据库,支持状态查询:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
actflare status scrna_pipeline_20260223_a1b2c3
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 调度方式
|
|
223
|
+
|
|
224
|
+
**CLI 手动调度:**
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
actflare dispatch scrna_pipeline # annoeva 流水线
|
|
228
|
+
actflare dispatch bindiff /data/tasks.sh # annotask 集群任务
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Agent 自动调度:**
|
|
232
|
+
|
|
233
|
+
已注册工具会自动注入 Agent 的系统提示词。用户在企业微信中发送类似「帮我跑一下单细胞分析」的消息,Agent 会自动识别并调用对应工具。
|
|
234
|
+
|
|
235
|
+
## Skills 系统
|
|
236
|
+
|
|
237
|
+
Skills 是可编辑的 Markdown 知识文件,自动注入 Agent 的 system prompt,让 Agent 掌握公司特有的数据目录规范、路径模式等领域知识。
|
|
238
|
+
|
|
239
|
+
### 加载顺序
|
|
240
|
+
|
|
241
|
+
Skills 从两个目录加载(同名文件以全局目录为准):
|
|
242
|
+
|
|
243
|
+
1. `~/.config/actflare/skills/` — 全局 skills(默认优先)
|
|
244
|
+
2. `{workspace}/skills/` — 项目级 skills(补充)
|
|
245
|
+
|
|
246
|
+
首次运行时自动从模板创建全局 skills 目录。
|
|
247
|
+
|
|
248
|
+
### 内置 Skill
|
|
249
|
+
|
|
250
|
+
| 文件 | 内容 |
|
|
251
|
+
|------|------|
|
|
252
|
+
| `data_io.md` | 数据 I/O 规范:项目目录结构、分析/过滤目录位置、云端路径、CellRanger 数据 |
|
|
253
|
+
|
|
254
|
+
### 自改进机制
|
|
255
|
+
|
|
256
|
+
Agent 拥有 Edit/Write 权限,可以直接修改 skill 文件。当 Agent 在实践中发现更准确的规律(如新的路径模式、目录结构变更),会自动更新对应的 skill 文件,形成 **memory 记住具体案例 + skill 记住通用规律** 的双层知识体系。
|
|
257
|
+
|
|
258
|
+
### 添加新 Skill
|
|
259
|
+
|
|
260
|
+
在 `~/.config/actflare/skills/` 目录下创建 `.md` 文件即可:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
vim ~/.config/actflare/skills/my_knowledge.md
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**注意**: skills 文件可能包含公司内部路径等敏感信息,已在 `.gitignore` 中排除。
|
|
267
|
+
|
|
268
|
+
## 配置说明
|
|
269
|
+
|
|
270
|
+
完整示例见 [`config.example.yml`](config.example.yml)。
|
|
271
|
+
|
|
272
|
+
`paths` 中的相对路径基于配置文件所在目录解析(即 `~/.config/actflare/`)。
|
|
273
|
+
|
|
274
|
+
### paths
|
|
275
|
+
|
|
276
|
+
| 字段 | 默认值 | 说明 |
|
|
277
|
+
|------|--------|------|
|
|
278
|
+
| `claude_cli` | (必填) | Claude CLI 可执行文件的绝对路径 |
|
|
279
|
+
| `huey_db` | `./data/huey.db` | Huey 任务队列 SQLite 数据库 |
|
|
280
|
+
| `memory_db` | `./data/memory.db` | 记忆系统 SQLite 数据库 |
|
|
281
|
+
| `workspace` | `./workspace` | Claude Agent 文件操作的工作目录 |
|
|
282
|
+
| `tools_yml` | (空) | 工具注册表路径,空则使用 `~/.config/actflare/tools.yml` |
|
|
283
|
+
| `workdir` | `./workdir` | 任务根目录(annoeva/annotask 任务在此创建) |
|
|
284
|
+
| `task_db` | `./data/task.db` | 任务跟踪 SQLite 数据库 |
|
|
285
|
+
|
|
286
|
+
### wechat
|
|
287
|
+
|
|
288
|
+
| 字段 | 说明 |
|
|
289
|
+
|------|------|
|
|
290
|
+
| `corpid` | 企业微信 Corp ID |
|
|
291
|
+
| `token` | 回调验证 Token |
|
|
292
|
+
| `encoding_aes_key` | 43 位 Base64 编码 AES 密钥 |
|
|
293
|
+
| `agent_id` | 应用 AgentID (整数) |
|
|
294
|
+
| `corpsecret` | 应用 Secret |
|
|
295
|
+
|
|
296
|
+
### agent
|
|
297
|
+
|
|
298
|
+
| 字段 | 默认值 | 说明 |
|
|
299
|
+
|------|--------|------|
|
|
300
|
+
| `max_turns` | `10` | 单次请求最大 Agent 轮次 |
|
|
301
|
+
| `allowed_tools` | `[Read, Glob, Grep, Bash, Edit, Write]` | Agent 可用工具列表 |
|
|
302
|
+
| `system_prompt` | `你是企业内部开发助手...` | 系统提示词 |
|
|
303
|
+
| `permission_mode` | `bypassPermissions` | 权限模式 |
|
|
304
|
+
| `model` | `null` | 模型覆盖,`null` 使用 SDK 默认值 |
|
|
305
|
+
| `env` | `{}` | 注入 Claude CLI 子进程的环境变量 |
|
|
306
|
+
| `cli_args` | `[]` | 追加到 Claude CLI 的额外参数 |
|
|
307
|
+
|
|
308
|
+
### server / worker
|
|
309
|
+
|
|
310
|
+
| 字段 | 默认值 | 说明 |
|
|
311
|
+
|------|--------|------|
|
|
312
|
+
| `server.host` | `0.0.0.0` | 服务器绑定地址 |
|
|
313
|
+
| `server.port` | `8001` | 服务器端口 |
|
|
314
|
+
| `worker.concurrency` | `2` | Worker 并发数 |
|
|
315
|
+
| `worker.worker_type` | `process` | `process` 或 `thread` |
|
|
316
|
+
|
|
317
|
+
## 开发
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
git clone https://github.com/seqyuan/actflare.git
|
|
321
|
+
cd actflare
|
|
322
|
+
poetry install
|
|
323
|
+
poetry run pytest
|
|
324
|
+
poetry run black actflare/
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## License
|
|
328
|
+
|
|
329
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ActFlare: WeChat Work callback service powered by Claude Agent SDK.
|
|
3
|
+
|
|
4
|
+
Receives messages from WeChat Work, processes them asynchronously via
|
|
5
|
+
Claude Agent SDK, and pushes replies back to WeChat Work.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
__author__ = "Zan Yuan"
|
|
10
|
+
__email__ = "yfinddream@gmail.com"
|
|
11
|
+
|
|
12
|
+
from actflare.config import load_config, get_config
|
|
13
|
+
|
|
14
|
+
__all__ = ["load_config", "get_config"]
|