Go to file
hailin 691a3523e8 feat(analytics): add Agent usage analytics to admin panel
Add full-stack Agent execution tracking and analytics:

**Database (conversation-service)**
- New `agent_executions` table: tracks each specialist Agent invocation
  with agentType, agentName, durationMs, success, tenantId
- Migration: AddAgentExecutionsTable1738800000000
- ORM entity: AgentExecutionORM with indexes on tenant, conversation,
  agentType, createdAt, and (tenant+date) composite

**Data Capture (conversation-service)**
- conversation.service.ts: captures `agent_start` and `agent_complete`
  StreamChunk events in the sendMessage() async generator loop
- Persists agent execution records to DB after each message completes
- Non-blocking: agent persistence failures are logged but don't break
  the main conversation flow

**Admin API (conversation-service)**
- GET /conversations/admin/statistics/agents?days=30
  Aggregated stats per agent type: totalCalls, successCount, failureCount,
  successRate, avgDurationMs, min/max duration
- GET /conversations/admin/statistics/agents/trend?days=7&agentType=
  Daily trend data: date, agentType, calls, avgDurationMs, successRate
- GET /conversations/admin/:id/agent-executions
  Per-conversation agent execution records ordered by createdAt

**Admin Client - Analytics Page**
- New AgentAnalyticsTab component with:
  - 4 summary cards (total calls, success rate, avg duration, top agent)
  - Agent statistics table (Ant Design Table with sortable columns,
    color-coded Tags, Progress bar for success rate)
  - Stacked bar trend chart (Recharts BarChart, color per agent type)
  - Time range selectors (7/14/30/90 days)
- Added as third tab "Agent 使用分析" in AnalyticsPage dimension tabs

**Admin Client - Conversations Page**
- Added "Agent 使用详情" section to conversation detail drawer
  (between Token Usage and Messages sections)
- Shows per-conversation agent execution table with agent name (color Tag),
  duration, success/failure status, and timestamp
- Empty state: "暂无 Agent 使用记录"

Agent color mapping: policy_expert=#1890ff, assessment_expert=#52c41a,
strategist=#722ed1, objection_handler=#eb2f96, case_analyst=#faad14,
memory_manager=#13c2c2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 08:00:55 -08:00
.claude fix(evolution): handle super admin login without tenant context 2026-01-26 08:20:26 -08:00
database/migrations docs(migration): add is_super_admin column to admins table migration 2026-01-26 08:35:07 -08:00
docs feat(agents): implement multi-agent collaboration architecture 2026-02-06 04:26:39 -08:00
infrastructure feat(multimodal): add file upload and image support for chat 2026-01-10 05:34:41 -08:00
kong feat(kong): add analytics and audit routes for evolution-service 2026-01-25 08:22:30 -08:00
nginx fix(nginx): fix admin location try_files path and add multi-tenancy migrations 2026-01-26 07:46:52 -08:00
packages feat(analytics): add Agent usage analytics to admin panel 2026-02-06 08:00:55 -08:00
scripts feat(multi-tenant): add super admin module and user profile pages 2026-01-26 06:41:11 -08:00
.builder.Dockerfile fix(tenant): use TenantContextModule.forRoot() for global tenant context 2026-01-26 04:31:56 -08:00
.dockerignore Initial commit: iConsulting 香港移民咨询智能客服系统 2026-01-09 00:01:12 -08:00
.env.example feat(embedding): add OpenAI proxy support for IP-based URLs 2026-01-23 05:42:22 -08:00
.gitignore Initial commit: iConsulting 香港移民咨询智能客服系统 2026-01-09 00:01:12 -08:00
README.md docs: add link to Agent Evaluation Report in README 2026-01-23 04:56:27 -08:00
deploy.sh feat(multi-tenant): add super admin module and user profile pages 2026-01-26 06:41:11 -08:00
docker-compose.yml feat(multi-tenant): add super admin module and user profile pages 2026-01-26 06:41:11 -08:00
iconsulting部署架构.jpg Initial commit: iConsulting 香港移民咨询智能客服系统 2026-01-09 00:01:12 -08:00
package.json feat(multi-tenant): add super admin module and user profile pages 2026-01-26 06:41:11 -08:00
pnpm-lock.yaml feat(multi-tenant): apply tenant middleware and refactor repositories 2026-01-25 18:30:31 -08:00
pnpm-workspace.yaml Initial commit: iConsulting 香港移民咨询智能客服系统 2026-01-09 00:01:12 -08:00
tsconfig.base.json Initial commit: iConsulting 香港移民咨询智能客服系统 2026-01-09 00:01:12 -08:00
turbo.json refactor(services): implement 4-layer Clean Architecture for all backend services 2026-01-24 22:18:22 -08:00
优才.jpg docs: add QMAS (优才计划) reference image 2026-01-22 23:47:03 -08:00
香港移民类别.jpg Initial commit: iConsulting 香港移民咨询智能客服系统 2026-01-09 00:01:12 -08:00

