SCSAI Digital Employee Platform — Rule Engine SOUL
Version: 3.0
Update Date: 2026-05-09
Core Concept: Natural Language → Keyword Recognition → Rule Matching → Tool Invocation → Result Return
Ultimate Goal: A Self-Operating, Self-Evolving Industrial Digital Employee System
I. System Soul (SOUL)
1.1 What is This
SCSAI is a rule-driven digital employee platform. It is not a simple chatbot, but a closed-loop business operating system:
``
Boss/Employee issues a command (natural language)
↓
Keyword Recognition Engine (L1: Pure rules, no LLM required)
↓
Rule Template Matching (ai-agent-rules.json)
↓
┌─ need_llm=false → Directly invoke API to execute
└─ need_llm=true → LLM-assisted understanding + Execute after confirmation
↓
Execution result returned (Frontend/Feishu/Automatic operation)
↓
System self-learning and self-optimization
`
1.2 Three-Level Intelligence Strategy
| Level | Trigger Condition | Processing Method | Latency | Cost |
|------|----------|----------|------|------|
| L1 Rule Direct | Keywords hit rules with need_llm=false | Directly call tool API |
| L2 Rule+LLM | Keywords hit rules with need_llm=true | LLM extracts parameters → User confirmation → Execution | 1-3s | Low |
| L3 Pure LLM | Keywords hit no rules | LLM understands intent → Reasons over tools → Confirmation → Execution | 3-10s | Medium |
Core principle: Never call LLM for tasks solvable by rules; never escalate to L2/L3 if L1 can handle.
II. Rule Template System (RULES)
2.1 Rule Template Structure
Each rule is a "soul fragment," defining how the system understands a category of instructions:
`json
{
"id": "Unique rule identifier",
"name": "Rule name (Chinese)",
"keywords": ["Keyword1", "Keyword2"],
"need_llm": false,
"action": {
"tool": "Tool name",
"params": { "parameter name": "parameter value template" },
"required_fields": ["Required fields"],
"SCSAI_type": "SCSAI object class name (optional)",
"SCSAI_select": "SCSAI query fields (optional)"
},
"examples": ["Example command 1", "Example command 2"]
}
`
2.2 Rule Matching Algorithm
`
Input: User message "Create supplier Huawei, phone 12345678"
↓
- Convert to lowercase: "create supplier huawei, phone 12345678"
↓
- Iterate through all rules, calculate the keyword hit count for each rule:
- create_vendor: "create"✓ "supplier"✓ "vendor"✓ → score 3
- create_project: "create"✓ → score 1
- query_vendors: "supplier"✓ "vendor"✓ → score 2
↓
- Highest-scoring rule: create_vendor (score 3)
↓
- need_llm=true → Attempt to extract parameters from the message:
- name: "Huawei" (extracted from message)
- phone: "12345678" (extracted from message)
↓
- Return confirmation: "I understand you want to create a supplier: Huawei, confirm execution?"
↓
- User confirms → Call create_vendor tool → Execute
`
2.3 Complete Rule List (47 items)
#### ? Query Rules (L1 Direct Pass, No LLM Required)
| ID | Rule Name | Keywords | Tool | Description |
|----|----------|--------|------|------|
| query_item_types | Query Object Class List | object class/list/ItemType/type | search_item_types | View all object class definitions in the system |
| query_inventory | Query Inventory | inventory/query/material/stock | list_data(inventory_items) | View inventory material list |
| query_projects | Query Projects | project/list/progress/project | list_data(projects) | View project list and progress |
| query_quality | Query quality data | Quality/Inspection/NCR/Pass Rate | list_data(inspections) | View quality inspection records |
| query_vendors | Query vendors | Supplier/Vendor/Manufacturer/List | list_data(vendors) | View vendor list |
| query_documents | Query documents | Document/Drawing/Document/File | list_data(documents) | View document list |
| query_cad | Query CAD drawings | CAD/Drawing/cad | list_data(documents) | View CAD drawings |
| query_customers | Query customers | Customer/Customer/Customer List | list_data(customers) | View customer list |
| query_work_orders | Query work orders | Work Order/Production/Work_Order | list_data(orders) | View production work orders |
| dashboard | Data overview | Overview/Statistics/Dashboard/Data | dashboard_summary | Dashboard data summary |
| compare_item_types | Comparison Object Types | compare/comparison/difference/diff | compare_item_types | Local vs. SCSAI Difference Comparison |
| system_health | System Health Check | health/status/system/check | system_health | Database/SCSAI/LLM Status |
| export_data | Export Data | export/download/export/excel | export_data | Export Module Data |
#### ? System Operation and Maintenance Rules (L1 Direct)
| ID | Rule Name | Keywords | Tool | Description |
|----|----------|--------|------|------|
| optimize_item_types | Batch Optimize Object Types | optimize/object type/attribute/completion | optimize_item_types | Automatically Complete Missing Attributes |
| import_item_types | Import Object Classes | Import/Sync/Object Classes/AML | import_item_types | Import from AML file |
| repair_item_type | Repair Object Classes | Repair/Object Classes/Integrity | repair_item_type | Repair object class definitions |
#### ✏️ Create Class Rules (L2 requires LLM assistance for understanding)
| ID | Rule Name | Keywords | Tool | SCSAI Type | Required Fields |
|----|----------|--------|------|----------|----------|
| create_vendor | Create Vendor | Create/Add/Vendor/Manufacturer | create_vendor | Vendor | name |
| create_project | Create Project | Create/Add/Project | create_project | Project | name |
| create_ecr | Create Change Request | Create/Add/Change Request/ECR/Change | create_SCSAI_item | ECR | name |
| create_ncr | Create Nonconformance Report | Create/Add/Nonconformance/NCR/Quality | create_ncr | NCR | title |
| create_purchase_order | Create Purchase Order | Create/Purchase/PO | create_SCSAI_item | pop_purchase_order | name |
| create_sales_order | Create Sales Order | Create/Sales/SO/Order | create_SCSAI_item | sop_sale_order | name |
| create_work_order | Create Work Order | Create/Work Order/Production Order | create_SCSAI_item | Work_Order | name |
| create_document | Create Document | Create/Document/Upload | create_SCSAI_item | Document | name |
#### ? Inventory Operation Rules (L2 requires LLM assistance for understanding)
| ID | Rule Name | Keywords | Tool | SCSAI Type | Required Fields |
|----|----------|--------|------|----------|----------|
| inventory_outbound | Inventory Outbound | Outbound/Picking/Shipment/Deduct Inventory | inventory_transaction | stk_issue | part_number, quantity |
| inventory_inbound | Inventory Inbound | Inbound/Receipt/Inbound Order | inventory_transaction | stk_issue | part_number, quantity |
#### ?️ Tagging Rules (L2 requires LLM assistance for understanding)
| ID | Rule Name | Keywords | Tool | Required Fields |
|----|----------|--------|------|----------|
| toggle_core | Set as Core Object | Core/Business Object/Tag | toggle_core_business | item_type_name |
#### ? Analysis Rules (L2 requires LLM assistance for understanding)
| ID | Rule Name | Keywords | Tool | Required Fields |
|----|----------|--------|------|----------|
| analyze_trends | Trend Analysis | Trend/Analysis/Statistics/Report | analyze_trends | module |
III. Tool Registry (TOOLS)
3.1 Tool Definition
Each tool serves as the "hands and feet" of a rule template, defining the specific execution logic:
| Tool Name | Description | Required Parameters | Data Source |
|--------|------|----------|--------|
| search_item_types | Search Object Classes | None | SQLite |
| get_item_type_detail | Get Object Class Details | name | SQLite |
| list_data | Query Business Data List | module | SQLite |
| create_vendor | Create Vendor | name | SQLite + SCSAI |
| create_project | Create Project | name | SQLite |
| create_ncr | Create NCR | title | SQLite |
| create_quality_inspection | Create Quality Inspection | title, inspection_type | SQLite |
| create_inventory_item | Create Inventory Item | part_number, part_name | SQLite |
| inventory_transaction | Inventory Transaction | part_number, transaction_type, quantity | SQLite |
| create_SCSAI_item | General SCSAI Object Creation | item_type, name | SQLite + SCSAI |
| optimize_item_types | Batch Optimize Object Classes | None | SQLite |
| repair_item_type | Repair Object Class | name | SQLite |
| toggle_core_business | Set Core Object Flag | item_type_name, is_core | SQLite |
| import_item_types | Import object classes from AML | source | AML file + SQLite |
| compare_item_types | Compare object class differences | None | SQLite + SCSAI |
| dashboard_summary | Dashboard summary | None | SQLite |
| system_health | System health check | None | SQLite + SCSAI + LLM |
| analyze_trends | Trend analysis | module | SQLite |
| export_data | Data export | module | SQLite |
3.2 Tool Execution Flow
`
executeTool(toolName, params)
↓
- Find tool in TOOLS array
↓
- Validate required parameters (required)
↓
- Call tool.handler(params)
↓
- Return { type: 'result', success: true, data: ... }
or { type: 'error', message: '...' }
`
IV. SCSAI Object Class Mapping
4.1 PLM Core Object Classes
| Object Class | SCSAI Type Name | AML File Path | Purpose |
|---|---|---|---|
| Part | Part | PLM/Import/ItemType/Part.xml | BOM Management |
| Document | Document | PLM/Import/ItemType/Document.xml | Document Management |
| CAD Drawing | CAD | PLM/Import/ItemType/CAD.xml | Drawing Management |
| Vendor | Vendor | PLM/Import/ItemType/Vendor.xml | Vendor Management |
| Customer | Customer | PLM/Import/ItemType/Customer.xml | Customer Management |
| Change Request | ECR | PLM/Import/ItemType/ECR.xml | Engineering Change |
4.2 SCIOT Extended Object Classes
| Object Class | SCSAI Type Name | AML File Path | Purpose |
|---|---|---|---|
| Project | Project | SCIOT/SCIOT/Project/Import/ItemType/Project.xml | Project Management |
| Project Task | Project Task | SCIOT/SCIOT/Project/Import/ItemType/Project Task.xml | Task Management |
| Nonconformance Report | NCR | SCIOT/SCIOT/QS/Import/ItemType/NCR.xml | Quality Management |
| Corrective & Preventive Action | QAP | SCIOT/SCIOT/QS/Import/ItemType/QAP.xml | Quality Management |
| Inventory Setup | stk_stock_setup | SCIOT/SCIOT/WEFIC_ACCOUNTING/Import/ItemType/stk_stock_setup.xml | Inventory Management |
| Issue Slip | stk_issue | SCIOT/SCIOT/WEFIC_ACCOUNTING/Import/ItemType/stk_issue.xml | Inventory Management |
| Stock Transfer | stk_stock_transfer | SCIOT/SCIOT/WEFIC_ACCOUNTING/Import/ItemType/stk_stock_transfer.xml | Inventory Management |
| Purchase Order | pop_purchase_order | SCIOT/SCIOT/WEFIC_ACCOUNTING/Import/ItemType/pop_purchase_order.xml | Procurement Management |
| Sales Order | sop_sale_order | SCIOT/SCIOT/WEFIC_ACCOUNTING/Import/ItemType/sop_sale_order.xml | Sales Management |
| Work Order | Work_Order | SCIOT/SCIOT/WEFIC_ACCOUNTING/Import/ItemType/Work_Order.xml | Production Management |
4.3 SCIOT Object Relationship Types
Real relationship types discovered from ItemType.xml (non-SCSAI standard names):
| Relationship Type | Query Method | Description |
|----------|----------|------|
| Property | | Direct relationship |
| Method | | Direct relationship |
| View | | Direct relationship |
| Allowed Permission | | Direct relationship |
| Server Event | | Direct relationship |
| Item Action | | Direct relationship |
| RelationshipType | | Queried via source_id |
V. Closed-Loop Execution Example
Example 1: L1 Direct Pass — "View Inventory"
`
User: "View Inventory"
↓
Keyword match: "Inventory"✓ "Query"✓ → query_inventory (score 2, need_llm=false)
↓
Direct execution: list_data({ module: "inventory_items" })
↓
SQL: SELECT * FROM inventory_items ORDER BY created_at DESC LIMIT 50
↓
Return: { type: 'result', data: { total: 156, items: [...] } }
↓
Frontend displays inventory list
`
Example 2: L2 Rule + LLM — "Create vendor Huawei, phone 12345678"
`
User: "Create vendor Huawei, phone 12345678"
↓
Keyword matching: "create"✓ "vendor"✓ "vendor"✓ → create_vendor (score 3, need_llm=true)
↓
Parameter extraction: name="Huawei", phone="12345678"
↓
Return confirmation: { type: 'confirm', message: "I understand you want to create vendor: Huawei\n\nConfirm execution?" }
↓
User clicks "Confirm"
↓
Execute: create_vendor({ name: "Huawei", phone: "12345678" })
↓
- SQLite: INSERT INTO vendors (id, name, phone, ...) VALUES (...)
- SCSAI: POST /server/odata/Part → Create Vendor object
↓
Return: { type: 'result', message: "Vendor created successfully (synced to SCSAI)" }
`
Example 3: Feishu Remote Command — "Inventory Alert"
`
Boss in Feishu group @Digital Assistant: "Inventory Alert"
↓
Feishu event push → POST /api/feishu/webhook
↓
handleMessageEvent → aiAgent.processMessage("Inventory Alert")
↓
Keyword matching: "inventory"✓ "alert"✗ → query_inventory (score 1, need_llm=false)
↓
Execute: list_data({ module: "inventory_items" })
↓
Feishu reply: "Current inventory alert items total 12:\n1. R001 Resistor - Current 0 Safety 100\n2. ..."
`
VI. AI Inspection System (Self-Evolution Core)
6.1 Inspection Architecture
The AI Inspection System is the core engine for platform self-evolution. It continuously detects data quality issues in SCSAI object classes, automatically fixes and validates them:
`
Inspection (1,197 object classes) → Problem identification (5 rule categories) → One-click fix (SSE real-time progress) → Automatic re-inspection verification
`
6.2 Inspection Rules (5 rules, all auto-fixable)
| Rule ID | Name | Category | Severity | Fix Method |
|---|---|---|---|---|
| rule-001 | Must have Chinese label | Basic Specification | error | Built-in translation mapping table (100+ entries) + DeepSeek fallback |
| rule-002 | Must have a number field | Data Integrity | error | Automatically add item_number attribute |
| rule-003 | Must have a name field | Data Integrity | error | Automatically add name attribute |
| rule-004 | Must have a status field | Lifecycle | warning | Automatically add state attribute |
| rule-005 | Must have audit fields | Audit Trail | warning | Automatically add created_by_id attribute |
6.3 Technical Points for Fixing
- Serial execution + 200ms delay: Avoid SCSAI database deadlock
- Retry mechanism: Automatic deadlock retry, up to 2 times
- SSE real-time push: Push to frontend immediately after each fix item completes
- Data separation: SSE only pushes summary; full issues fetched via JSON API (to avoid frontend lag from large data)
- Authentication passthrough: Frontend passes current logged-in user's authentication to server, fixes executed using that user's permissions
6.4 API Interfaces
| Route | Method | Function |
|---|---|---|
| /api/ai-inspector/inspect-stream | POST | SSE streaming inspection |
| /api/ai-inspector/fix-stream | POST | SSE streaming fix |
| /api/ai-inspector/last-result | POST | Get latest full inspection result |
| /api/ai-inspector/rules | GET | Get rule list |
Seven. Digital Employee Team
7.1 Current On-Duty Employees (4 persons)
| Employee ID | Name | Position | Department | Scheduling Cycle | Core Capabilities |
|---|---|---|---|---|---|
| DS-ECR-001 | XiaoZhi-ECR Reviewer | Junior Change Management Reviewer | Quality Department | Every 15 minutes | LLM intelligent initial ECR review, auto-approval if confidence >0.8 |
| DS-VEN-001 | XiaoZhi-Supplier Steward | Supplier Quality Management Specialist | Procurement Department | Every 30 minutes | Supplier quality score monitoring, triggers diagnosis if below 75 |
| DS-COST-001 | XiaoZhi-Cost Optimizer | Cost Analysis Engineer | Finance Department | Daily at 2 AM | BOM cost scanning, alternative material recommendation, ROI analysis |
| DS-DATA-001 | XiaoZhi-Data Clerk | Data Synchronization Engineer | IT Department | Hourly | SCSAI data sync to local cache (6 object types) |
7.2 LLM Brain Capabilities
| Capability | Role Setting | Output |
|---|---|---|
| ECR Intelligent Review | CCB Expert | decision / confidence / riskLevel |
| Supplier Intelligent Diagnosis | Quality Expert | healthScore / risk / improvementPlan |
| BOM Cost Optimization | Cost Expert | alternativeMaterialRecommendation / ROI analysis |
| 5Why Root Cause Analysis | 6 Sigma Black Belt | 5-level Why chain / correctivePreventiveActions |
Eight. Self-Operation & Self-Evolution Roadmap
Phase One: Rule-Driven (✅ Completed)
- ✅ 47 rule templates covering core business
- ✅ 42 utility functions implementing business operations
- ✅ Three-level intelligent strategy (L1/L2/L3)
- ✅ Feishu bot remote commands
- ✅ Keyword matching + LLM fallback
- ✅ AI inspection system (5 rules, SSE real-time fixes)
- ✅ 4 digital employees working autonomously
- ✅ SCSAI SOAP API integration
- ✅ Dual-write data architecture (SCSAI + SQLite)
Phase 2: Self-Learning (? In Progress)
- ? Operation Log Analysis → Automatic Discovery of High-Frequency Commands → Automatic Generation of New Rules
- ? User Feedback Collection → Optimization of Rule Keyword Weights
- ? Rule Conflict Detection → Automatic Priority Adjustment
- ? AML Change Monitoring → Automatic Synchronization of Object Class Definitions
- ? Inspection Rule Expansion (Relationship Types/Lifecycle/Permissions/Naming Conventions)
Phase 3: Self-Operation and Maintenance (? Planned)
- ✅ Scheduled Health Check → Data Scribe Already Implemented
- ? Inventory Alert → Automatic Triggering of Procurement Suggestions
- ? Quality Trend Analysis → Automatic Initiation of Corrective Actions
- ? System Anomaly Detection → Automatic Diagnosis and Repair
- ? Object Class Integrity Automatic Inspection → Automatic Repair (AI Inspection System Basic Version Already Implemented)
Phase 4: Self-Evolution (Long-term)
- ? Business Process Mining → Automatically Discover Standard Processes
- ? Rule Auto-generation → Learn New Rules from Historical Operations
- ? Cross-Module Linkage → Automatically Trigger Related Operations
- ? Predictive Maintenance → Proactively Identify Potential Issues
IX. Core Business Module Mapping
9.1 Business Module → SCSAI Object Class → Rule/Tool Mapping
| Business Module | SCSAI Object Class | Implemented Rules | Implemented Tools | Digital Employee |
|---|---|---|---|---|
| BOM Management | Part, CAD | query_item_types | optimize_item_types | Cost Optimization Engineer |
| Change Management | ECR, ECO | create_ecr | create_SCSAI_item | ECR Reviewer |
| Project Management | Project, Project Task | create_project | create_project | - |
| Quality Management | NCR, QAP | create_ncr, analyze_root_cause | create_ncr, analyze_root_cause, generate_quality_report | - |
| Process Management | - | optimize_process_params | optimize_process_params, run_mold_flow_analysis | - |
| Vendor Management | Vendor, Manufacturer | create_vendor, query_vendors | create_vendor | Vendor Management |
| Customer Management | Customer | query_customers | create_SCSAI_item | - |
| Inventory Management | stk_stock_setup, stk_issue | inventory_inbound/outbound | inventory_transaction, create_inventory_item | - |
| Procurement Management | pop_purchase_order | create_purchase_order | create_SCSAI_item | - |
| Sales Management | sop_sale_order | create_sales_order | create_SCSAI_item | - |
| Production Management | Work_Order | create_work_order | create_SCSAI_item, get_production_status | - |
| Equipment Management | - | predict_health, predict_tool_wear | predict_device_health, predict_tool_wear | - |
| Green Manufacturing | - | carbon_management | calculate_carbon_footprint | - |
9.2 Business Modules to be Improved
| Business Module | Missing Content | Priority |
|---|---|---|
| Project Management | Lacks project progress tracking, Gantt chart, milestone management tools | High |
| Quality Management | Lack of real-time SPC monitoring and automatic CPK calculation tools | High |
| Process Management | Process parameter optimization is simulated and requires integration with real models | Medium |
| Equipment Management | Equipment health prediction is simulated and requires IoT data integration | Medium |
| Customer Management | Lack of customer segmentation, credit evaluation, and order analysis tools | Medium |
10. Known Limitations and Improvement Directions
10.1 Current Limitations
- Simulated Implementation: Approximately 13 advanced tools (visual inspection, equipment prediction, process optimization, etc.) still use simulated data.
- Insufficient Inspection Rules: Only 5 basic rules, lacking checks for relationship types, lifecycle, permissions, etc.
- Data Synchronization Limitations: Only 6 SCSAI object types are synchronized, missing BOM/Project/Customer, etc.
- Insufficient Digital Employee Coverage: Only 4 digital employees cover 47 rules.
- Lack of Testing Framework: No unit tests or integration tests.
10.2 Near-term Improvement Directions
- Expand Inspection Rules: Add rules for relationship type integrity, attribute label localization, naming conventions, etc.
- Add New Digital Employees: Quality Inspector, Inventory Manager, Production Scheduler.
- Business Loop Closure: Inspection Discovery → Automatic Repair → Verification → Continuous Monitoring.
- Large Model Integration: Combine inspection repair with LLM rule templates for intelligent repair decision-making.
11. How to Extend
7.1 Adding New Rules
Edit server/ai-agent-rules.json and add to the rules array:
`json
{
"id": "your_rule_id",
"name": "Rule Name",
"keywords": ["keyword1", "keyword2"],
"need_llm": false,
"action": {
"tool": "corresponding_tool_name",
"params": {}
},
"examples": ["Example Instruction"]
}
`
7.2 Adding New Tools
Edit server/ai-agent.js and add to the TOOLS array:
`javascript
{
name: 'your_tool_name',
description: 'Tool description',
parameters: {
type: 'object',
properties: {
param1: { type: 'string', description: 'Parameter description' }
},
required: ['param1']
},
handler: async (params) => {
// Implement your business logic here
return { result: 'success' };
}
}
`
7.3 Add a New SCSAI Object Class
- Create an AML definition file for the ItemType in SCSAI/SCIOT
- Add corresponding creation/query rules in ai-agent-rules.json
- Add corresponding tools in ai-agent.js if special logic is required
- The system will automatically synchronize the new object class via import_item_types
12. File Index
| File | Purpose |
|---|---|
| server/ai-agent-rules.json | Rule template definitions (31 rules) |
| server/ai-agent.js | AI agent core (19 tools + intent recognition + execution engine) |
| server/digital-staff/llm-brain.js | LLM brain (ECR review/supplier analysis/BOM optimization/5Why root cause) |
| server/feishu-bot.js | Feishu bot integration (event reception + message reply + proactive push) |
| server/routes/aml.js | AML routes (optimization/fix/comparison/core marking) |
| server/database1.js | Database management (SQLite + auto migration) |
| server/utils/SCSAI-connection.js | SCSAI connection utility (SOAP API wrapper) |
| frontend/app.js | Frontend application (Vue 3 + SCSAI integration + AI assistant UI) |
| index-vue.html | Main page (sidebar + 12 tabs + AI assistant) |
| frontend/styles.css | Styles (light/dark theme + responsive layout) |
BossAgents