feat: add AI Digital Employee agent orchestrator with pipeline tracking
- New AgentPipeline model with JSONB pipeline_data for stages/leads/summary
- AgentOrchestrator service chains DiscoveryService search→analyze→outreach→auto-save
- 3 new API endpoints: POST /agent/start, GET /agent/pipelines, GET /agent/{id}
- Full Agent dashboard Vue component with stats, pipeline grid, leads table, outreach preview
- Sidebar redesigned with AI Agent as primary entry point
- Updated PROGRESS.md, AGENTS.md, DATABASE_SCHEMA.md with latest state
This commit is contained in:
+108
-12
@@ -1,7 +1,8 @@
|
||||
# 外贸小助手 (TradeMate) — 数据库设计文档
|
||||
|
||||
> 版本: v1.0
|
||||
> 版本: v1.1
|
||||
> 创建日期: 2026-05-08
|
||||
> 最后更新: 2026-06-16 (新增 agent_pipelines 表)
|
||||
|
||||
---
|
||||
|
||||
@@ -61,16 +62,19 @@
|
||||
│
|
||||
│ 1:N
|
||||
▼
|
||||
┌────────────────┐
|
||||
│ messages │
|
||||
├────────────────┤
|
||||
│ id (PK) │
|
||||
│ conversation_id│
|
||||
│ direction │
|
||||
│ content │
|
||||
│ content_translt│
|
||||
│ ai_suggestions │
|
||||
└────────────────┘
|
||||
┌────────────────┐ ┌──────────────────┐
|
||||
│ messages │ │ agent_pipelines │
|
||||
├────────────────┤ ├──────────────────┤
|
||||
│ id (PK) │ │ id (PK) │
|
||||
│ conversation_id│ │ user_id (FK) │
|
||||
│ direction │ │ status │
|
||||
│ content │ │ progress │
|
||||
│ content_translt│ │ product_name │
|
||||
│ ai_suggestions │ │ target_market │
|
||||
└────────────────┘ │ pipeline_data(JB)│
|
||||
│ error_message │
|
||||
│ created_at │
|
||||
└──────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
@@ -89,6 +93,9 @@ CREATE TABLE users (
|
||||
tier VARCHAR(50) DEFAULT 'free',
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
settings JSONB DEFAULT '{"preferred_translate_provider": "auto", "reply_tone": "professional"}',
|
||||
email VARCHAR(255),
|
||||
last_login_at TIMESTAMP,
|
||||
login_count INTEGER DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
@@ -338,6 +345,85 @@ CREATE INDEX idx_corpus_embedding ON corpus_entries USING ivfflat (embedding vec
|
||||
|
||||
---
|
||||
|
||||
### 3.9 AI 数字员工流水线表 (agent_pipelines) 🆕
|
||||
|
||||
```sql
|
||||
CREATE TABLE agent_pipelines (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL,
|
||||
status VARCHAR(50) DEFAULT 'running',
|
||||
progress INTEGER DEFAULT 0,
|
||||
product_name VARCHAR(255) NOT NULL,
|
||||
product_description TEXT DEFAULT '',
|
||||
target_market VARCHAR(255) NOT NULL,
|
||||
pipeline_data JSONB DEFAULT '{
|
||||
"stages": {
|
||||
"discover": {"status": "pending", "message": ""},
|
||||
"analyze": {"status": "pending", "message": ""},
|
||||
"outreach": {"status": "pending", "message": ""},
|
||||
"complete": {"status": "pending", "message": ""}
|
||||
},
|
||||
"leads": [],
|
||||
"summary": {}
|
||||
}',
|
||||
error_message TEXT,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_agent_pipelines_user ON agent_pipelines(user_id);
|
||||
CREATE INDEX idx_agent_pipelines_status ON agent_pipelines(status);
|
||||
```
|
||||
|
||||
**status 枚举值**:
|
||||
- `running`: 执行中
|
||||
- `completed`: 已完成
|
||||
- `failed`: 失败
|
||||
|
||||
**pipeline_data 结构**:
|
||||
```json
|
||||
{
|
||||
"stages": {
|
||||
"discover": {"status": "completed", "message": "已发现 15 家客户", "count": 15},
|
||||
"analyze": {"status": "completed", "message": "已完成 15 家分析", "count": 15},
|
||||
"outreach": {"status": "completed", "message": "已为 5 家生成触达", "top_count": 5},
|
||||
"complete": {"status": "completed", "message": "任务完成"}
|
||||
},
|
||||
"leads": [
|
||||
{
|
||||
"name": "Company ABC",
|
||||
"match_score": 85,
|
||||
"match_reason": "高度匹配",
|
||||
"company_summary": "主营...",
|
||||
"url": "https://...",
|
||||
"outreach": {"email_body": "...", "whatsapp_message": "..."}
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"total_leads": 15,
|
||||
"high_match": 5,
|
||||
"medium_match": 7,
|
||||
"customers_saved": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | UUID | 主键 |
|
||||
| user_id | UUID | 所属用户 |
|
||||
| status | VARCHAR | 状态: running/completed/failed |
|
||||
| progress | INTEGER | 进度百分比 0-100 |
|
||||
| product_name | VARCHAR | 产品名称 |
|
||||
| product_description | TEXT | 产品描述 |
|
||||
| target_market | VARCHAR | 目标市场 |
|
||||
| pipeline_data | JSONB | 流水线数据 (stages + leads + summary) |
|
||||
| error_message | TEXT | 错误信息 |
|
||||
| created_at | TIMESTAMP | 创建时间 |
|
||||
| updated_at | TIMESTAMP | 更新时间 |
|
||||
|
||||
---
|
||||
|
||||
## 四、pgvector 扩展
|
||||
|
||||
```sql
|
||||
@@ -367,6 +453,7 @@ LIMIT 5;
|
||||
| messages | conversation_id | 消息历史 |
|
||||
| quotations | user_id, customer_id, status | 报价单管理 |
|
||||
| corpus_entries | task_type, domain, embedding | 语料检索 |
|
||||
| agent_pipelines | user_id, status | 流水线查询 |
|
||||
|
||||
---
|
||||
|
||||
@@ -380,9 +467,18 @@ LIMIT 5;
|
||||
| 报价单数据 | 3年 | 订单追溯 |
|
||||
| 语料数据 | 永久 | AI训练 |
|
||||
| 日志数据 | 90天 | 调试审计 |
|
||||
| 流水线数据 | 永久 | AI 数字员工执行记录 |
|
||||
|
||||
---
|
||||
|
||||
## 七、迁移脚本
|
||||
|
||||
使用 Alembic 进行数据库迁移,初始迁移见 `backend/alembic/versions/001_initial.py`。
|
||||
使用 Alembic 进行数据库迁移,初始迁移见 `backend/alembic/versions/001_initial.py`。
|
||||
|
||||
```bash
|
||||
# 创建新迁移
|
||||
cd backend && alembic revision --autogenerate -m "add agent_pipelines"
|
||||
|
||||
# 执行迁移
|
||||
cd backend && alembic upgrade head
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user