# 任务1: [木/青龙] CaaS Skill SKILL.md规范编写

---
name: wuxing-caas
description: "五行飞轮认知服务 (Wuxing Flywheel Cognitive-as-a-Service) — 将五行飞轮认知框架封装为独立API服务。输入关键词或领域，自动执行青龙(种子发散)→朱雀(结构化执行)→白虎(对抗压测)→玄武(认知收敛)四象分析，输出结构化JSON认知报告。适用于：(1) 技术/产业深度分析 (2) 战略决策支持 (3) 材料/供应链卡脖子评估 (4) 竞争情报解析 (5) 第一性原理推演。通过CaaS API网关(端口19106)对外提供服务，支持材料库L0公开层查询。"
version: "1.0.0"
author: "SkyCetus"
tags: ["cognitive-framework", "analysis", "caas", "wuxing", "flywheel", "materials", "deep-analysis"]
---

# 五行飞轮认知服务 (Wuxing CaaS)

## Overview

五行飞轮CaaS版将认知飞轮框架从Agent内置skill升级为独立的Cognitive-as-a-Service API，可被任何客户端调用。

**核心能力**: 输入关键词/领域 → 五行飞轮四象分析 → 结构化认知报告(JSON)

## Metadata

| 属性 | 值 |
|------|-----|
| Skill Name | `wuxing-caas` |
| Version | 1.0.0 |
| API Port | 19106 |
| LLM Backend | MiniMax-M2.7 (Anthropic兼容) |
| LLM Endpoint | `https://api.minimaxi.com/anthropic/v1/messages` |
| Framework | FastAPI |
| Python | 3.11+ |
| HTTP Client | urllib (内置, 无外部依赖) |

## Dependencies

### 必需
- **Python 3.11+** — 运行时环境
- **FastAPI** — API网关框架
- **uvicorn** — ASGI服务器

### 内置 (无需安装)
- **urllib** — HTTP请求 (替代requests/httpx, 避免SSL兼容性问题)
- **json** — JSON序列化
- **ssl** — HTTPS连接

### 安装

```bash
pip install fastapi uvicorn
```

## Setup

### 1. 环境配置

```bash
# 设置MiniMax API Key (环境变量方式)
set MINIMAX_API_KEY=sk-cp-xxx...

# 或直接在caas_gateway.py中配置 (已内置)
```

### 2. 启动服务

```bash
cd D:\ClawMatrix
python caas_gateway.py
# 服务启动于 http://localhost:19106
```

### 3. 验证

```bash
curl http://localhost:19106/caas/status
```

## Architecture

```
┌─────────────────────────────────────────────┐
│              CaaS API Gateway               │
│            (FastAPI :19106)                  │
├─────────────────────────────────────────────┤
│  POST /caas/analyze                         │
│  ├── 青龙 Qinglong (种子发散)                │
│  ├── 朱雀 Zhuque   (结构化执行)              │
│  ├── 白虎 Baihu    (对抗压测)                │
│  └── 玄武 Xuanwu   (认知收敛)                │
├─────────────────────────────────────────────┤
│  GET  /caas/materials                       │
│  └── L0公开层材料库查询                       │
├─────────────────────────────────────────────┤
│  GET  /caas/status                          │
│  └── 系统状态 / LLM连通性 / 任务统计          │
└─────────────┬───────────────────────────────┘
              │ urllib (HTTPS)
              ▼
┌─────────────────────────────────────────────┐
│         MiniMax-M2.7 LLM Backend            │
│    api.minimaxi.com (Anthropic兼容)          │
│    thinking: {enabled, budget_tokens:1000}   │
└─────────────────────────────────────────────┘
```

## API Endpoints

### POST /caas/analyze

执行四象认知分析。

**Request:**
```json
{
  "keyword": "碳化硅",
  "domain": "半导体",
  "depth": "standard"
}
```

| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| keyword | string | ✅ | 分析目标关键词 |
| domain | string | ❌ | 领域范围 (半导体/新能源/先进材料/生物医药/量子计算) |
| depth | string | ❌ | 分析深度: `quick`(快速) / `standard`(标准) / `deep`(深度), 默认`standard` |

