BossAgents Rule Template Management System Architecture Documentation
Version: 1.0 | Update Date: 2026-05-31
1. System Architecture Overview
1.1 Core Concept
BossAgents adopts the architectural philosophy of "Rule-Driven + LLM-Enhanced":
- Rules are deterministic logic responsible for rapid judgment and standard operations
- Templates define data structures to ensure consistent output formats
- Prompts are LLM interaction protocols that enable AI to understand business context
- These three elements collectively drive foundational digital staff capabilities, which are then orchestrated and invoked by business digital staff
1.2 Overall Architecture Diagram
``
┌─────────────────────────────────────────────────────────────────────────┐
│ Business Digital Staff Layer (Digital Staff) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ DS-ECR-001 │ │ DS-VEN-001 │ │ DS-COST-001 │ │ DS-SYS-001 │ │
│ │ ECR Reviewer │ │ Supplier Steward │ │ Cost Optimizer │ │ System Operations Engineer │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
├─────────┼────────────────┼────────────────┼──────────────────────────────┤
│ ▼ ▼ ▼ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ Basic Digital Employee Capability Layer (Capabilities) │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Identify │ │ Create │ │ Repair │ │ Optimize │ │ │
│ │ │ Identify │ │ Create │ │ Repair │ │ Optimize │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ │ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Compare │ │ Generate │ ← Unified execution via Rule Engine │ │
│ │ │ Comparison Capability │ │ Generation Capability │ │ │
│ │ └──────────┘ └──────────┘ │ │
│ └──────────────────────────────────────────────────────────────────┘ │
├──────────────────────────────────────────────────────────────────────────┤
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ Configuration Layer ── sciot_import.db (Unified Configuration Database) │ │
│ │ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │ │
│ │ │ sciot_rules_v2 │ │ sciot_templates│ │ prompt_templates│ │ │
│ │ │ Unified Rules Engine │ │ Object Template Library │ │ Prompt Template Library │ │ │
│ │ └────────────────┘ └────────────────┘ └────────────────┘ │ │
│ │ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │ │
│ │ │ sciot_properties│ │sciot_sequences│ │sciot_relationships│ │ │
│ │ │ Object Property Definition │ │ Numbering Sequence │ │ Relationship Type Definition │ │ │
│ │ └────────────────┘ └────────────────┘ └────────────────┘ │ │
│ └──────────────────────────────────────────────────────────────────┘ │
├──────────────────────────────────────────────────────────────────────────┤
│ Data Source Layer │
│ ┌────────────────┐ ┌────────────────┐ ┌────────────────┐ │
│ │ PLM/AML XML │ │ SCSAI Real-time API │ │ Manual Creation │ │
│ │ Import Parsing │ │ Online Synchronization │ │ UI Maintenance │ │
│ └────────────────┘ └────────────────┘ └────────────────┘ │
└──────────────────────────────────────────────────────────────────────────┘
`
2. Data Flow Diagram
2.1 Complete Object Creation Process
`
User describes "Create Project X"
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ 1. Get Schema │
│ GET /api/aml/unified/schema/Project │
│ Return: { llmFields: [...], autoFields: [...], properties: [...] } │
└─────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ 2. Get Template │
│ GET /api/sciot/type-template/Project │
│ Return: { properties, relationships, list_values, lifecycle, ... } │
└─────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ 3. Get/Build Prompt │
│ GET /api/aml/sciot/prompts → Prefer pre-generated prompts │
│ or POST /api/rule-engine/pregenerate-prompt → Dynamically generate │
└─────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ 4. Invoke LLM to Generate JSON │
│ POST /api/llm/chat │
│ Input: prompt + user description │
│ Output: { item_type, properties, relationships, ... } │
└─────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ 5. Rule Engine Processing │
│ POST /api/rule-engine/create-item │
│ Process: validate → create_pre → assemble AML → create_post │
└─────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ 6. Submit to SCSAI │
│ POST /SCSAI-api/ApplyItem │
│ Input: AML XML │
│ Output: { Item: { id: "..." } } │
└─────────────────────────────────────────────────────────────────────────┘
`
2.2 Rule Engine Execution Process
`
execute(scope, context, options)
│
├── 1. getRules({ scope, item_type, is_active: true })
│ └── Query rules from sciot_rules_v2 table
│
├── 2. Sort by priority (P0 → P1 → P2 → P3)
│
├── 3. Execute one by one
│ ├── _evaluateCondition(rule, context) → match?
│ │ └── Check condition.field + condition.operator
│ │
│ └── if (match) _executeAction(rule, context)
│ ├── block → return { blocked: true }
│ ├── warn → log warning
│ ├── suggest → possibly call LLM
│ └── auto_fix → modify context data
│
├── 4. Record history _recordHistory()
│
└── 5. Conflict resolution
├── first_match → break (execute only the first matching rule)
├── merge → continue (execute all matching rules)
└── stop → break (stop if any rule matches)
`
3. Core data tables
3.1 sciot_rules_v2 (unified rule table)
| Field | Type | Description |
|------|------|------|
| id | TEXT | Rule ID (primary key) |
| name | TEXT | Rule name |
| scope | TEXT | Scope: identify/validate/create_pre/create_post/repair/optimize/compare |
| item_type_name | TEXT | Applicable object type (null = universal) |
| severity | TEXT | Severity: error/warning/info/hint |
| priority | INTEGER | Priority: 0=P0 (blocking), 1=P1 (high), 2=P2 (medium), 3=P3 (low) |
| condition | TEXT | Condition JSON: { field, operator, value } |
| action_type | TEXT | Action type: block/warn/suggest/auto_fix |
| action_script | TEXT | Action script (JS code) |
| conflict_strategy | TEXT | Conflict strategy: first_match/merge/stop |
| is_active | INTEGER | Whether enabled |
| is_builtin | INTEGER | Whether built-in rule |
Scope description:
| scope | Purpose | Execution timing |
|-------|------|----------|
| validate | Validation rule | Validate before creation; block creation on failure |
| create_pre | Pre-creation preprocessing | After validation passes, fill default values, generate numbers |
| create_post | Post-creation processing | After SCSAI submission succeeds, create related objects, send notifications |
| repair | Repair rule | Called by repair capability |
| optimize | Optimization rule | Called by optimization capability |
3.2 sciot_templates (object template table)
| Field | Type | Description |
|------|------|------|
| item_type_name | TEXT | Object type name |
| llm_fields | TEXT | LLM-generatable fields (JSON array) |
| auto_fields | TEXT | System auto-filled fields (JSON array) |
| generation_rules | TEXT | Child object generation rules (JSON) |
| aml_template | TEXT | AML template XML |
Field classification usage:
- llm_fields: Appears in the prompt, letting the LLM generate values
- auto_fields: Does not appear in the prompt; handled automatically by the system (numbering, creation time, etc.)
3.3 sciot_properties (Object Property Definition Table)
| Field | Type | Description |
|------|------|------|
| item_type_name | TEXT | Owning object type |
| name | TEXT | Property name |
| data_type | TEXT | Data type: string/integer/date/list/item/foreign/sequence |
| is_required | INTEGER | Whether required |
| is_hidden | INTEGER | Whether hidden (not shown in UI) |
| readonly | INTEGER | Whether read-only |
| default_value | TEXT | Default value |
| data_source | TEXT | Data source for list type |
Key data_type types:
- list: Enumeration type; selectable values are obtained from sciot_list_values
- item: Reference type, pointing to another Item (e.g., wbs_id → WBS Element)
- foreign: Foreign key type
- sequence: Auto-numbering type
3.4 prompt_templates (Prompt Template Table)
| Field | Type | Description |
|---|---|---|
| item_type_name | TEXT | Applicable object type |
| prompt_type | TEXT | Prompt type: creation/identify/repair/optimize |
| content | TEXT | Prompt content (supports {{variable}}) |
| version | INTEGER | Version number |
| status | TEXT | Status: active/deprecated/testing |
3.5 sciot_sequences (Numbering Sequence Table)
| Field | Type | Description |
|------|------|------|
| name | TEXT | Sequence name (usually object type name + " Number") |
| prefix | TEXT | Number prefix |
| current_value | INTEGER | Current value |
| pad_to | INTEGER | Number of zero-padding digits |
Number generation: prefix + String(current_value + 1).padStart(pad_to, '0')
4. Core APIs
4.1 Rule Engine API
| Method | Route | Function |
|---|---|---|
| GET | /api/rule-engine/rules | Get rule list |
| POST | /api/rule-engine/rules | Create rule |
| PUT | /api/rule-engine/rules/:id | Update rule |
| DELETE | /api/rule-engine/rules/:id | Delete rule |
| POST | /api/rule-engine/execute/:scope | Execute rules for the specified scope |
| POST | /api/rule-engine/validate | Validate object |
| POST | /api/rule-engine/create-item | Create object (full lifecycle) |
| POST | /api/rule-engine/pregenerate-prompt | Pre-generate prompt |
| GET | /api/rule-engine/stats | Rule statistics |
| GET | /api/rule-engine/history | Execution history |
4.2 SCIOT Data API
| Method | Route | Description |
|---|---|---|
| GET | /api/aml/unified/schema/:type | Get object Schema (including llmFields/autoFields) |
| GET | /api/sciot/type-template/:type | Get full object template |
| GET | /api/aml/sciot/prompts | Get all prompts |
| GET | /api/aml/sciot/templates | Get all templates |
5. Troubleshooting Guide
5.1 Problem Diagnosis Process
`
Issue occurs
│
├── 1. Browser console → frontend errors, API call failures
│
├── 2. Server logs → server-log.txt
│
├── 3. Check database → sqlite3 sciot_import.db
│
└── 4. Rule execution history → GET /api/rule-engine/history
`
5.2 Common Issues
| Issue | Possible Cause | Diagnosis Method | Solution |
|---|---|---|---|
| Prompt generation failed | sciot_templates has no data | SELECT COUNT(*) FROM sciot_templates | Run AML import |
| LLM returns empty | Prompt too long or malformed | Check LLM response logs | Check prompt template |
| Creation failed | Blocked by validation rule | Check execution history | Check validate rules |
| Duplicate number | Sequence value not updated | SELECT * FROM sciot_sequences | Update current_value |
| SCSAI submission failed | Field type error | Check AML content | Check data_type definition |
5.3 Debugging SQL
`sql
-- View rule statistics
SELECT scope, COUNT(*) as count, SUM(CASE WHEN is_active=1 THEN 1 ELSE 0 END) as active
FROM sciot_rules_v2 GROUP BY scope;
-- View template coverage
SELECT t.name,
CASE WHEN tmpl.id IS NOT NULL THEN 'YES' ELSE 'NO' END as has_template,
CASE WHEN pt.id IS NOT NULL THEN 'YES' ELSE 'NO' END as has_prompt
FROM sciot_item_types t
LEFT JOIN sciot_templates tmpl ON t.name = tmpl.item_type_name
LEFT JOIN prompt_templates pt ON t.name = pt.item_type_name;
-- View execution history
SELECT r.name, h.item_type, h.action, h.duration_ms, h.executed_at
FROM sciot_rule_history h
JOIN sciot_rules_v2 r ON h.rule_id = r.id
ORDER BY h.executed_at DESC LIMIT 50;
-- View rules with high false positive rate
SELECT name, hit_count, user_correction_count,
ROUND(user_correction_count * 100.0 / NULLIF(hit_count, 0), 2) as correction_rate
FROM sciot_rules_v2 WHERE hit_count > 10 ORDER BY correction_rate DESC;
`
6. Optimization Recommendations
6.1 Identified Issues
| Issue | Severity | Suggestion |
|---|---|---|
| Two rule tables coexist (sciot_rules vs sciot_rules_v2) | High | Migrate uniformly to sciot_rules_v2 |
| No singleton for database connection | Medium | Create a unified SciotDatabase singleton |
| AMLEngine does not consume the rule engine | High | Use the rule engine uniformly |
6.2 Performance Optimization
- Add indexes to sciot_rules_v2: (scope, item_type_name, is_active, priority)
- Rule execution supports parallelism (for rules without dependencies)
- Implement cache warming: preload frequently used rules at startup
6.3 Feature Enhancements
- Rule testing sandbox: POST /api/rule-engine/test`
- Rule self-optimization: analyze execution history and automatically adjust priorities
- Prompt A/B testing: supported via parent_id and score fields
7. File Index
| File | Purpose |
|---|---|
| server/core/rule-engine.js | Unified rule engine core (2268 lines) |
| server/routes/rule-engine.js | Rule engine API routes (722 lines) |
| server/routes/aml.js | SCIOT data API (4847 lines) |
| src/views/RulesAndTemplates.vue | Rule template management UI |
| src/views/StaffCapabilities.vue | Basic capability operations UI |
Document updated: 2026-05-31
BossAgents