common-agent 0.1.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.
- common_agent-0.1.0/.env.example +26 -0
- common_agent-0.1.0/.gitignore +9 -0
- common_agent-0.1.0/PKG-INFO +19 -0
- common_agent-0.1.0/README.md +202 -0
- common_agent-0.1.0/application.yml +74 -0
- common_agent-0.1.0/common_agent/__init__.py +1 -0
- common_agent-0.1.0/common_agent/app.py +464 -0
- common_agent-0.1.0/common_agent/baseline/__init__.py +1 -0
- common_agent-0.1.0/common_agent/baseline/auth.py +90 -0
- common_agent-0.1.0/common_agent/baseline/checks.py +33 -0
- common_agent-0.1.0/common_agent/baseline/policy.py +36 -0
- common_agent-0.1.0/common_agent/cli.py +110 -0
- common_agent-0.1.0/common_agent/config/__init__.py +1 -0
- common_agent-0.1.0/common_agent/config/loader.py +76 -0
- common_agent-0.1.0/common_agent/config/schema.py +129 -0
- common_agent-0.1.0/common_agent/credential_boot.py +23 -0
- common_agent-0.1.0/common_agent/doctor.py +167 -0
- common_agent-0.1.0/common_agent/log_config.py +40 -0
- common_agent-0.1.0/common_agent/model_catalog/__init__.py +1 -0
- common_agent-0.1.0/common_agent/model_catalog/adapter.py +52 -0
- common_agent-0.1.0/common_agent/model_catalog/router.py +222 -0
- common_agent-0.1.0/common_agent/model_catalog/storage.py +197 -0
- common_agent-0.1.0/common_agent/project_render.py +41 -0
- common_agent-0.1.0/common_agent/py.typed +0 -0
- common_agent-0.1.0/common_agent/rag/__init__.py +1 -0
- common_agent-0.1.0/common_agent/rag/rerank.py +350 -0
- common_agent-0.1.0/common_agent/request_log.py +91 -0
- common_agent-0.1.0/common_agent/templates/starter/.env.example +5 -0
- common_agent-0.1.0/common_agent/templates/starter/.gitignore +9 -0
- common_agent-0.1.0/common_agent/templates/starter/README.md +69 -0
- common_agent-0.1.0/common_agent/templates/starter/app/__init__.py +1 -0
- common_agent-0.1.0/common_agent/templates/starter/app/agent/__init__.py +1 -0
- common_agent-0.1.0/common_agent/templates/starter/app/agent/runtime.py +51 -0
- common_agent-0.1.0/common_agent/templates/starter/app/api/__init__.py +1 -0
- common_agent-0.1.0/common_agent/templates/starter/app/api/orders.py +27 -0
- common_agent-0.1.0/common_agent/templates/starter/app/core/__init__.py +1 -0
- common_agent-0.1.0/common_agent/templates/starter/app/core/seed_data.py +25 -0
- common_agent-0.1.0/common_agent/templates/starter/app/log_config.py +40 -0
- common_agent-0.1.0/common_agent/templates/starter/app/main.py +56 -0
- common_agent-0.1.0/common_agent/templates/starter/app/request_log.py +91 -0
- common_agent-0.1.0/common_agent/templates/starter/app/service/__init__.py +1 -0
- common_agent-0.1.0/common_agent/templates/starter/app/service/order_service.py +23 -0
- common_agent-0.1.0/common_agent/templates/starter/app/tools/crm.py +38 -0
- common_agent-0.1.0/common_agent/templates/starter/application.yml +41 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/README.md +34 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/dist/assets/index-B74dwWzh.css +1 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/dist/assets/index-DFfMKx-L.js +83 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/dist/index.html +13 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/index.html +12 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/package-lock.json +1416 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/package.json +22 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/playwright.config.js +10 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/App.vue +23 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/api.js +82 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/components/chat/ChatInput.vue +31 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/components/chat/ConfirmCard.vue +33 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/components/chat/MessageList.vue +56 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/components/chat/SessionSidebar.vue +115 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/components/chat/SettingsDialog.vue +69 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/components/chat/TeamPanel.vue +35 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/components/chat/ToolCallCard.vue +17 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/icons.js +18 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/main.js +12 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/pages/ChatPage.vue +488 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/pages/CredentialsPage.vue +126 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/pages/ModelsPage.vue +296 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/replay.js +45 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/router.js +18 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/sprite.js +27 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/sse.js +99 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/styles/app.css +217 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/styles/tokens.css +61 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/theme.js +37 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/ui/ConfirmDialog.vue +20 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/ui/Dialog.vue +29 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/ui/EmptyState.vue +14 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/src/ui/ThemeSeg.vue +18 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/tests/e2e.spec.js +22 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/tests/hitl-sse.spec.js +54 -0
- common_agent-0.1.0/common_agent/templates/starter/frontend/vite.config.js +17 -0
- common_agent-0.1.0/common_agent/templates/starter/pyproject.toml +30 -0
- common_agent-0.1.0/common_agent/templates/starter/run.py +25 -0
- common_agent-0.1.0/common_agent/templates/starter/tests/__init__.py +1 -0
- common_agent-0.1.0/common_agent/templates/starter/tests/test_smoke.py +32 -0
- common_agent-0.1.0/common_agent/tools/__init__.py +20 -0
- common_agent-0.1.0/common_agent/tools/builtin/__init__.py +1 -0
- common_agent-0.1.0/common_agent/tools/builtin/sop.py +348 -0
- common_agent-0.1.0/common_agent/tools/discovery.py +70 -0
- common_agent-0.1.0/common_agent/tools/toolkit.py +107 -0
- common_agent-0.1.0/docs/guides/model-catalog-integration.md +397 -0
- common_agent-0.1.0/docs/guides/open-api.md +80 -0
- common_agent-0.1.0/docs/plans/2026-12-02-mvp-implementation.md +1488 -0
- common_agent-0.1.0/docs/plans/2026-12-03-cli-init-scaffold.md +767 -0
- common_agent-0.1.0/docs/research/2026-12-01-agentscope-2.0.12-notes.md +158 -0
- common_agent-0.1.0/docs/specs/2026-12-01-framework-design.md +250 -0
- common_agent-0.1.0/docs/specs/2026-12-03-cli-init-scaffold-design.md +114 -0
- common_agent-0.1.0/docs/superpowers/plans/2026-12-04-rerank-model-binding.md +91 -0
- common_agent-0.1.0/docs/superpowers/plans/2026-12-04-sop-tool-group.md +57 -0
- common_agent-0.1.0/docs/superpowers/plans/2026-12-04-vue-frontend-redesign.md +225 -0
- common_agent-0.1.0/docs/superpowers/specs/2026-12-04-rerank-model-binding-design.md +431 -0
- common_agent-0.1.0/docs/superpowers/specs/2026-12-04-sop-tool-group-design.md +45 -0
- common_agent-0.1.0/docs/superpowers/specs/2026-12-04-vue-frontend-redesign-design.md +142 -0
- common_agent-0.1.0/pyproject.toml +46 -0
- common_agent-0.1.0/tests/conftest.py +1 -0
- common_agent-0.1.0/tests/e2e/__init__.py +1 -0
- common_agent-0.1.0/tests/e2e/test_minimal_loop.py +78 -0
- common_agent-0.1.0/tests/integration/__init__.py +1 -0
- common_agent-0.1.0/tests/integration/test_build_app.py +40 -0
- common_agent-0.1.0/tests/integration/test_cli.py +35 -0
- common_agent-0.1.0/tests/integration/test_embedded.py +40 -0
- common_agent-0.1.0/tests/test_cli_init.py +108 -0
- common_agent-0.1.0/tests/test_doctor.py +75 -0
- common_agent-0.1.0/tests/test_log_config.py +41 -0
- common_agent-0.1.0/tests/test_rag_and_log.py +89 -0
- common_agent-0.1.0/tests/unit/__init__.py +1 -0
- common_agent-0.1.0/tests/unit/test_auth.py +40 -0
- common_agent-0.1.0/tests/unit/test_baseline.py +55 -0
- common_agent-0.1.0/tests/unit/test_builtin_sop_tools.py +220 -0
- common_agent-0.1.0/tests/unit/test_discovery.py +32 -0
- common_agent-0.1.0/tests/unit/test_env_file.py +44 -0
- common_agent-0.1.0/tests/unit/test_loader.py +37 -0
- common_agent-0.1.0/tests/unit/test_model_catalog.py +261 -0
- common_agent-0.1.0/tests/unit/test_model_config.py +70 -0
- common_agent-0.1.0/tests/unit/test_permission_tools.py +56 -0
- common_agent-0.1.0/tests/unit/test_rerank.py +184 -0
- common_agent-0.1.0/tests/unit/test_schema.py +65 -0
- common_agent-0.1.0/tools/order.py +11 -0
- common_agent-0.1.0/uv.lock +3769 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# =====================================================================
|
|
2
|
+
# common-agent 环境变量示例
|
|
3
|
+
# 复制为 .env(与 application.yml 同目录)并填入真实值;.env 已被 gitignore
|
|
4
|
+
# 真实环境变量优先于 .env 文件,CI/容器直接 export 覆盖
|
|
5
|
+
# =====================================================================
|
|
6
|
+
|
|
7
|
+
# 模型厂商(dashscope / openai / anthropic / deepseek / gemini)
|
|
8
|
+
PROVIDER=dashscope
|
|
9
|
+
|
|
10
|
+
# 模型名
|
|
11
|
+
MODEL=qwen-max
|
|
12
|
+
|
|
13
|
+
# 模型 API 密钥(必填,占位值替换为真实密钥)
|
|
14
|
+
API_KEY=sk-your-api-key-here
|
|
15
|
+
|
|
16
|
+
# 模型网关/兼容端点(可选,留空走官方默认地址)
|
|
17
|
+
API_BASE=
|
|
18
|
+
|
|
19
|
+
# ---------------------------------------------------------------------
|
|
20
|
+
# 映射关系:application.yml 里用「环境变量名」引用,例如
|
|
21
|
+
# model:
|
|
22
|
+
# provider: ${PROVIDER}
|
|
23
|
+
# name: ${MODEL}
|
|
24
|
+
# api_key_ref: API_KEY # 注意:api_key_ref 写的是键名,不是 ${...}
|
|
25
|
+
# base_url_ref: API_BASE # 仅当 API_BASE 非空时生效
|
|
26
|
+
# ---------------------------------------------------------------------
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: common-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 企业级智能体配置化交付层:AgentScope 官方平台之上的部门 starter
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: agentscope[service,storage-redis,storage-sql]==2.0.12
|
|
7
|
+
Requires-Dist: aiosqlite>=0.20
|
|
8
|
+
Requires-Dist: httpx>=0.27
|
|
9
|
+
Requires-Dist: pydantic>=2.7
|
|
10
|
+
Requires-Dist: pyyaml>=6.0
|
|
11
|
+
Requires-Dist: uvicorn>=0.30
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: aiosqlite>=0.20; extra == 'dev'
|
|
14
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
18
|
+
Provides-Extra: postgres
|
|
19
|
+
Requires-Dist: asyncpg>=0.29; extra == 'postgres'
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# common-agent
|
|
2
|
+
|
|
3
|
+
企业级智能体基础框架:AgentScope 官方平台之上的配置化交付层。
|
|
4
|
+
|
|
5
|
+
业务团队引入开发包、编写一份配置文件与自己的业务工具函数,即可在半天内给自己的系统加上智能体能力,无需理解大模型编排、会话管理、事件推送、渠道接入等底层机制。
|
|
6
|
+
|
|
7
|
+
完整的目的、背景、定位辨析、演进路线与架构设计见 [docs/specs/2026-12-01-framework-design.md](docs/specs/2026-12-01-framework-design.md)。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uv tool install common-agent # 全局 CLI:common-agent init / validate / run
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
或作为库引入业务项目:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv pip install common-agent
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
开发模式(本仓库内贡献时使用):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
uv venv .venv && uv pip install --python .venv/bin/python -e ".[dev]"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
要求 Python 3.11+;依赖 `agentscope==2.0.12`(锁定版本,升级走调研回归流程)。
|
|
28
|
+
|
|
29
|
+
## 最小接入三样东西
|
|
30
|
+
|
|
31
|
+
| 东西 | 说明 |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `application.yml` | 唯一声明面:存储、总线、工作区、安全基线与智能体清单 |
|
|
34
|
+
| `tools/*.py` | 业务工具函数:函数名 + docstring + 类型注解即完整契约 |
|
|
35
|
+
| `skills/` | 智能体技能目录(MVP 已声明字段,装配透传留给后续版本) |
|
|
36
|
+
|
|
37
|
+
### application.yml 示例
|
|
38
|
+
|
|
39
|
+
仓库根的 [application.yml](application.yml) 即最小示例:
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
name: customer-service
|
|
43
|
+
owner_user_id: system
|
|
44
|
+
storage: {type: sqlite, url: "sqlite+aiosqlite:///./data/agents.db"}
|
|
45
|
+
message_bus: {type: in-memory}
|
|
46
|
+
workspace: {backend: local, basedir: ./workspaces, ttl: 3600}
|
|
47
|
+
channels: []
|
|
48
|
+
security: {auth: none}
|
|
49
|
+
agents:
|
|
50
|
+
assistant:
|
|
51
|
+
model: {provider: dashscope, name: qwen-max, api_key_ref: DASHSCOPE_API_KEY}
|
|
52
|
+
system_prompt: |
|
|
53
|
+
你是售后客服助手,负责查询订单与创建工单。
|
|
54
|
+
permission_mode: DEFAULT
|
|
55
|
+
tools: [tools/*]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
要点:
|
|
59
|
+
|
|
60
|
+
- 密钥一律 `${VAR}` 环境变量引用,缺失时启动 fail-fast 并列出全部问题;
|
|
61
|
+
- `owner_user_id` 名下的智能体与凭据自动种子写入 storage,确定性 id 保证重复启动幂等更新;
|
|
62
|
+
- `channels` 是飞书/钉钉/Discord 渠道白名单,留空不影响内置 HTTP API。
|
|
63
|
+
|
|
64
|
+
## CLI:init 脚手架
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
common-agent init my-project # 当前目录生成 my-project/
|
|
68
|
+
common-agent init my-project --dir /some/where
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
生成以 `test-project` 为蓝本的完整项目(业务 API + 工具样例 + Vue 对话页 + 冒烟测试),
|
|
72
|
+
编辑 `.env` 填入 API_KEY 后即可 `common-agent run --config application.yml`。
|
|
73
|
+
目标目录已存在时报错退出,不覆盖任何文件。
|
|
74
|
+
|
|
75
|
+
## CLI:validate 与 run
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# 静态校验:不起进程不调外部服务,输出基线警告、错误清单与工具数量
|
|
79
|
+
common-agent validate --config application.yml
|
|
80
|
+
|
|
81
|
+
# 起服务:基线检查通过后以 uvicorn 启动,默认 127.0.0.1:8000
|
|
82
|
+
export DASHSCOPE_API_KEY=sk-xxx
|
|
83
|
+
common-agent run --config application.yml
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Tool 契约
|
|
87
|
+
|
|
88
|
+
一个业务函数就是一座工具桥,无需写任何注册代码:
|
|
89
|
+
|
|
90
|
+
| 业务侧 | 工具侧 |
|
|
91
|
+
|---|---|
|
|
92
|
+
| 函数名 `query_order` | 工具名 `query_order` |
|
|
93
|
+
| docstring(含 Args 段) | 工具描述与参数说明 |
|
|
94
|
+
| 参数类型注解 `order_id: str` | 输入 schema 类型 |
|
|
95
|
+
| 返回值(建议 JSON 字符串) | 回传模型的结果文本 |
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
def query_order(order_id: str) -> str:
|
|
99
|
+
"""按订单号查询订单状态。
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
order_id: 订单号,形如 SO-2026-0001。
|
|
103
|
+
"""
|
|
104
|
+
return json.dumps({"order_id": order_id, "status": "shipped"}, ensure_ascii=False)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
约束:所有参数必须带类型注解,缺失时校验显式报错;下划线开头函数不注册;复杂嵌套 schema 请显式声明 Pydantic 模型。
|
|
108
|
+
|
|
109
|
+
## 内置 SOP 工具组
|
|
110
|
+
|
|
111
|
+
common-agent 在 Toolkit 装配阶段通过通用 `tool_groups` 扩展点,把 AgentScope 官方 SOP service 能力包装成 `sop_tools` 工具组注入每个 assistant。
|
|
112
|
+
模型可先调用 `reset_tools(sop_tools=true)` 激活,再使用以下工具:
|
|
113
|
+
|
|
114
|
+
- 查询:`list_sops` / `get_sop` / `list_sop_runs` / `get_sop_run`
|
|
115
|
+
- 管理:`create_sop` / `update_sop` / `delete_sop`
|
|
116
|
+
- 运行:`start_sop_run` / `delete_sop_run` / `submit_sop_verdict`
|
|
117
|
+
|
|
118
|
+
查询类工具使用 `is_read_only=true`。管理、启动、删除和审批类工具显式交还权限引擎(`PASSTHROUGH`),
|
|
119
|
+
由 `PermissionContext` 规则与 `permission_mode` 裁决;未声明规则时,`DEFAULT` 下兜底询问,
|
|
120
|
+
`DONT_ASK` / `EXPLORE` 下拒绝,`BYPASS` 下放行。可通过 `tool_permissions` 显式声明:
|
|
121
|
+
|
|
122
|
+
```yaml
|
|
123
|
+
tool_permissions:
|
|
124
|
+
create_sop: ask
|
|
125
|
+
delete_sop: deny
|
|
126
|
+
start_sop_run: allow
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## 调用闭环
|
|
130
|
+
|
|
131
|
+
服务启动后按官方端点调用(身份经鉴权中间件统一注入 `X-User-ID`):
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# 建会话(agent_id 来自 GET /agent/,credential_id 来自 GET /credential/)
|
|
135
|
+
curl -X POST http://127.0.0.1:8000/sessions/ \
|
|
136
|
+
-H "Content-Type: application/json" \
|
|
137
|
+
-d '{"agent_id": "...", "chat_model_config": {"type": "dashscope_chat", "credential_id": "...", "model": "qwen-max", "parameters": {}}}'
|
|
138
|
+
|
|
139
|
+
# 触发对话(fire-and-forget,返回 queued;input 必须是完整 Msg 对象)
|
|
140
|
+
curl -X POST http://127.0.0.1:8000/chat/ \
|
|
141
|
+
-H "Content-Type: application/json" \
|
|
142
|
+
-d '{"agent_id": "...", "session_id": "...", "input": {"name": "customer", "role": "user", "content": [{"type": "text", "text": "在吗"}]}}'
|
|
143
|
+
|
|
144
|
+
# 订阅事件流(SSE)/ 回读会话历史(分页)
|
|
145
|
+
curl "http://127.0.0.1:8000/sessions/{session_id}/stream?agent_id=..."
|
|
146
|
+
curl "http://127.0.0.1:8000/sessions/{session_id}/messages?agent_id=..."
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
注意:`input` 是官方 `Msg` 模型,`name`/`role` 必填且 `content` 是块列表,直接传纯字符串会被 422 拒绝。
|
|
150
|
+
|
|
151
|
+
## 开放 API:可插拔组件,接入方自由消费
|
|
152
|
+
|
|
153
|
+
mount 之后,官方平台全部端点在 `/agents/*` 前缀下自动暴露:模型凭据 CRUD(含厂商 schema 与内置模型清单)、会话与对话(HTTP + SSE 事件流)、智能体、渠道、工作区等。**common-agent 只提供后端能力与数据面,不绑定前端形态**——业务方可做管理页、走自家后台、或纯脚本调用。
|
|
154
|
+
|
|
155
|
+
完整端点清单、身份隔离规则与三种接入模式见 [docs/guides/open-api.md](docs/guides/open-api.md)。
|
|
156
|
+
|
|
157
|
+
## 嵌入接入方 FastAPI
|
|
158
|
+
|
|
159
|
+
Starlette `Mount` 不向子应用转发 `lifespan` scope,直接 mount 会得到连接池从未打开的死服务(已实测对照)。因此嵌入模式必须做 lifespan 组合:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from contextlib import asynccontextmanager
|
|
163
|
+
from fastapi import FastAPI
|
|
164
|
+
|
|
165
|
+
from common_agent.app import AgentRuntime, build_agent_app
|
|
166
|
+
from common_agent.config.loader import load_config
|
|
167
|
+
|
|
168
|
+
runtime = AgentRuntime(load_config("application.yml"))
|
|
169
|
+
|
|
170
|
+
@asynccontextmanager
|
|
171
|
+
async def lifespan(app):
|
|
172
|
+
async with runtime: # 官方组件连接池在此打开/关闭,并完成种子写入
|
|
173
|
+
yield
|
|
174
|
+
|
|
175
|
+
main_app = FastAPI(lifespan=lifespan)
|
|
176
|
+
main_app.mount("/agents", build_agent_app(runtime.config, runtime.components))
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## docker-compose 示例(独立部署形态)
|
|
180
|
+
|
|
181
|
+
```yaml
|
|
182
|
+
services:
|
|
183
|
+
agent:
|
|
184
|
+
image: python:3.12-slim
|
|
185
|
+
working_dir: /app
|
|
186
|
+
command: sh -c "pip install common-agent && common-agent run --config application.yml"
|
|
187
|
+
environment:
|
|
188
|
+
DASHSCOPE_API_KEY: ${DASHSCOPE_API_KEY}
|
|
189
|
+
volumes:
|
|
190
|
+
- ./application.yml:/app/application.yml
|
|
191
|
+
- ./tools:/app/tools
|
|
192
|
+
- ./data:/app/data
|
|
193
|
+
ports:
|
|
194
|
+
- "8000:8000"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## 已知边界
|
|
198
|
+
|
|
199
|
+
- **多副本部署必须显式设置 `security.download_secret`**:未设置时当前为启动警告,负载均衡后工作区文件下载会随机失败;
|
|
200
|
+
- **多进程/多副本部署必须 Redis 消息总线**:in-memory 仅限单机开发(锁与回放依赖共享总线);
|
|
201
|
+
- **复杂业务流程**(受理查重、检查点、回执核验等)属平台 BusinessAdapter 领域,common-agent 不重复建设,请对接平台能力;
|
|
202
|
+
- **多副本需 download_secret、渠道 HITL 审批部门化 UI** 等边界同设计文档 3.6/3.6a。
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# =====================================================================
|
|
2
|
+
# common-agent 配置示例(application.yml)
|
|
3
|
+
# 复制本文件到你的项目,按注释改值即可接入
|
|
4
|
+
# =====================================================================
|
|
5
|
+
|
|
6
|
+
# 应用名:显示在 OpenAPI 文档标题
|
|
7
|
+
name: customer-service
|
|
8
|
+
|
|
9
|
+
# ---------------------------------------------------------------------
|
|
10
|
+
# owner_user_id:智能体与模型凭据在平台里的「属主账号 ID」(服务账号概念)
|
|
11
|
+
# - 全部种子资源(智能体、模型凭据)都挂在这个账号名下
|
|
12
|
+
# - 其他用户身份(请求头 X-User-ID 与它不同)通过共享策略「只读」使用这些资源
|
|
13
|
+
# - owner 本人身份调用则拥有管理权限(可增删改)
|
|
14
|
+
# - 没有自有账号体系时保持默认 system 即可;有则改为你的服务账号 ID
|
|
15
|
+
# ---------------------------------------------------------------------
|
|
16
|
+
owner_user_id: system
|
|
17
|
+
|
|
18
|
+
# 存储后端:会话、消息、凭据、智能体记录
|
|
19
|
+
# sqlite 本地开发(type: sqlite, url 用 sqlite+aiosqlite 协议)
|
|
20
|
+
# postgres 生产推荐(url 用 postgresql+asyncpg 协议)
|
|
21
|
+
# redis 多副本共享(url 用 redis:// 协议)
|
|
22
|
+
storage: {type: sqlite, url: "sqlite+aiosqlite:///./data/agents.db"}
|
|
23
|
+
|
|
24
|
+
# 消息总线:事件与锁的通道
|
|
25
|
+
# in-memory 单机开发(多副本必须换 redis,否则锁与回放失效)
|
|
26
|
+
# redis 生产/多副本必选(host/port/db/password)
|
|
27
|
+
message_bus: {type: in-memory}
|
|
28
|
+
|
|
29
|
+
# 工作区:智能体文件读写目录(本地后端 + 存活时长秒)
|
|
30
|
+
workspace: {backend: local, basedir: ./workspaces, ttl: 3600}
|
|
31
|
+
|
|
32
|
+
# 内置知识库开关(enabled: true 时启用向量存储)
|
|
33
|
+
knowledge_base: {enabled: false}
|
|
34
|
+
|
|
35
|
+
# 渠道白名单:feishu / dingtalk / discord;留空不影响内置 HTTP API
|
|
36
|
+
channels: []
|
|
37
|
+
|
|
38
|
+
# 安全基线
|
|
39
|
+
security:
|
|
40
|
+
# basic=部门基础鉴权(用户清单经 users_env 环境变量提供);none=仅本地开发
|
|
41
|
+
auth: none
|
|
42
|
+
# 是否允许 BYPASS 权限档位(沙箱场景才打开)
|
|
43
|
+
allow_bypass_mode: false
|
|
44
|
+
# 多副本/负载均衡部署必须设置,否则工作区文件下载随机失败(当前为启动警告)
|
|
45
|
+
download_secret: null
|
|
46
|
+
|
|
47
|
+
# =====================================================================
|
|
48
|
+
# 智能体清单:键名即对外显示名
|
|
49
|
+
# =====================================================================
|
|
50
|
+
agents:
|
|
51
|
+
assistant:
|
|
52
|
+
# 模型声明:provider/name 是模型选型,api_key_ref/base_url_ref 只写
|
|
53
|
+
# 「环境变量名」不写值(值放 .env 或真实环境变量,绝不入 git)
|
|
54
|
+
model:
|
|
55
|
+
provider: dashscope # dashscope / openai / anthropic / deepseek / gemini
|
|
56
|
+
name: qwen-max # 模型名
|
|
57
|
+
api_key_ref: DASHSCOPE_API_KEY # 密钥环境变量名
|
|
58
|
+
# base_url_ref: LLM_BASE_URL # 可选:自定义网关/兼容端点的环境变量名
|
|
59
|
+
system_prompt: |
|
|
60
|
+
你是售后客服助手,负责查询订单与创建工单。
|
|
61
|
+
# 权限档位:DEFAULT=工具默认逐次确认;ACCEPT_EDITS=工作目录写自动放行;
|
|
62
|
+
# EXPLORE=只读;DONT_ASK=所有确认转拒绝(无人值守安全默认);BYPASS=跳过检查(需 allow_bypass_mode)
|
|
63
|
+
permission_mode: DEFAULT
|
|
64
|
+
# 免确认工具白名单:查询/问数类工具在这里声明后自动放行,对话无需人工点确认
|
|
65
|
+
tool_permissions:
|
|
66
|
+
query_order: allow
|
|
67
|
+
# 工具声明:目录通配(tools/* 取全部 py)或显式文件
|
|
68
|
+
tools: [tools/*]
|
|
69
|
+
# 上下文压缩与 ReAct 策略(透传官方默认,可省略)
|
|
70
|
+
# context: {trigger_ratio: 0.7, reserve_ratio: 0.2}
|
|
71
|
+
# react: {max_iters: 30}
|
|
72
|
+
# MCP 与 skills 为声明面字段,装配接线在后续版本
|
|
73
|
+
# mcps: [{name: xxx, url: https://...}]
|
|
74
|
+
# skills: ["./skills"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""common-agent:AgentScope 官方平台之上的配置化交付层,包含配置装配、工具发现、部门安全基线与 CLI。"""
|