**Response:**
```json
{
  "task_id": "wx-20260430-001",
  "keyword": "碳化硅",
  "domain": "半导体",
  "timestamp": "2026-04-30T13:26:00+08:00",
  "analysis": {
    "qinglong_seeds": {
      "phase": "木/青龙 — 种子发散",
      "seeds": [
        {
          "id": 1,
          "angle": "...",
          "rationale": "...",
          "uncertainty": 0.3
        }
      ],
      "divergence_score": 0.85
    },
    "zhuque_execution": {
      "phase": "火/朱雀 — 结构化执行",
      "structured_analysis": [...],
      "data_points": [...],
      "execution_completeness": 0.9
    },
    "baihu_adversarial": {
      "phase": "金/白虎 — 对抗压测",
      "attack_defense_pairs": [...],
      "fragile_assumptions": [...],
      "robustness_rating": "🟡 Conditional"
    },
    "xuanwu_cognition": {
      "phase": "水/玄武 — 认知收敛",
      "conclusions": [...],
      "confidence_scores": {...},
      "first_principles": [...],
      "residuals": [...]
    }
  },
  "meta": {
    "llm_model": "MiniMax-M2.7",
    "thinking_budget": 1000,
    "total_tokens": 0,
    "processing_time_ms": 0
  }
}
```

### GET /caas/materials

查询L0公开层材料库。

**Query Parameters:**

| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| domain | string | ❌ | 按领域筛选 |
| tier | string | ❌ | 按层级筛选: `T1`(战略级) / `T2`(关键级) / `T3`(重要级) |

**Response:**
```json
{
  "total": 41,
  "domain": "半导体",
  "materials": [
    {
      "name": "碳化硅 (SiC)",
      "domain": "半导体",
      "tier": "T1",
      "brief": "...",
      "convergence_score": 0.92,
      "chokepoint_level": "critical"
    }
  ]
}
```

### GET /caas/status

系统状态查询。

**Response:**
```json
{
  "status": "operational",
  "hub_connection": true,
  "llm_status": "connected",
  "llm_model": "MiniMax-M2.7",
  "materials_count": 41,
  "tasks_completed": 0,
  "uptime_seconds": 0
}
```

## Workflow

### 标准分析流程

```
用户请求 → POST /caas/analyze
    ↓
[Phase 1] 青龙/种子发散
    • LLM生成5-10个发散角度
    • 包含逆向和非显而易见视角
    • 标注信息缺口和不确定性
    ↓
[Phase 2] 朱雀/结构化执行
    • 选取Top 3-5种子深入展开
    • 结构化论证 + 数据点
    • 分解为可操作子组件
    ↓
[Phase 3] 白虎/对抗压测
    • 对每个结论发起最强反驳
    • 识别脆弱假设
    • 标注鲁棒性: 🟢/🟡/🔴
    ↓
[Phase 4] 玄武/认知收敛
    • 综合幸存结论 + 置信度评分
    • 提取可复用认知模式
    • 映射第一性原理
    ↓
返回JSON结构化报告
```

### 相生链 (Mutual Generation)

木→火→土→金→水→木

种子激发任务 → 任务产出交付物 → 交付物接受对抗检验 → 检验产出认知 → 认知催生新种子

## Configuration

### 环境变量

| 变量名 | 说明 | 默认值 |
|--------|------|--------|
| MINIMAX_API_KEY | MiniMax API密钥 | 内置 |
| CAAS_PORT | API网关端口 | 19106 |
| CAAS_THINKING_BUDGET | LLM思考预算 | 1000 |

## File Structure

```
D:\ClawMatrix\
├── caas_gateway.py              # API网关主程序
├── caas_data/
│   └── l0_materials.json        # L0公开层材料库
└── skills/
    └── wuxing-caas/
        └── SKILL.md             # 本文件
```

## Notes

- MiniMax API使用urllib而非requests/httpx，避免SSL兼容性问题
- thinking参数必须设置为 `{"type":"enabled","budget_tokens":1000}`
- 材料库L0层为公开信息，L1/L2层需要授权访问
- API网关无需认证（内网部署），生产环境需添加API Key验证
