BossAgents Rule Template Management System Architecture Documentation

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)

FieldTypeDescription
item_type_nameTEXTApplicable object type
prompt_typeTEXTPrompt type: creation/identify/repair/optimize
contentTEXTPrompt content (supports {{variable}})
versionINTEGERVersion number
statusTEXTStatus: 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

MethodRouteFunction
GET/api/rule-engine/rulesGet rule list
POST/api/rule-engine/rulesCreate rule
PUT/api/rule-engine/rules/:idUpdate rule
DELETE/api/rule-engine/rules/:idDelete rule
POST/api/rule-engine/execute/:scopeExecute rules for the specified scope
POST/api/rule-engine/validateValidate object
POST/api/rule-engine/create-itemCreate object (full lifecycle)
POST/api/rule-engine/pregenerate-promptPre-generate prompt
GET/api/rule-engine/statsRule statistics
GET/api/rule-engine/historyExecution history

4.2 SCIOT Data API

MethodRouteDescription
GET/api/aml/unified/schema/:typeGet object Schema (including llmFields/autoFields)
GET/api/sciot/type-template/:typeGet full object template
GET/api/aml/sciot/promptsGet all prompts
GET/api/aml/sciot/templatesGet 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

IssuePossible CauseDiagnosis MethodSolution
Prompt generation failedsciot_templates has no dataSELECT COUNT(*) FROM sciot_templatesRun AML import
LLM returns emptyPrompt too long or malformedCheck LLM response logsCheck prompt template
Creation failedBlocked by validation ruleCheck execution historyCheck validate rules
Duplicate numberSequence value not updatedSELECT * FROM sciot_sequencesUpdate current_value
SCSAI submission failedField type errorCheck AML contentCheck 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

IssueSeveritySuggestion
Two rule tables coexist (sciot_rules vs sciot_rules_v2)HighMigrate uniformly to sciot_rules_v2
No singleton for database connectionMediumCreate a unified SciotDatabase singleton
AMLEngine does not consume the rule engineHighUse the rule engine uniformly

6.2 Performance Optimization

  1. Add indexes to sciot_rules_v2: (scope, item_type_name, is_active, priority)
  2. Rule execution supports parallelism (for rules without dependencies)
  3. Implement cache warming: preload frequently used rules at startup

6.3 Feature Enhancements

  1. Rule testing sandbox: POST /api/rule-engine/test`
  2. Rule self-optimization: analyze execution history and automatically adjust priorities
  3. Prompt A/B testing: supported via parent_id and score fields

7. File Index

FilePurpose
server/core/rule-engine.jsUnified rule engine core (2268 lines)
server/routes/rule-engine.jsRule engine API routes (722 lines)
server/routes/aml.jsSCIOT data API (4847 lines)
src/views/RulesAndTemplates.vueRule template management UI
src/views/StaffCapabilities.vueBasic capability operations UI

Document updated: 2026-05-31

← 返回案例列表

Try 左帮右臂 Industrial Agent — your digital workforce

Available as a WeChat mini program, web app (ylxt.chat) and desktop client. Start from whichever fits your workflow.

🌐 Web App 💻 Desktop Download 📞 Call 189-8606-6876
WeChat mini program QR
Scan for the WeChat mini program
Share:
🤖 Try Now →
🤖
🎁