Chuyển đến nội dung chính

第 15 課:域包 — 行業特定的 AI 包

設計域包架構:套件定義、專用工具、特定域的提示。為醫療保健、法律、金融、教育建構包。自動激活,打包市場。

🧠 人工智慧與機器學習 — 第 14 課 Lesson 15: Domain Packs — Industry-specific 人工智慧捆綁包

從零開始搭建AI代理平台-與xClaw實戰

第 5 部分:技能、領域和插件

亞洲開發網

簡介

Domain Packs are pre-built bundles including skills + tools + prompts specific to a specific industry.使用者選擇「Healthcare Pack」而不是通用代理,並立即獲得醫療工具、臨床提示和 HIPAA 合規性檢查。


1. Domain Pack Architecture

// packages/domains/src/types.ts
export interface DomainPack {
  id: string;
  name: string;
  slug: string;
  description: string;
  version: string;
  icon: string;
  color: string;
  skills: SkillDefinition[];
  systemPrompt: string;              // Domain-specific base prompt
  suggestedQuestions: string[];       // Quick-start examples
  complianceRules?: ComplianceRule[];
  requiredPermissions?: string[];
}

export interface ComplianceRule {
  id: string;
  name: string;
  description: string;
  check: (message: string) => boolean;
  action: 'warn' | 'block' | 'redact';
}

2. Healthcare Domain Pack

// packages/domains/src/packs/healthcare.ts
export const healthcarePack: DomainPack = {
  id: 'healthcare',
  name: 'Healthcare & Medical',
  slug: 'healthcare',
  description: 'Medical AI assistant with clinical tools and HIPAA compliance',
  version: '1.0.0',
  icon: '🏥',
  color: '#10b981',

  systemPrompt: `You are a medical AI assistant. Guidelines:
- Always cite medical sources (PubMed, clinical guidelines)
- Include appropriate disclaimers for medical advice
- Follow HIPAA compliance for patient data
- Use ICD-10 codes when relevant
- Recommend professional consultation for diagnoses`,

  suggestedQuestions: [
    'Explain the mechanism of action of metformin',
    'What are the differential diagnoses for chest pain?',
    'Summarize the latest guidelines for hypertension management',
  ],

  skills: [
    defineSkill({
      id: 'medical-search',
      name: 'Medical Literature Search',
      description: 'Search PubMed and medical databases',
      version: '1.0.0',
      tools: [
        {
          definition: {
            name: 'pubmed_search',
            description: 'Search PubMed for medical literature',
            parameters: {
              type: 'object',
              properties: {
                query: { type: 'string', description: 'Medical search query' },
                maxResults: { type: 'number', description: 'Max results (1-20)' },
              },
              required: ['query'],
            },
          },
          handler: pubmedSearchHandler,
        },
        {
          definition: {
            name: 'drug_interaction_check',
            description: 'Check for drug-drug interactions',
            parameters: {
              type: 'object',
              properties: {
                drugs: { type: 'string', description: 'Comma-separated drug names' },
              },
              required: ['drugs'],
            },
          },
          handler: drugInteractionHandler,
        },
        {
          definition: {
            name: 'icd10_lookup',
            description: 'Look up ICD-10 diagnosis codes',
            parameters: {
              type: 'object',
              properties: {
                query: { type: 'string', description: 'Condition or symptom' },
              },
              required: ['query'],
            },
          },
          handler: icd10LookupHandler,
        },
      ],
    }),
  ],

  complianceRules: [
    {
      id: 'hipaa-phi',
      name: 'HIPAA PHI Detection',
      description: 'Detect and redact Protected Health Information',
      check: (message) => {
        // Detect SSN, patient IDs, etc.
        return /\b\d{3}-\d{2}-\d{4}\b/.test(message) ||
               /patient\s+id:\s*\w+/i.test(message);
      },
      action: 'redact',
    },
  ],
};

3. Domain Pack Registry

// packages/domains/src/domain-registry.ts
export class DomainRegistry {
  private packs = new Map<string, DomainPack>();

  register(pack: DomainPack) {
    this.packs.set(pack.id, pack);
  }

  get(id: string): DomainPack | undefined {
    return this.packs.get(id);
  }

  listAll(): DomainPack[] {
    return Array.from(this.packs.values());
  }

  // Activate domain for a session
  activateForSession(
    domainId: string,
    sessionId: string,
    skillManager: SkillManager,
  ): void {
    const pack = this.packs.get(domainId);
    if (!pack) throw new Error(`Domain pack not found: ${domainId}`);

    // Register all skills from the pack
    for (const skill of pack.skills) {
      skillManager.register(skill);
      skillManager.activate(sessionId, skill.id);
    }
  }
}

4. Available Domain Packs in xClaw

包工具使用案例
醫療保健PubMed search, Drug interactions, ICD-10Medical AI assistant
法律Case law search, Contract analysis, Compliance法律研究
金融Market data, Financial analysis, Risk scoring財務顧問
教育Quiz generator, Curriculum builder, Grading教育科技人工智慧
開發營運Log analysis, Infrastructure check, AlertManagerSRE助理
客戶支援Ticket search, FAQ retrieval, Sentiment analysisSupport bot
內容SEO analysis, Content calendar, Social post gen內容行銷
人力資源Resume parser, Job matching, Interview questions人力資源自動化
電子商務Product search, Price comparison, Review analysis導購助理
資料分析SQL generation, Chart creation, Statistical tests資料分析師
研究Paper search, Citation manager, Literature review學術研究
創意Image prompts, Story generator, Brand namingCreative AI
安全CVE lookup, SIEM analysis, Threat intelligence證券分析師

5. 總結

  • Domain Packs = pre-built bundles (skills + prompts + compliance)
  • Registry pattern — plug-and-play activation
  • Compliance rules — domain-specific safety checks
  • Scalability — each pack is an independent package, can be published separately

Next article: Plugin System & MCP Protocol.