hailin
60a74fc3b0
feat(agents): enforce QMAS 12-item eligibility threshold with 3-layer validation
...
根据2024年11月1日更新的优才计划政策,实现12项基本门槛评核准则的
系统级强制校验(需满足至少6项才具备申请资格)。
**Layer 1 — Assessment Expert Prompt (assessment-expert-prompt.ts):**
- QMAS评估新增强制性3步流程:门槛评核 → 成就计分制 → 综合计分制
- 12项评核准则逐一列出,含判定依据(年龄≤50、硕士/博士、STEM、
双语能力、英文能力、≥5年工作经验、跨国/知名企业≥3年、
特定行业≥3年、国际经验≥2年、年收入≥100万港币、
业务实体盈利≥500万港币、上市公司)
- 每项判定为 met/not_met/unknown,unknown不计为符合
- 门槛不通过 → eligible=false, score上限29分
- 输出JSON新增 thresholdCheck 结构化字段(items数组+metCount+passed)
**Layer 2 — Code-level 后置校验 (immigration-tools.service.ts):**
- Step 4.5 安全网:解析评估结果后校验QMAS thresholdCheck一致性
- 门槛不通过但score>29 → 自动降级修正(score=29, eligible=false)
- 门槛通过但eligible=false且score>29 → 自动修正eligible=true
- 缺少thresholdCheck → 记录警告日志
**Layer 3 — Coordinator System Prompt (coordinator-system-prompt.ts):**
- Section 10.1 新增"基本门槛(2024年11月更新)"小节
- 明确说明门槛不通过者不具备申请资格(即使计分制达80分)
- 更新4条常见问题速答,融入门槛准则解释
**数据收集增强 (collection-expert-prompt.ts):**
- 新增3个附加字段:company_type、business_ownership、listed_company
- QMAS类别映射扩展,覆盖门槛评核12项所需全部数据点
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 07:40:47 -08:00
hailin
9feb03153b
feat(agents): add admin assessment directive system for dynamic prompt injection
...
Admins can now write natural-language directives that get injected into the
assessment expert's system prompt. Directives are stored in DB, loaded per
execution, and support incremental additions, toggling, and full reset.
Backend:
- New assessment_directives table + ORM entity
- Admin CRUD API at /conversations/admin/assessment-directives
- buildAssessmentExpertPrompt() accepts optional adminDirectives param
- AssessmentExpertService loads active directives from DB before each execution
- Fail-safe: missing repo/tenant context → default prompt (no directives)
Frontend (admin-client):
- New "评估指令" page with table, create/edit modals, toggle switches
- Prompt preview panel showing assembled directive text
- Reset-to-default with confirmation
- React Query hooks for all CRUD operations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 18:21:21 -08:00
hailin
16cc0e4c08
feat(agents): implement multi-agent collaboration architecture
...
借鉴 Claude Code 的架构模式,将单一 Agent 重构为 Coordinator + 6 Specialist 多 Agent 协作系统。
## 新增文件 (36个)
### 架构设计文档 (docs/architecture/, 12个)
- 00-overview.md ~ 11-prompt-templates.md: 完整架构设计,覆盖所有 Agent 的详细设计、
Prompt 模板、协作流程、工具并发系统、动态上下文注入
### 多 Agent 系统 (infrastructure/agents/, 23个)
- coordinator/coordinator-agent.service.ts: 主协调器,替代 ClaudeAgentServiceV2
- coordinator/agent-loop.ts: 核心递归 async generator 循环(参考 Claude Code aM())
- coordinator/context-injector.service.ts: 动态上下文注入(8种上下文类型按优先级注入)
- specialists/base-specialist.service.ts: Agent 基类(封装 Claude API 调用 + prompt 缓存)
- specialists/policy-expert.service.ts: 政策专家 (Sonnet 4, temp=0)
- specialists/assessment-expert.service.ts: 评估专家 (Sonnet 4, temp=0)
- specialists/strategist.service.ts: 策略顾问 (Sonnet 4, temp=0.3)
- specialists/objection-handler.service.ts: 异议处理 (Sonnet 4, temp=0.2)
- specialists/case-analyst.service.ts: 案例分析 (Haiku, temp=0)
- specialists/memory-manager.service.ts: 记忆管理 (Haiku, temp=0)
- prompts/coordinator-system-prompt.ts: 协调器 Prompt(1095行,13章)
- prompts/{policy,assessment,strategist,objection,case,memory}-*-prompt.ts: 各专家 Prompt
- tools/coordinator-tools.ts: 16个工具定义(6 Agent 调用 + 10 直接工具)
- tools/tool-execution-queue.ts: 并发执行队列(isConcurrencySafe 控制并行/串行)
- types/agent.types.ts: Agent 配置、输入/输出类型定义
- types/stream.types.ts: 流式事件类型(含 agent_start/complete/coordinator_thinking)
- types/context.types.ts: 上下文注入类型
- agents.module.ts: NestJS 模块注册
### 前端 Agent 状态展示 (1个)
- AgentStatusIndicator.tsx: 多 Agent 工作状态组件(含动画)
## 修改文件 (15个)
### 后端集成
- conversation.service.ts: 切换到 CoordinatorAgentService
- conversation.gateway.ts: 新增 agent_start/agent_complete/coordinator_thinking 事件
- claude.module.ts: 引入 AgentsModule
- agents.module.ts: 注册 ImmigrationToolsService(复用旧版生产测试的工具实现)
- knowledge-client.service.ts: 新增 search()/getUserContext() 便捷方法
### 旧代码标记 @deprecated
- claude-agent.service.ts, claude-agent-v2.service.ts
- strategy-engine.service.ts, intent-classifier.ts, response-gate.ts
### 前端适配
- chatStore.ts: 新增 ActiveAgent/CompletedAgent/CoordinatorPhase 状态
- useChat.ts: 新增 WebSocket 事件处理
- ChatWindow.tsx: 集成 AgentStatusIndicator
- globals.css: 新增 agentPulse/agentSlideIn 动画
### 共享类型
- conversation.types.ts: 新增 AGENT_START/AGENT_COMPLETE/COORDINATOR_THINKING 事件
## 核心设计决策
1. **新旧结合**: Coordinator 的 10 个直接工具委托给旧版 ImmigrationToolsService
(经过生产测试的 Google Search、汇率 API、新闻 API 等),6 个 Agent 调用工具
走新的 Specialist Agent 系统
2. **递归 async generator**: agent-loop 支持流式输出 + 工具递归 + 成本/轮次控制
3. **并行 Agent 执行**: ToolExecutionQueue 根据 isConcurrencySafe 自动并行/串行
4. **Prompt 缓存**: 所有 Agent 的 system prompt 使用 cache_control: ephemeral
5. **速率限制重试**: 429/529 指数退避,最多 2 次
6. **向后兼容**: LegacyConversationContext 类型别名,StreamChunk 扩展不破坏现有结构
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 04:26:39 -08:00