Skip to content

Commit 2a2d4f7

Browse files
author
weiyilan
committed
Sourced-From: d85570d17a49ece78b5e407eeb80d116662ea3c3
0 parents  commit 2a2d4f7

1,878 files changed

Lines changed: 110713 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ENVIRONMENT=local
2+
SERVICE_NAME=genworker
3+
RUNTIME_PROFILE=local
4+
HTTP_HOST=127.0.0.1
5+
HTTP_PORT=8000
6+
LOG_DIR=logs
7+
REDIS_ENABLED=false
8+
MYSQL_ENABLED=false
9+
OPENVIKING_ENABLED=false
10+
IM_CHANNEL_ENABLED=false

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: genworker-ci
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
smoke:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: "3.11"
15+
- run: pip install -r requirements.txt
16+
- run: python .release/genworker/cli.py verify --work-tree .

.release/community-manifest.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
mode: baseline_default
2+
3+
include:
4+
- src/**
5+
- tests/**
6+
- frontend/**
7+
- workspace/**
8+
- start.py
9+
- requirements.txt
10+
- docs/ARCHITECTURE.md
11+
- docs/im-channel-runbook.md
12+
13+
exclude:
14+
- src/enterprise/**
15+
- src/services/mysql/**
16+
- configs/enterprise/**
17+
- docs/internal/**
18+
- tests/enterprise/**
19+
- frontend/node_modules/**
20+
21+
replace_from_overlay:
22+
- README.md
23+
- CONTRIBUTING.md
24+
- LICENSE
25+
- requirements.txt
26+
- .env.example
27+
- .github/workflows/
28+
- scripts/build_frontend.sh
29+
30+
add_from_overlay:
31+
- configs/config.example.env
32+
- configs/profiles/local.env
33+
- configs/profiles/local_memory.env
34+
- configs/profiles/advanced.env
35+
- configs/profiles/enterprise.env
36+
- docs/API.md
37+
- docs/CONFIGURATION.md
38+
- docs/DEPLOYMENT.md
39+
- docs/RELEASE.md
40+
- workspace.example/
41+
42+
string_rewrites:
43+
- match: "genworker"
44+
replace: "genworker"
45+
46+
test_scope:
47+
include_editions: [baseline, community]
48+
exclude_editions: [enterprise]
49+
50+
dependency_allowlist:
51+
- fastapi
52+
- uvicorn
53+
- pydantic
54+
- pydantic-settings
55+
- litellm
56+
- openai
57+
- tiktoken
58+
- openviking
59+
- langgraph
60+
- langchain-core
61+
- langchain-community
62+
- python-frontmatter
63+
- apscheduler
64+
- pandas
65+
- PyYAML
66+
- python-dotenv
67+
- httpx
68+
- requests
69+
- lark-oapi
70+
- dingtalk-stream
71+
- slack_sdk
72+
- redis
73+
- PyJWT
74+
- sse-starlette
75+
- tenacity
76+
- pytest
77+
- pytest-asyncio
78+
- asgi-lifespan

.release/source.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sourced_from": "d85570d17a49ece78b5e407eeb80d116662ea3c3",
3+
"manifest_hash": "9ef8a871f87152053784a955452e464e772b9ca096e33189024e6154d1beeade",
4+
"overlay_hash": "603c8aa3ba17488a92830d1dc68d5e6ee6536904cbedc636e305fa70e6f1b2b6",
5+
"exported_at": "2026-04-23T08:04:38.657192Z",
6+
"exporter_version": "0.3.1"
7+
}

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributing
2+
3+
当前阶段接收 issue 反馈,默认不直接接收对 `main` 的人工 push。

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Apache License 2.0

README.md

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# genworker
2+
3+
[![CI](https://github.com/wyl116/genworker/actions/workflows/ci.yml/badge.svg)](https://github.com/wyl116/genworker/actions/workflows/ci.yml)
4+
![Python](https://img.shields.io/badge/python-3.11%2B-blue)
5+
![Mode](https://img.shields.io/badge/runtime-local--first-2f855a)
6+
![Transport](https://img.shields.io/badge/transport-HTTP%20%2B%20SSE-0ea5e9)
7+
8+
The local-first runtime for digital workers that hold roles, follow rules, and evolve under governance.
9+
10+
[Quick Start](#three-minute-quick-start) | [API](docs/API.md) | [Configuration](docs/CONFIGURATION.md) | [Deployment](docs/DEPLOYMENT.md) | [Architecture](docs/ARCHITECTURE.md)
11+
12+
genworker 是一个面向“数字员工 / 数字工人”场景的 `filesystem-first` runtime。
13+
14+
它不是把一个通用 Agent 包一层 prompt 再长期运行,而是把“岗位”作为系统里的主对象来运行:
15+
16+
- 一个岗位是谁
17+
- 这个岗位负责什么
18+
- 这个岗位能做什么、不能做什么
19+
- 这个岗位和谁协作
20+
- 这个岗位学到的东西如何进入系统
21+
22+
默认形态下,它保留了多 Worker、Skill、Tool、MCP、会话与自治运行时的核心能力,同时把依赖压到最小:
23+
24+
- 默认不要求 Redis
25+
- 默认不要求 MySQL
26+
- 默认不要求 OpenViking
27+
- 默认不启用 IM 渠道
28+
- 默认只依赖本地 `workspace/``configs/`
29+
30+
## Core Characteristics
31+
32+
- `Role-first, not agent-first`: 主体不是“agent 实例”,而是“岗位 / worker”
33+
- `Organization-aware`: 多个 AI 不是简单 multi-agent 通信,而是有职责边界、协作关系和归属路由
34+
- `Governable by design`: 权限、审计、信任分级、人在回路是系统能力,不靠 prompt 口头约束
35+
- `Learning with approval`: 学习不是自动沉淀自动生效,而是“提议 -> 审核 -> 生效”
36+
- `Goal-driven autonomy`: 主动性不是单纯 cron 到点执行,而是围绕结构化目标做状态偏离判断
37+
- `One runtime, many triggers`: 对话、任务、事件、巡检共享同一条岗位执行管线
38+
39+
## What You Can Do With It
40+
41+
- 为一个组织部署多个数字员工,每个数字员工占一个岗位、各自有职责和边界
42+
- 让同一个岗位同时处理对话、API 任务、事件响应和自主巡检
43+
- 让岗位经验和客户数据分层隔离,避免跨租户或跨客户串数据
44+
- 让 AI 学习新规则,但把生效过程放进“提议 -> 审核 -> 生效”的治理链路
45+
- 让运行时根据目标偏离主动触发动作,而不是只在定时器到点时执行脚本
46+
- 用 HTTP/SSE、workspace、配置模板和调试接口把整条链路先在本地跑通
47+
48+
## How It Is Different
49+
50+
| 维度 | 常见个人助手 / 通用 Agent | genworker |
51+
| --- | --- | --- |
52+
| 主体 | 一个用户的 agent 或 workspace | 一个组织里的岗位 / worker |
53+
| 角色定义 | prompt + 工具配置 | 系统注册的岗位对象 |
54+
| 记忆边界 | 围绕“我”的全局记忆池 | 岗位经验与租户数据分层隔离 |
55+
| 学习方式 | 自动沉淀,往往自动生效 | 提议、审核、生效、衰减的生命周期 |
56+
| 多角色协作 | multi-agent 通信或路由 | 职责边界、协作关系、归属路由 |
57+
| 主动性 | cron / 定时触发 | 目标驱动 / 状态偏离驱动 |
58+
| 工作模式 | 对话、任务、事件常常分散实现 | 对话、任务、事件、巡检共享执行管线 |
59+
60+
## Best Fit
61+
62+
- 一个组织里部署多个数字员工,每个员工占一个岗位、各自有职责边界
63+
- 同一个岗位统一处理对话、任务、事件响应和自主巡检
64+
- 需要把岗位经验与客户数据分层隔离,避免跨租户串数据
65+
- 需要业务规则可审批、操作可审计、关键动作可追溯
66+
- 想先本地把整条运行链路跑通,再逐步接入更复杂基础设施
67+
68+
## Not For
69+
70+
- 给自己用的 AI 伙伴或消息收件箱整合器
71+
- “学到了就自动生效”的无治理自学习 Agent
72+
- 只需要一次性创意任务、不需要长期岗位和组织边界的场景
73+
- 用五套独立系统分别拼对话、任务、事件和巡检的轻量原型
74+
75+
如果你的目标是“给自己用的 AI 伙伴”,Hermes、OpenClaw 一类个人助手轨道通常更合适;如果你的目标是“给组织用、占岗位、可治理、可追溯的数字员工”,`genworker` 更适合。
76+
77+
## Documentation
78+
79+
- [docs/CONFIGURATION.md](docs/CONFIGURATION.md): 配置加载顺序、profile、关键环境变量与路径规则
80+
- [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md): 本地启动、反向代理、systemd 与容器化建议
81+
- [docs/API.md](docs/API.md): 核心 HTTP API、SSE 入口与调试接口
82+
- [docs/RELEASE.md](docs/RELEASE.md): 版本发布、变更校验与维护者发布建议
83+
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md): 运行时架构说明
84+
85+
## What You Get
86+
87+
- HTTP 对话入口:`POST /api/v1/chat/stream`
88+
- Worker 任务流入口:`POST /api/v1/worker/task/stream`
89+
- 健康检查:`GET /health`
90+
- 就绪检查:`GET /readiness`
91+
- 运行时诊断:`GET /api/v1/debug/runtime`
92+
- 本地 Worker / Skill / Persona 加载
93+
- 基于文件系统的会话与工作区运行模式
94+
- 可选 Redis / OpenViking / IM 渠道增强
95+
96+
## Default Operating Model
97+
98+
默认运行方式非常直接:
99+
100+
-`configs/` 管理分层配置
101+
-`workspace/` 管理 tenant、worker、skill、persona
102+
-`python start.py` 直接启动运行时
103+
-`/health``/readiness``/api/v1/debug/runtime` 观察当前状态
104+
105+
这意味着你可以先在一台普通开发机上跑通,再决定是否引入反向代理、外部存储或更复杂的部署拓扑。
106+
107+
## Three-Minute Quick Start
108+
109+
### 1. Install
110+
111+
```bash
112+
python -m venv venv
113+
source venv/bin/activate
114+
pip install -r requirements.txt
115+
```
116+
117+
### 2. Prepare Config
118+
119+
最小可运行配置:
120+
121+
```bash
122+
cp configs/config.example.env configs/config_local.env
123+
```
124+
125+
如果你已经习惯只维护 `configs/config_local.env`,也可以直接编辑它;运行时会优先读取 `configs/` 下的分层配置。根目录 `.env.example` 主要用于给容器、CI 或外部启动包装器做参考,不是 `start.py` 的主配置入口。
126+
127+
### 3. Start
128+
129+
```bash
130+
python start.py
131+
```
132+
133+
默认是本地轻量模式:
134+
135+
- `RUNTIME_PROFILE=local`
136+
- `REDIS_ENABLED=false`
137+
- `MYSQL_ENABLED=false`
138+
- `OPENVIKING_ENABLED=false`
139+
- `IM_CHANNEL_ENABLED=false`
140+
141+
### 4. Verify
142+
143+
```bash
144+
curl -s http://127.0.0.1:8000/health
145+
curl -s http://127.0.0.1:8000/readiness
146+
curl -s http://127.0.0.1:8000/api/v1/debug/runtime
147+
```
148+
149+
如果你看到 `/readiness` 返回成功,并且 `/api/v1/debug/runtime` 里能看到默认 worker 和当前 profile,说明主链路已经启动完成。
150+
151+
## First Requests
152+
153+
对话流示例:
154+
155+
```bash
156+
curl -s -N -X POST "http://127.0.0.1:8000/api/v1/chat/stream" \
157+
-H "Content-Type: application/json" \
158+
-d '{
159+
"message": "你好,帮我概括一下今天应该优先处理什么",
160+
"thread_id": "chat-001",
161+
"tenant_id": "demo",
162+
"worker_id": "analyst-01"
163+
}'
164+
```
165+
166+
任务流示例:
167+
168+
```bash
169+
curl -s -N -X POST "http://127.0.0.1:8000/api/v1/worker/task/stream" \
170+
-H "Content-Type: application/json" \
171+
-d '{
172+
"task": "检查我的收件箱并整理待办",
173+
"tenant_id": "demo",
174+
"worker_id": "analyst-01"
175+
}'
176+
```
177+
178+
更多接口说明见 [docs/API.md](docs/API.md)
179+
180+
## Configuration
181+
182+
配置说明见 [docs/CONFIGURATION.md](docs/CONFIGURATION.md)
183+
184+
重点规则:
185+
186+
- 配置文件从项目根目录的 `configs/` 读取,不依赖当前 shell 所在目录
187+
- `LOG_DIR` 如果写相对路径,会按项目根目录解析
188+
- 默认 `workspace` 根目录固定为 `<project>/workspace`
189+
- `start.py` 会在启动前切回项目根目录,避免从其他目录启动时路径漂移
190+
191+
可直接参考的模板:
192+
193+
- `.env.example`
194+
- `configs/config.example.env`
195+
- `configs/profiles/local.env`
196+
- `configs/profiles/local_memory.env`
197+
- `configs/profiles/advanced.env`
198+
- `configs/profiles/enterprise.env`
199+
200+
## Core Runtime Model
201+
202+
`genworker` 看成四层会更容易理解:
203+
204+
1. Entry Layer: HTTP / SSE / IM / Event / Scheduler
205+
2. Runtime Layer: WorkerRouter、Session、Task、Memory、ToolPipeline
206+
3. Workspace Layer: `workspace/` 中的 tenant、worker、skill、persona 定义
207+
4. Infra Layer: Redis、OpenViking、MySQL、外部平台与代理层
208+
209+
默认本地模式只强依赖前 3 层。
210+
211+
## Runtime Profiles
212+
213+
| Profile | 用途 | Redis | MySQL | OpenViking | IM |
214+
| --- | --- | --- | --- | --- | --- |
215+
| `local` | 最小本地开发与调试 | off | off | off | off |
216+
| `local_memory` | 本地文件系统 + 语义记忆实验 | off | off | on | off |
217+
| `advanced` | 增强型运行时 | on | off | off | off |
218+
| `enterprise` | 完整企业形态模板 | on | on | off | on |
219+
220+
这些 profile 只是模板,不会锁死你的部署方式;最终仍以进程环境变量为最高优先级。
221+
222+
## Repository Layout
223+
224+
```text
225+
.
226+
├── configs/ # 分层配置与 profile 模板
227+
├── docs/ # 架构与配置文档
228+
├── frontend/ # 前端静态资源
229+
├── src/ # 运行时实现
230+
├── tests/ # 单元 / 集成测试
231+
├── workspace/ # 默认运行时工作区
232+
├── workspace.example/ # 示例工作区模板
233+
└── start.py # 本地启动入口
234+
```
235+
236+
## Development Notes
237+
238+
- 推荐直接使用 `python start.py` 启动
239+
- 如果需要保护接口,可设置 `API_BEARER_TOKEN``API_KEY`
240+
- `/health` 只看进程是否活着,`/readiness` 看默认主链路是否可服务
241+
- `workspace.example/` 适合用于初始化新的 Worker 目录结构
242+
- `tests/` 同时包含单元测试和集成测试,适合作为二次开发回归基线
243+
244+
架构细节见 [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)

__pycache__/start.cpython-314.pyc

2.01 KB
Binary file not shown.

configs/config.example.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ENVIRONMENT=local
2+
SERVICE_NAME=genworker
3+
RUNTIME_PROFILE=local
4+
HTTP_HOST=127.0.0.1
5+
HTTP_PORT=8000
6+
LOG_DIR=logs
7+
REDIS_ENABLED=false
8+
MYSQL_ENABLED=false
9+
OPENVIKING_ENABLED=false
10+
IM_CHANNEL_ENABLED=false

configs/profiles/advanced.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RUNTIME_PROFILE=advanced
2+
REDIS_ENABLED=true
3+
MYSQL_ENABLED=false
4+
OPENVIKING_ENABLED=false
5+
IM_CHANNEL_ENABLED=false

0 commit comments

Comments
 (0)