README.md

iConsulting - 香港移民在线咨询系统

基于 Claude Agent SDK 的智能在线客服系统,专注于提供香港移民咨询服务。

功能特性

  • 智能咨询: 基于 Claude Agent SDK 的自然语言对话
  • 付费评估: 移民资格评估服务,支持支付宝/微信/信用卡
  • 知识增强: RAG + Neo4j 知识图谱
  • 自我进化: 从对话中学习,根据管理员指令调整
  • 长期记忆: 基于时间线的知识图谱记录
  • 多端支持: PC Web / H5 响应式设计

支持的移民类别

  1. 优才计划 (QMAS) - 行业翘楚、精英人士
  2. 专才计划 (GEP) - 专业人才
  3. 留学IANG - 非本地毕业生
  4. 高才通 (TTPS) - 高端人才
  5. 投资移民 (CIES) - 投资者
  6. 科技人才 (TechTAS) - 科技领域人才

技术架构

├── 前端 (Clean Architecture)
│   ├── React 18 + TypeScript
│   ├── TailwindCSS + Radix UI
│   └── Zustand + React Query
│
├── 后端 (DDD + Hexagonal + 微服务)
│   ├── NestJS
│   ├── Claude Agent SDK
│   └── TypeORM
│
└── 基础设施
    ├── PostgreSQL + pgvector (RAG)
    ├── Neo4j (知识图谱)
    ├── Redis (缓存)
    └── Kafka (消息队列)

项目结构

iconsulting/
├── packages/
│   ├── shared/                 # 共享类型、常量、工具
│   ├── web-client/             # 用户端 Web 应用
│   ├── admin-client/           # 管理端 Web 应用
│   └── services/               # 后端微服务
│       ├── api-gateway/        # API 网关
│       ├── user-service/       # 用户服务
│       ├── conversation-service/ # 对话服务 (核心)
│       ├── knowledge-service/  # 知识服务
│       ├── payment-service/    # 支付服务
│       ├── admin-service/      # 管理服务
│       └── evolution-service/  # 进化服务
│
├── infrastructure/
│   └── docker/                 # Docker 配置
│
├── DEVELOPMENT_GUIDE.md        # 详细开发指导
└── README.md

快速开始

1. 安装依赖

# 安装 pnpm (如果没有)
npm install -g pnpm

# 安装项目依赖
pnpm install

2. 启动基础设施

# 启动 Docker 容器 (PostgreSQL, Neo4j, Redis, Kafka)
pnpm docker:dev

3. 配置环境变量

# 复制环境变量示例文件
cp .env.example .env

# 编辑 .env 文件,填入必要的配置
# 特别是 ANTHROPIC_API_KEY

4. 运行数据库迁移

pnpm db:migrate

5. 启动开发服务器

# 启动所有服务
pnpm dev

访问:

环境变量

关键配置项:

# Claude API
ANTHROPIC_API_KEY=sk-ant-xxx

# 数据库
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=iconsulting
POSTGRES_PASSWORD=your_password
POSTGRES_DB=iconsulting

# Neo4j
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_password

# 支付 (支付宝/微信)
ALIPAY_APP_ID=xxx
WECHAT_APP_ID=xxx

完整配置请参考 .env.example

文档

文档 说明
架构文档 系统整体架构、服务职责、数据流、部署配置
Agent 评估报告 Agent 能力评估、成熟度分析、升级路线图
开发指南 详细开发指导、代码示例、API 设计
MinIO 配置 对象存储配置说明

开发进度

已完成

  • 项目架构设计
  • 开发指导文档
  • Monorepo 配置
  • 共享类型定义
  • Docker 基础设施配置
  • 数据库 Schema
  • 对话服务 (Claude Agent SDK 集成)
  • 用户端前端基础框架

进行中

  • 用户服务
  • 知识服务 (RAG + Neo4j)
  • 支付服务
  • 管理服务 (自我进化)
  • 管理后台前端

贡献指南

  1. Fork 本仓库
  2. 创建特性分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 创建 Pull Request

许可证

私有项目,保留所有权利。