首页 理论 架构 工程 文档 白皮书 著作 研究 案例 下载 博客 关于 开始使用 →

第208章 UpdateEngine

第208章 UpdateEngine

208.1 UpdateEngine概述

在ICAI系统中,系统经过对象计算、状态计算、知识计算、能力计算、方法计算、行为执行、反馈、诊断、修复和学习之后,最终必须将已经确认的变化反映到系统当前认知结构中。

因此,学习并不是整个更新过程的终点。

第207章LearningEngine解决的是:

哪些已经发生并验证的事实,可以成为新的学习依据?

第208章UpdateEngine解决的是:

已经确认的变化,应当如何更新系统中的状态、知识、能力以及个体结构?

因此:

UpdateEngine=StateUpdate+KnowledgeUpdate+CapabilityUpdate+IndividualStructureUpdateUpdateEngine = StateUpdate + KnowledgeUpdate + CapabilityUpdate + IndividualStructureUpdate

其中:

  • StateUpdate:状态更新;
  • KnowledgeUpdate:知识更新;
  • CapabilityUpdate:能力更新;
  • IndividualStructureUpdate:个体结构更新。

统一模型定义为:

UE=(I,ΔF,R,C,V,U,T)UE=(I,\Delta F,R,C,V,U,T)

其中:

  • I:Input,更新输入;
  • ΔF:Fact Change,事实变化;
  • R:Rule,更新规则;
  • C:Condition,更新条件;
  • V:Verification,验证结果;
  • U:Update,更新结果;
  • T:Time,更新时间。

UpdateEngine的核心不是“发现变化”,而是:

Current+VerifiedChange→UpdatedStateCurrent + VerifiedChange \rightarrow UpdatedState

即:

当前结构 + 已验证变化 → 新结构。


208.2 Update与Learning的区别

UpdateEngine与第207章LearningEngine必须严格区分。

LearningEngine:

Evidence→Comparison→Verification→Learning→UpdateCandidateEvidence \rightarrow Comparison \rightarrow Verification \rightarrow Learning \rightarrow UpdateCandidate

UpdateEngine:

UpdateCandidate→Condition→Rule→Verification→ActualUpdateUpdateCandidate \rightarrow Condition \rightarrow Rule \rightarrow Verification \rightarrow ActualUpdate

因此:

LearningEngine≠UpdateEngineLearningEngine \neq UpdateEngine

LearningEngine主要回答:

这个变化是否构成学习?
应该更新什么?

UpdateEngine主要回答:

已经确认要更新以后,
系统当前结构如何发生变化?

例如:

执行失败
↓
诊断
↓
原因确认
↓
验证
↓
LearningEngine
↓
Method Update Candidate
↓
UpdateEngine
↓
Method Condition真正改变

但是本章重点关注:

状态
知识
能力
个体结构

的统一更新机制。


208.3 UpdateEngine的核心原则

UpdateEngine必须遵循五项基本原则。

208.3.1 已验证变化原则

只有已经确认的变化才能进入正式更新:

Verified(ΔF)=TrueVerified(\Delta F)=True

未经验证的数据只能保持为:

Candidate
Observation
Unverified

不能直接改变正式认知结构。


208.3.2 最小更新原则

系统不能因为一个局部事实变化而无条件重建整个个体。

定义:

ΔU=Minimum(VerifiedChange)\Delta U=Minimum(VerifiedChange)

即:

只更新已经被证明发生变化的部分。

例如:

State changed

不应导致:

Knowledge全部重建
Capability全部重建
Individual全部重建

而应该只更新受影响部分。


208.3.3 一致性原则

更新后的对象必须满足:

Valid(Ut+1)=Structure∧State∧Relation∧ConditionValid(U_{t+1}) = Structure \land State \land Relation \land Condition

如果更新后产生结构冲突,则不能直接提交。


208.3.4 可追踪原则

每一次正式更新都必须能够追溯:

旧值
↓
变化事实
↓
规则
↓
验证
↓
新值

因此:

UpdateTrace=Before+Change+Rule+Verification+AfterUpdateTrace = Before + Change + Rule + Verification + After


208.3.5 原子更新原则

一次相关更新应当保持逻辑一致。

例如:

Capability State

发生变化后,同时依赖该能力状态的结构也可能需要同步处理。

因此可以使用:

Begin Update
↓
Calculate
↓
Validate
↓
Apply
↓
Verify
↓
Commit

如果更新计算失败:

Rollback Database Transaction

但必须注意:

数据库事务回滚不能撤销已经发生在外部世界的真实行为。

这与第185章IndividualService中的事务原则保持一致。


208.4 UpdateEngine输入模型

UpdateEngine的输入可以定义为:

InputU=(O,S,K,C,M,I,ΔF,R,V,T)Input_U=(O,S,K,C,M,I,\Delta F,R,V,T)

其中:

  • O:Object,对象;
  • S:State,当前状态;
  • K:Knowledge,当前知识;
  • C:Capability,当前能力;
  • M:Method,当前方法;
  • I:Individual,当前个体;
  • ΔF:已确认事实变化;
  • R:更新规则;
  • V:验证结果;
  • T:时间。

不同更新类型使用不同输入。

例如:

状态更新:
State + Event + Condition + Rule

知识更新:
Knowledge + VerifiedFact + Condition + Rule

能力更新:
Capability + VerifiedFact + Verification + Rule

个体结构更新:
Individual + StructuralChange + Relation + Verification

208.5 更新计算统一模型

UpdateEngine首先需要计算:

ΔX=Compare(Xt,Xc)\Delta X=Compare(X_t,X_c)

其中:

  • X_t:当前正式结构;
  • X_c:新的候选结构;
  • ΔX:结构变化。

然后:

CanUpdate=ValidChange∧Condition∧Rule∧VerificationCanUpdate = ValidChange \land Condition \land Rule \land Verification

如果:

CanUpdate=FalseCanUpdate=False

则:

No Update

如果:

CanUpdate=TrueCanUpdate=True

则:

Update Candidate
→
Apply Update
→
Validate
→
Verify
→
New State

208.6 StateUpdate——状态更新

状态是ICAI最频繁发生变化的认知结构之一。

状态模型:

S=(O,V,T,C,R)S=(O,V,T,C,R)

其中:

  • O:Owner,状态所属对象;
  • V:Value,状态值;
  • T:Time,时间;
  • C:Context,上下文;
  • R:Reason,状态变化原因。

UpdateEngine不负责重新计算状态转换规则。

状态转换候选由StateEngine计算:

T(St,E,C)→ScT(S_t,E,C)\rightarrow S_c

UpdateEngine负责将已经验证的状态变化应用到正式状态:

St+ΔS→St+1S_t+\Delta S\rightarrow S_{t+1}


208.6.1 状态更新条件

定义:

CanUpdateState=StateExists∧ValidTransition∧VerifiedCanUpdateState = StateExists \land ValidTransition \land Verified

其中:

  • StateExists:当前状态存在;
  • ValidTransition:状态转换合法;
  • Verified:变化已验证。

例如:

Ready
↓
Execution
↓
Completed

只有Execution实际完成并产生有效结果后:

Ready
→
Completed

才能成为正式状态。


208.6.2 状态更新与状态历史

当前状态:

State

与状态历史:

StateHistory

必须分开。

更新:

Ready
→
Running

数据库应形成:

Current State:
Running

同时保留:

History:
Ready
→
Running

因此:

CurrentState≠StateHistoryCurrentState\neq StateHistory

状态历史是未来Memory、Experience、Diagnosis和Learning的重要数据来源。


208.7 KnowledgeUpdate——知识更新

知识模型:

K=(S,P,O,C,St)K=(S,P,O,C,S_t)

其中:

  • S:Subject;
  • P:Predicate;
  • O:Object;
  • C:Condition;
  • S_t:Knowledge State。

知识更新:

Kt+1=Update(Kt,ΔK)K_{t+1}=Update(K_t,\Delta K)

其中:

  • K_t:当前知识;
  • ΔK:已验证知识变化;
  • K_{t+1}:更新后的知识。

208.7.1 知识新增

如果:

Kt=∅K_t=\varnothing

并且:

Verified(ΔK)=TrueVerified(\Delta K)=True

则:

Kt+1=Create(ΔK)K_{t+1}=Create(\Delta K)

例如:

Object A
supports
Object B

经过验证后,可以正式建立:

A → supports → B

208.7.2 知识修改

如果旧知识存在:

A → requires → Resource1

新的验证事实为:

A → requires → Resource2

则UpdateEngine必须先比较:

ΔK=Compare(Kt,Kc)\Delta K=Compare(K_t,K_c)

然后形成:

Before:
Resource1

Change:
Resource1 → Resource2

After:
Resource2

同时保存更新原因和验证依据。


208.7.3 知识失效

知识也可能被更新为:

outdated
invalid
conflicted
archived

例如:

Knowledge
↓
Condition Changed
↓
Old Knowledge No Longer Applies
↓
Update
↓
outdated

这里不能简单删除旧知识。

因为:

DeleteKnowledge≠InvalidateKnowledgeDeleteKnowledge \neq InvalidateKnowledge

失效知识仍然具有历史价值。


208.8 CapabilityUpdate——能力更新

能力模型:

C=(T,Co,S,R,V)C=(T,Co,S,R,V)

其中:

  • T:Type;
  • Co:Condition;
  • S:State;
  • R:Range;
  • V:Verification。

能力更新:

Ct+1=Update(Ct,ΔC,V)C_{t+1}=Update(C_t,\Delta C,V)


208.8.1 能力状态更新

例如:

Capability:
available

经过验证发现:

Capability:
blocked

UpdateEngine执行:

Cstate,t→Cstate,t+1C_{state,t} \rightarrow C_{state,t+1}

形成:

available
→
blocked

但是更新原因必须明确:

Resource
State
Condition
Environment
Verification

不能简单因为:

Execution Failed

就把能力标记为失效。


208.8.2 能力范围更新

能力范围:

Range=(Min,Max,Unit,Scope)Range=(Min,Max,Unit,Scope)

如果实际验证结果证明:

理论范围:
0~100

验证范围:
0~80

则可以更新:

Verified Range:
0~80

但不能因此直接修改理论能力:

TheoryRange≠VerifiedRangeTheoryRange\neq VerifiedRange

两者必须保持区别。


208.8.3 能力恢复

如果RepairEngine完成修复并经过验证:

blocked
↓
repair
↓
verification
↓
available

UpdateEngine可以执行:

CapabilityStatet+1=availableCapabilityState_{t+1} = available

因此:

RepairEngine

负责修复过程;

UpdateEngine

负责将验证后的修复结果反映到正式能力状态。


208.9 IndividualStructureUpdate——个体结构更新

这是UpdateEngine与普通状态更新最重要的区别。

Individual不是单一字段,而是一个组合认知对象。

第166~168章已经建立:

I=(O,K,C,M,B,MM,E)I=(O,K,C,M,B,MM,E)

其中:

  • I:Individual;
  • O:Object;
  • K:Knowledge;
  • C:Capability;
  • M:Method;
  • B:Behavior;
  • MM:Memory;
  • E:Experience。

因此个体结构更新不能简单理解为:

UPDATE individuals

而应该理解为:

Individualt+1=Individualt+ΔStructureIndividual_{t+1} = Individual_t + \Delta Structure


208.10 个体结构的组成更新

个体内部至少包含:

Individual
├── Objects
├── Knowledge
├── Capabilities
├── Methods
├── Behaviors
├── Memory
├── Experience
└── Relations

因此结构变化可能来自:

Object Added
Object Removed
Object Changed
Knowledge Added
Knowledge Modified
Capability Changed
Method Changed
Relation Added
Relation Removed
Memory Updated
Experience Updated

UpdateEngine必须首先识别:

StructuralChangeTypeStructuralChangeType


208.11 个体对象增加

例如Individual原来:

Individual
├── Object A
└── Object B

经过实际事实确认后发现存在:

Object C

则:

Ot+1=Ot+{OC}O_{t+1}=O_t+\{O_C\}

形成:

Individual
├── Object A
├── Object B
└── Object C

但新增对象必须经过:

Identity Validation
Type Validation
Relation Validation
State Initialization

不能因为某个字段出现就直接创建正式对象。


208.12 个体对象删除

删除同样需要严格区分:

Physical Delete
Logical Delete
Archive
Deactivate

例如:

Object C

不再有效时,不一定意味着:

DELETE FROM objects

可能应该:

Object C
→
inactive

或者:

Object C
→
archived

原因是历史、关系、记忆和经验可能仍然引用该对象。

因此:

DeleteObject≠DeleteHistoryDeleteObject\neq DeleteHistory


208.13 个体关系更新

个体结构更新还包括对象之间关系变化。

关系模型:

R=(ID,O1,T,O2,C,S,Tm)R=(ID,O_1,T,O_2,C,S,Tm)

例如:

A
depends_on
B

后来验证发现:

A
no_longer_depends_on
B

UpdateEngine需要形成:

Relation Update

而不是简单删除所有关系数据。

可以:

active
→
inactive

或者:

active
→
expired

具体状态由RelationEngine计算并由UpdateEngine应用。


208.14 个体结构更新的级联问题

个体内部结构之间存在依赖。

例如:

Object
↓
Capability
↓
Method
↓
Behavior

如果某个Object发生变化,可能影响Capability。

例如:

Object State
↓
Capability Availability
↓
Method Availability
↓
Decision Candidate

因此UpdateEngine需要识别:

DependencyDependency

但不能无条件进行无限级联。

必须采用:

Actual Change
↓
Dependency Check
↓
Affected Structure
↓
Update Candidate
↓
Validation
↓
Update

例如:

Object State Changed
↓
Capability affected
↓
Method affected
↓
Decision Candidate affected

最终只更新真正受影响的部分。


208.15 更新影响范围

定义更新影响范围:

Impact(U)={X1,X2,…,Xn}Impact(U)=\{X_1,X_2,…,X_n\}

例如:

State Update

可能影响:

Capability
Method
Decision

但如果没有明确依赖关系,则不应该自动修改。

因此:

Update(X)⇒Update(Y)Update(X) \Rightarrow Update(Y)

只有在:

Depends(Y,X)=TrueDepends(Y,X)=True

并且相关更新规则存在时才成立。

这可以防止系统出现错误级联更新。


208.16 UpdateEngine统一更新流程

统一流程:

Verified Change
↓
Load Current Structure
↓
Compare
↓
Identify Update Type
↓
Evaluate Condition
↓
Evaluate Rule
↓
Calculate Update Candidate
↓
Validate Candidate
↓
Apply Update
↓
Verify Updated Structure
↓
Save History
↓
Return Update Result

可以表示为:

Fv→Xt→Compare→Candidate→Validate→Apply→Verify→Xt+1F_v \rightarrow X_t \rightarrow Compare \rightarrow Candidate \rightarrow Validate \rightarrow Apply \rightarrow Verify \rightarrow X_{t+1}

其中:

  • F_v:已验证事实;
  • X_t:当前结构;
  • X_{t+1}:更新后的结构。

208.17 UpdateResult

UpdateEngine的输出不能只有:

success

应该定义:

UR=(T,O,B,Δ,N,V,S,R,Tm)UR=(T,O,B,\Delta,N,V,S,R,Tm)

其中:

  • T:Update Type;
  • O:Update Object;
  • B:Before;
  • Δ:Change;
  • N:After;
  • V:Verification;
  • S:Status;
  • R:Reason;
  • Tm:Time。

例如:

Update Type:
capability_state

Target:
Capability-001

Before:
available

Change:
available → blocked

After:
blocked

Verification:
verified

Status:
updated

Reason:
capability condition failed

这样才能支持完整追踪。


208.18 UpdateEngine PHP工程实现

以下实现采用PHP 5.6/7兼容语法。

<?php

abstract class Engine
{
    public function calculate($input)
    {
        return array();
    }
}

class UpdateEngine extends Engine
{
    public function calculate($input)
    {
        $input = is_array($input)
            ? $input
            : array();

        $verification = $this->verifyInput($input);

        if (!$verification['valid']) {
            return array(
                'engine' => 'UpdateEngine',
                'status' => 'blocked',
                'reason' => $verification['reason'],
                'updates' => array()
            );
        }

        $updates = array();

        if (!empty($input['state'])) {
            $updates[] =
                $this->calculateStateUpdate(
                    $input['state'],
                    $input
                );
        }

        if (!empty($input['knowledge'])) {
            $updates[] =
                $this->calculateKnowledgeUpdate(
                    $input['knowledge'],
                    $input
                );
        }

        if (!empty($input['capability'])) {
            $updates[] =
                $this->calculateCapabilityUpdate(
                    $input['capability'],
                    $input
                );
        }

        if (!empty($input['individual'])) {
            $updates[] =
                $this->calculateIndividualUpdate(
                    $input['individual'],
                    $input
                );
        }

        return array(
            'engine' => 'UpdateEngine',
            'status' => 'calculated',
            'updates' => $updates
        );
    }

    protected function verifyInput($input)
    {
        if (empty($input['verified'])) {
            return array(
                'valid' => false,
                'reason' => 'change_not_verified'
            );
        }

        if (empty($input['change'])) {
            return array(
                'valid' => false,
                'reason' => 'change_not_found'
            );
        }

        if (empty($input['update_allowed'])) {
            return array(
                'valid' => false,
                'reason' => 'update_not_allowed'
            );
        }

        return array(
            'valid' => true,
            'reason' => 'valid'
        );
    }

    protected function calculateStateUpdate(
        $state,
        $input
    ) {
        $oldValue =
            isset($state['value'])
            ? $state['value']
            : null;

        $newValue =
            isset($state['new_value'])
            ? $state['new_value']
            : $oldValue;

        return array(
            'type' => 'state_update',
            'target_id' =>
                isset($state['owner_id'])
                ? $state['owner_id']
                : null,
            'before' => $oldValue,
            'change' => $newValue !== $oldValue,
            'after' => $newValue,
            'status' =>
                $newValue !== $oldValue
                ? 'updated'
                : 'no_change'
        );
    }

    protected function calculateKnowledgeUpdate(
        $knowledge,
        $input
    ) {
        $oldValue =
            isset($knowledge['old'])
            ? $knowledge['old']
            : null;

        $newValue =
            isset($knowledge['new'])
            ? $knowledge['new']
            : null;

        return array(
            'type' => 'knowledge_update',
            'target_id' =>
                isset($knowledge['id'])
                ? $knowledge['id']
                : null,
            'before' => $oldValue,
            'change' => $oldValue !== $newValue,
            'after' => $newValue,
            'status' =>
                $oldValue !== $newValue
                ? 'updated'
                : 'no_change'
        );
    }

    protected function calculateCapabilityUpdate(
        $capability,
        $input
    ) {
        $oldState =
            isset($capability['old_state'])
            ? $capability['old_state']
            : null;

        $newState =
            isset($capability['new_state'])
            ? $capability['new_state']
            : null;

        $oldRange =
            isset($capability['old_range'])
            ? $capability['old_range']
            : null;

        $newRange =
            isset($capability['new_range'])
            ? $capability['new_range']
            : null;

        $stateChanged =
            $oldState !== $newState;

        $rangeChanged =
            $oldRange !== $newRange;

        return array(
            'type' => 'capability_update',
            'target_id' =>
                isset($capability['id'])
                ? $capability['id']
                : null,
            'before' => array(
                'state' => $oldState,
                'range' => $oldRange
            ),
            'change' =>
                $stateChanged || $rangeChanged,
            'after' => array(
                'state' => $newState,
                'range' => $newRange
            ),
            'status' =>
                ($stateChanged || $rangeChanged)
                ? 'updated'
                : 'no_change'
        );
    }

    protected function calculateIndividualUpdate(
        $individual,
        $input
    ) {
        $before =
            isset($individual['before'])
            ? $individual['before']
            : array();

        $after =
            isset($individual['after'])
            ? $individual['after']
            : $before;

        $change =
            $this->compareStructure(
                $before,
                $after
            );

        return array(
            'type' => 'individual_structure_update',
            'target_id' =>
                isset($individual['id'])
                ? $individual['id']
                : null,
            'before' => $before,
            'change' => $change,
            'after' => $after,
            'status' =>
                $change
                ? 'updated'
                : 'no_change'
        );
    }

    protected function compareStructure(
        $before,
        $after
    ) {
        return serialize($before) !==
            serialize($after);
    }
}

这里需要特别强调:

以上代码是Learning/Update计算层的PHP结构实现,并不等于已经在用户实际WSaiOS工程中完成安装、运行和测试。

如果要进入真实工程,仍然需要根据实际项目中的:

Domain Object
Repository
Service
Engine
Database Schema
StateEngine
KnowledgeEngine
CapabilityEngine

进行接口适配和实际测试。


208.19 状态更新PHP计算

可以进一步将状态更新单独封装:

class StateUpdateCalculator
{
    public function calculate(
        $currentState,
        $candidateState,
        $verified
    ) {
        if (!$verified) {
            return array(
                'status' => 'blocked',
                'reason' => 'not_verified'
            );
        }

        if ($currentState === $candidateState) {
            return array(
                'status' => 'no_change',
                'before' => $currentState,
                'after' => $candidateState
            );
        }

        return array(
            'status' => 'update_candidate',
            'before' => $currentState,
            'after' => $candidateState
        );
    }
}

这里返回:

update_candidate

而不是立即写数据库。

真正提交仍由:

StateService

负责。


208.20 知识更新PHP计算

知识更新可以使用:

class KnowledgeUpdateCalculator
{
    public function calculate(
        $current,
        $candidate,
        $verified
    ) {
        if (!$verified) {
            return array(
                'status' => 'blocked'
            );
        }

        if ($current === $candidate) {
            return array(
                'status' => 'no_change',
                'before' => $current,
                'after' => $candidate
            );
        }

        return array(
            'status' => 'update_candidate',
            'before' => $current,
            'after' => $candidate
        );
    }
}

KnowledgeEngine负责知识计算。

UpdateEngine负责:

确认变化
→
计算更新
→
生成更新结果

KnowledgeService负责最终协调和持久化。


208.21 能力更新PHP计算

能力更新必须区分:

State Change
Range Change
Condition Change
Verification Change

因此可以定义:

class CapabilityUpdateCalculator
{
    public function calculate(
        $current,
        $candidate,
        $verified
    ) {
        if (!$verified) {
            return array(
                'status' => 'blocked',
                'reason' => 'verification_failed'
            );
        }

        $changes = array();

        if (
            isset($current['state']) &&
            isset($candidate['state']) &&
            $current['state'] !==
            $candidate['state']
        ) {
            $changes['state'] = array(
                'before' => $current['state'],
                'after' => $candidate['state']
            );
        }

        if (
            isset($current['range']) &&
            isset($candidate['range']) &&
            $current['range'] !==
            $candidate['range']
        ) {
            $changes['range'] = array(
                'before' => $current['range'],
                'after' => $candidate['range']
            );
        }

        return array(
            'status' =>
                empty($changes)
                ? 'no_change'
                : 'update_candidate',
            'changes' => $changes
        );
    }
}

这样能够避免把:

能力状态变化

误认为:

能力类型变化

也避免把:

验证范围变化

误认为:

理论能力范围变化

208.22 个体结构更新PHP计算

个体结构更新的核心是比较:

ItI_t

与:

IcI_c

形成:

ΔI=Compare(It,Ic)\Delta I=Compare(I_t,I_c)

可以拆成:

Object Change
Knowledge Change
Capability Change
Method Change
Behavior Change
Memory Change
Experience Change
Relation Change

例如:

class IndividualStructureUpdateCalculator
{
    public function calculate(
        $current,
        $candidate,
        $verified
    ) {
        if (!$verified) {
            return array(
                'status' => 'blocked'
            );
        }

        $result = array();

        $sections = array(
            'objects',
            'knowledge',
            'capabilities',
            'methods',
            'behaviors',
            'memory',
            'experience',
            'relations'
        );

        foreach ($sections as $section) {

            $old = isset($current[$section])
                ? $current[$section]
                : array();

            $new = isset($candidate[$section])
                ? $candidate[$section]
                : array();

            if (serialize($old) !==
                serialize($new)) {

                $result[$section] = array(
                    'before' => $old,
                    'after' => $new
                );
            }
        }

        return array(
            'status' =>
                empty($result)
                ? 'no_change'
                : 'update_candidate',
            'changes' => $result
        );
    }
}

这里的重点不是一次性重写Individual,而是得到:

Individual ΔStructure

再交由IndividualService进行真正的组合更新。


208.23 UpdateEngine与Service层

UpdateEngine不应该直接承担完整业务流程。

架构:

Controller
↓
IndividualService / UpdateService
↓
UpdateEngine
↓
StateEngine
KnowledgeEngine
CapabilityEngine
RelationEngine
↓
Update Result
↓
Domain Service
↓
Repository
↓
MySQL

其中:

UpdateEngine

负责:

更新计算
更新候选
变化比较
更新验证

StateService

负责:

状态读取
状态更新
状态历史
状态持久化

KnowledgeService

负责:

知识读取
知识更新
知识历史
知识持久化

CapabilityService

负责:

能力读取
能力更新
能力验证
能力历史

IndividualService

负责:

个体整体结构编排
多个Service调用
事务
整体结果

因此:

UpdateEngine≠UpdateServiceUpdateEngine \neq UpdateService


208.24 UpdateEngine与LearningEngine

两者形成前后关系:

LearningEngine
↓
学习结果
↓
Update Candidate
↓
UpdateEngine
↓
正式结构更新

因此:

Learning→UpdateCandidate→UpdateLearning \rightarrow UpdateCandidate \rightarrow Update

例如:

Execution Failure
↓
Diagnosis
↓
Verification
↓
LearningEngine
↓
Capability Update Candidate
↓
UpdateEngine
↓
Capability State Update

这里LearningEngine负责:

“应该改变什么。”

UpdateEngine负责:

“确认后如何改变当前结构。”


208.25 UpdateEngine与事务

更新涉及多个对象时,应使用事务协调。

例如:

Capability
↓
Method
↓
Individual Structure

同时发生变化时:

Begin Transaction
↓
Update Capability
↓
Update Method
↓
Update Individual Relation
↓
Validate
↓
Commit

如果数据库操作失败:

Rollback

但是:

External Execution

已经发生的现实事实不能通过数据库Rollback消除。

因此:

DatabaseRollback≠WorldRollbackDatabaseRollback \neq WorldRollback

这一原则必须保持。


208.26 UpdateHistory

每一次更新都必须保存历史。

统一历史模型:

UH=(I,T,O,B,Δ,N,R,V,Tm)UH=(I,T,O,B,\Delta,N,R,V,Tm)

其中:

  • I:Update ID;
  • T:Update Type;
  • O:Target;
  • B:Before;
  • Δ:Change;
  • N:After;
  • R:Reason;
  • V:Verification;
  • Tm:Time。

例如:

Update:
U-00031

Target:
Capability-12

Before:
available

Change:
available → blocked

After:
blocked

Reason:
verified capability restriction

Verification:
passed

这样后续:

MemoryEngine
ExperienceEngine
LearningEngine
DiagnosisEngine

都可以读取更新历史。


208.27 UpdateEngine数据库结构

可以建立:

update_records

id
individual_id
update_type
target_type
target_id
before_data
change_data
after_data
reason
verification_state
created_at

update_history

id
update_id
operation
before_data
after_data
reason
created_at

状态仍使用:

states
state_history

知识使用:

knowledge
knowledge_history
knowledge_evidence

能力使用:

capabilities
capability_history
capability_verifications

个体结构关系继续使用:

individuals
individual_objects
individual_knowledge
individual_capabilities
individual_methods
individual_behaviors
individual_memory
individual_experience
object_relations

因此UpdateEngine不需要创建一张巨大的“所有认知数据表”。


208.28 更新状态模型

UpdateEngine本身也需要状态。

建议:

Created
↓
Loaded
↓
Calculated
↓
Validated
↓
Applied
↓
Verified
↓
Completed

异常:

Calculated
↓
ValidationFailed

或者:

Applied
↓
VerificationFailed
↓
Diagnosis

因此:

UpdateState=Created→Loaded→Calculated→Validated→Applied→Verified→CompletedUpdateState = Created \rightarrow Loaded \rightarrow Calculated \rightarrow Validated \rightarrow Applied \rightarrow Verified \rightarrow Completed


208.29 更新失败处理

如果更新候选不合法:

Update Candidate
↓
Validation Failed

不能强制写入。

如果更新已经执行,但验证失败:

Applied
↓
Verification Failed

则需要:

Feedback
↓
Diagnosis
↓
Repair
↓
Recalculate

形成:

Update
↓
Verification
↓
Failure
↓
Diagnosis
↓
Repair
↓
Update Recalculation

这与第204章DiagnosisEngine和第206章RepairEngine保持一致。


208.30 UpdateEngine完整闭环

最终形成:

Result→Feedback→Learning→UpdateCandidate→UpdateEngine→State/Knowledge/Capability/IndividualResult \rightarrow Feedback \rightarrow Learning \rightarrow UpdateCandidate \rightarrow UpdateEngine \rightarrow State/Knowledge/Capability/Individual

进一步:

UpdatedStructure→Knowledge→Capability→Method→DecisionUpdatedStructure \rightarrow Knowledge \rightarrow Capability \rightarrow Method \rightarrow Decision

然后:

Decision→Behavior→Action→Execution→ResultDecision \rightarrow Behavior \rightarrow Action \rightarrow Execution \rightarrow Result

形成:

Execution
↓
Result
↓
Feedback
↓
LearningEngine
↓
Update Candidate
↓
UpdateEngine
↓
State / Knowledge / Capability / Individual
↓
Method / Decision
↓
Behavior
↓
Action
↓
Execution

这就是ICAI中的:

运行 → 学习 → 更新 → 再运行闭环。


208.31 UpdateEngine完整工程定位

经过第207章LearningEngine与本章UpdateEngine之后,ICAI的学习更新体系可以分成两个阶段。

第一阶段:

LearningLearning

负责:

发现已经验证的变化
↓
形成学习结果
↓
生成Update Candidate

第二阶段:

UpdateUpdate

负责:

读取当前结构
↓
计算变化
↓
验证更新条件
↓
应用更新
↓
验证新结构
↓
保存历史

因此:

LearningEngine→UpdateEngineLearningEngine \rightarrow UpdateEngine

不是重复关系,而是:

Learning=认知变化形成Learning = 认知变化形成 Update=认知结构落实Update = 认知结构落实


208.32 本章总结

第208章建立UpdateEngine。

UpdateEngine的核心职责是:

状态更新
知识更新
能力更新
个体结构更新

统一模型:

UE=(I,ΔF,R,C,V,U,T)UE=(I,\Delta F,R,C,V,U,T)

核心计算:

ΔX=Compare(Xt,Xc)\Delta X=Compare(X_t,X_c)

更新条件:

CanUpdate=ValidChange∧Condition∧Rule∧VerificationCanUpdate = ValidChange \land Condition \land Rule \land Verification

状态更新:

St+ΔS→St+1S_t+\Delta S\rightarrow S_{t+1}

知识更新:

Kt+ΔK→Kt+1K_t+\Delta K\rightarrow K_{t+1}

能力更新:

Ct+ΔC→Ct+1C_t+\Delta C\rightarrow C_{t+1}

个体结构更新:

It+ΔI→It+1I_t+\Delta I\rightarrow I_{t+1}

其中最重要的工程原则是:

LearningEngine负责产生经过学习计算确认的更新候选,UpdateEngine负责将经过验证的变化计算并落实到正式认知结构。

因此完整链路为:

Result
↓
Feedback
↓
Memory
↓
Experience
↓
LearningEngine
↓
Update Candidate
↓
UpdateEngine
↓
State Update
Knowledge Update
Capability Update
Individual Structure Update
↓
New Cognitive Structure
↓
Decision
↓
Behavior
↓
Execution
↓
Result

由此,WSaiOS-ICAI不再只是一个能够保存历史、记忆经验和执行规则的系统,而形成了:

Perception→Cognition→Execution→Feedback→Learning→Update→New CognitionPerception \rightarrow Cognition \rightarrow Execution \rightarrow Feedback \rightarrow Learning \rightarrow Update \rightarrow New\ Cognition

的完整离散认知更新闭环。

整个过程仍然建立在:

对象、属性、状态、关系、事实、规则、条件、历史、记忆、经验、验证、离散计算和PHP OOP工程结构

之上,不依赖LLM、Transformer、Embedding、Vector Search、Prompt Engineering、神经网络或LLM API。

208.33 UpdateEngine端到端更新案例

为了说明UpdateEngine如何真正参与ICAI的认知循环,下面建立一个完整的端到端案例。

本案例不使用LLM、Transformer、Embedding、Vector Search或神经网络,而完全采用:

Object
State
Knowledge
Capability
Method
Decision
Behavior
Action
Execution
Result
Feedback
Diagnosis
Learning
Update
Verification

进行离散计算。


208.33.1 初始个体结构

假设ICAI中存在一个Individual:

Individual: I-001

该Individual具有一个执行任务:

Goal:
完成Object-A的处理任务

当前对象:

Object-A
State = ready

当前能力:

Capability-C1
Type = process_object
State = available
Range = 0~100

当前方法:

Method-M1
Type = standard_process
Condition:
Resource >= 1

方法过程:

Action-A1
↓
Action-A2
↓
Action-A3

当前知识:

K1:
Object-A
supports
Method-M1

当前个体结构可以表示为:

I-001
├── Object-A
│   └── State = ready
├── Capability-C1
│   └── State = available
├── Method-M1
│   └── Condition = Resource >= 1
└── Knowledge-K1
    └── A supports M1

208.33.2 第一次决策

系统首先进行:

Goal
↓
CapabilityEngine
↓
Capability-C1 available
↓
MethodEngine
↓
Method-M1 applicable
↓
DecisionEngine
↓
Select Method-M1

DecisionEngine得到:

Decision:
D-001

Candidate:
Method-M1

Status:
selected

然后:

Decision
↓
BehaviorEngine
↓
Behavior-B1
↓
Action-A1
↓
Action-A2
↓
Action-A3
↓
Execution

208.33.3 实际执行发生异常

假设实际运行环境发生:

Resource = 1

而Action-A2实际需要:

Resource = 2

因此:

Action-A2
↓
Execution
↓
Failed

实际结果:

Expected Result:
success

Actual Result:
failed

Reason:
resource_insufficient

此时系统不能直接得出:

Capability-C1 = invalid

因为失败原因可能来自:

Capability
Method
Action
Resource
Environment
Condition

所以首先进入反馈和诊断。


208.33.4 FeedbackEngine处理

Execution产生:

Execution:
E-001

Result:
failed

Expected:
success

Actual:
failed

FeedbackEngine计算:

C=Compare(Re,Ra)C=Compare(R_e,R_a)

其中:

  • R_e:Expected Result,期望结果;
  • R_a:Actual Result,实际结果;
  • C:Comparison,比较结果。

得到:

Comparison:
Different

Status:
failed

同时产生状态变化:

Behavior:
running → failed

以及环境事实:

Resource = 1

于是:

Execution
↓
Result
↓
Feedback

208.33.5 DiagnosisEngine确定原因

DiagnosisEngine接收:

Expected:
success

Actual:
failed

Resource:
1

Required Resource:
2

进行原因分析:

CauseScore(Ci)=WeEi+WhHi+WmMi+WxXi+WrRi+WcCiCauseScore(C_i) = W_eE_i + W_hH_i + W_mM_i + W_xX_i + W_rR_i + W_cC_i

其中资源不足具有明确证据:

Required = 2
Actual = 1

因此得到:

Diagnosis:
D-001

Problem:
Method execution failed

Cause:
Resource Insufficient

Cause Type:
Resource

State:
confirmed

Verification:
passed

这一步非常重要。

系统现在知道:

失败 ≠ 能力失效

而是:

失败
→
资源不足

因此Capability-C1暂时不能直接标记为invalid。


208.33.6 Repair与再次执行

系统可以产生Repair Candidate:

Repair:
Resource Replacement

经过DecisionEngine选择后:

Decision
↓
Repair Candidate
↓
Resource Replacement
↓
Execution

资源变为:

Resource = 2

然后重新执行:

Action-A2
↓
Execution
↓
Success

最终:

Expected:
success

Actual:
success

Verification:

passed

于是系统获得新的重要事实:

Method-M1在Resource >= 2时可以正常完成。

208.33.7 LearningEngine形成学习结果

现在LearningEngine开始工作。

它接收到:

History
Feedback
Diagnosis
Repair
Execution Result
Verification

形成:

ΔF=ActualFact−PreviousFact\Delta F = ActualFact – PreviousFact

旧事实:

Method-M1
Condition:
Resource >= 1

新的验证事实:

Method-M1
实际成功条件:
Resource >= 2

于是:

Learning Candidate:
Method Condition Update

学习条件:

CanLearn=EvidenceValid∧ActualValid∧Verified∧ApplicableCanLearn = EvidenceValid \land ActualValid \land Verified \land Applicable

本案例:

EvidenceValid = true
ActualValid = true
Verified = true
Applicable = true

所以:

CanLearn=TrueCanLearn=True

LearningEngine产生:

Learning:
L-001

Type:
method_condition_update

Target:
Method-M1

Before:
Resource >= 1

New:
Resource >= 2

Reason:
verified execution evidence

208.33.8 LearningEngine产生Update Candidate

LearningEngine不直接修改Method。

它只产生:

Update Candidate

即:

UC-001

Target:
Method-M1

Type:
Method Condition Update

Before:
Resource >= 1

After:
Resource >= 2

Evidence:
E-001, E-002

Verification:
passed

此时:

LearningEngine
↓
Update Candidate

208.33.9 UpdateEngine接收更新候选

UpdateEngine接收到:

Current Method:
M1

Current Condition:
Resource >= 1

Candidate Condition:
Resource >= 2

Verification:
passed

Rule:
method_condition_update_allowed = true

首先计算:

ΔM=Compare(Mt,Mc)\Delta M = Compare(M_t,M_c)

得到:

Old:
Resource >= 1

New:
Resource >= 2

因此:

Change:
true

208.33.10 UpdateEngine验证更新条件

UpdateEngine执行:

CanUpdate=ValidChange∧Condition∧Rule∧VerificationCanUpdate = ValidChange \land Condition \land Rule \land Verification

本案例:

ValidChange = true
Condition = true
Rule = true
Verification = true

所以:

CanUpdate=TrueCanUpdate=True

UpdateEngine产生:

Update Status:
validated

208.33.11 Method正式更新

UpdateEngine现在计算:

Mt+1=Update(Mt,ΔM)M_{t+1}=Update(M_t,\Delta M)

因此:

Method-M1
Before:
Resource >= 1

After:
Resource >= 2

形成新的正式方法结构:

Method-M1
Type:
standard_process

Condition:
Resource >= 2

Process:
A1 → A2 → A3

注意这里并没有修改:

Method Type
Process
Action Sequence

因为实际证据只证明:

Condition

发生了变化。

这正是第208章的最小更新原则

ΔU=Minimum(VerifiedChange)\Delta U=Minimum(VerifiedChange)

即:

验证了什么,只更新什么。


208.33.12 能力是否需要更新?

此时系统还必须判断:

Capability-C1

是否需要更新。

原能力:

Capability-C1
State:
available

Range:
0~100

实际情况:

Capability itself:
verified

Failure Cause:
Resource Insufficient

因此:

Capability State:
available

保持不变。

也就是说:

Method Update = Yes
Capability Update = No

这体现了UpdateEngine不能进行无依据的级联修改。


208.33.13 状态更新

虽然Capability没有改变,但Behavior和Execution状态发生了变化。

第一次执行:

Behavior-B1:
running → failed

修复后重新执行:

Behavior-B1:
failed → running

最终:

Behavior-B1:
running → completed

Execution:

E-001:
failed

E-002:
completed

因此StateEngine计算:

St+1=Transition(St,E,C)S_{t+1}=Transition(S_t,E,C)

UpdateEngine应用已经验证的状态结果:

Behavior:
completed

Object-A:
processed

Execution:
completed

208.33.14 知识更新

当前Knowledge:

K1:
Object-A supports Method-M1

实际运行后又得到一个新的事实:

K2:
Method-M1 requires Resource >= 2

该事实经过Verification后进入UpdateEngine。

因此:

Kt+1=Kt+ΔKK_{t+1}=K_t+\Delta K

形成:

Knowledge-K2

Subject:
Method-M1

Predicate:
requires_resource

Object:
2

Condition:
Resource >= 2

State:
verified

此时个体知识结构变成:

Knowledge
├── K1:
│   A supports M1
│
└── K2:
    M1 requires Resource >= 2

208.33.15 个体结构更新

由于Method-M1发生正式更新,因此Individual的组合结构也发生变化。

原结构:

I-001
├── Object-A
├── Capability-C1
├── Method-M1
│   └── Resource >= 1
└── Knowledge
    └── K1

更新后:

I-001
├── Object-A
├── Capability-C1
├── Method-M1
│   └── Resource >= 2
└── Knowledge
    ├── K1
    └── K2

因此:

It+1=Update(It,ΔI)I_{t+1}=Update(I_t,\Delta I)

其中:

ΔI:
Method-M1.Condition
+
Knowledge-K2

而:

Capability-C1

没有发生结构变化。


208.33.16 更新历史

UpdateEngine必须保存完整更新历史。

Update-001

Update Type:
state_update

Target:
Behavior-B1

Before:
running

After:
failed

Reason:
execution_failure

Verification:
verified

Update-002

Update Type:
state_update

Target:
Behavior-B1

Before:
failed

After:
completed

Reason:
repair_and_reexecution

Verification:
verified

Update-003

Update Type:
knowledge_update

Target:
Knowledge-K2

Before:
not_exists

After:
M1 requires Resource >= 2

Reason:
verified_execution

Verification:
passed

Update-004

Update Type:
method_update

Target:
Method-M1

Before:
Resource >= 1

After:
Resource >= 2

Reason:
verified_execution_and_diagnosis

Verification:
passed

这样以后MemoryEngine和ExperienceEngine可以读取:

Update History

进一步形成:

Memory
↓
Experience
↓
Learning

208.33.17 更新后的第二次决策

现在系统再次遇到:

Goal:
完成Object-B处理

DecisionEngine重新加载:

Capability
Method
Knowledge
State

此时Method-M1已经是:

Condition:
Resource >= 2

如果当前环境:

Resource = 1

那么MatchingEngine直接得到:

Method-M1:
unmatched

而不是让系统再次执行后才发现失败。

于是:

Goal
↓
Capability
↓
Method Matching
↓
M1 Condition Failed
↓
DecisionEngine
↓
寻找其他Method

这就是一次真正的认知更新。

第一次系统:

不知道
→
执行
→
失败
→
诊断
→
修复
→
验证
→
学习
→
更新

第二次系统:

已经知道
→
匹配条件
→
提前排除

208.33.18 整个端到端闭环

本案例完整流程可以表示为:

Goal→Capability→Method→Decision→Behavior→Action→ExecutionGoal \rightarrow Capability \rightarrow Method \rightarrow Decision \rightarrow Behavior \rightarrow Action \rightarrow Execution

第一次执行:

Execution→Failure→Feedback→Diagnosis→Repair→ExecutionExecution \rightarrow Failure \rightarrow Feedback \rightarrow Diagnosis \rightarrow Repair \rightarrow Execution

修复成功:

Result→Verification→LearningResult \rightarrow Verification \rightarrow Learning

学习产生:

Learning→UpdateCandidateLearning \rightarrow UpdateCandidate

UpdateEngine执行:

UpdateCandidate→StateUpdate→KnowledgeUpdate→MethodUpdate→IndividualStructureUpdateUpdateCandidate \rightarrow StateUpdate \rightarrow KnowledgeUpdate \rightarrow MethodUpdate \rightarrow IndividualStructureUpdate

最后:

UpdatedIndividual→NewDecision→NewBehaviorUpdatedIndividual \rightarrow NewDecision \rightarrow NewBehavior

形成完整闭环:

Goal
↓
Capability
↓
Method
↓
Decision
↓
Behavior
↓
Action
↓
Execution
↓
Failure
↓
Feedback
↓
Diagnosis
↓
Repair
↓
Execution
↓
Success
↓
Verification
↓
LearningEngine
↓
Update Candidate
↓
UpdateEngine
├── State Update
├── Knowledge Update
├── Capability Update
└── Individual Structure Update
↓
Updated Individual
↓
Matching
↓
Decision
↓
Behavior
↓
Execution

208.33.19 本案例体现的四个关键原则

第一,失败不等于能力失效

本案例中:

Execution Failed

原因是:

Resource Insufficient

所以:

Capability-C1 = available

没有被错误修改。


第二,学习不等于更新

LearningEngine得到:

Method Update Candidate

并没有直接修改Method。

真正修改由:

UpdateEngine

完成。

因此:

Learning≠UpdateLearning \neq Update


第三,更新不等于全部重建

实际验证只证明:

Method Condition

发生变化。

所以只修改:

Resource >= 1
→
Resource >= 2

而不修改:

Method Type
Process
Action
Capability

因此:

Update=MinimumVerifiedChangeUpdate=MinimumVerifiedChange


第四,更新必须改变未来行为

如果更新以后第二次运行仍然:

Resource = 1

系统应该在Method Matching阶段发现:

Method-M1:
unmatched

而不是再次执行相同错误。

因此一次真正有效的Update必须满足:

UpdateEffect→FutureCognitiveChangeUpdateEffect \rightarrow FutureCognitiveChange

即:

更新后的结构必须能够影响未来的匹配、判断、决策或执行。

这也是UpdateEngine存在的根本工程意义。


208.34 端到端案例总结

本案例可以浓缩为:

Failure→Diagnosis→Repair→Verification→Learning→Update→FutureDecisionChangeFailure \rightarrow Diagnosis \rightarrow Repair \rightarrow Verification \rightarrow Learning \rightarrow Update \rightarrow FutureDecisionChange

第一次系统不知道:

Resource >= 2

所以:

执行
→
失败

经过实际执行和验证以后:

Knowledge:
M1 requires Resource >= 2

Method:
Condition = Resource >= 2

下一次系统面对:

Resource = 1

就可以在执行之前得到:

M1 = Unmatched

从而:

DecisionEngine

选择其他方法或者进入重新规划。

因此,本案例完整体现了:

PastExecution→VerifiedLearning→StructuralUpdate→FutureCognitionPastExecution \rightarrow VerifiedLearning \rightarrow StructuralUpdate \rightarrow FutureCognition

这就是ICAI中UpdateEngine真正承担的功能:

不是简单修改数据库字段,而是把已经验证的现实变化落实为个体未来可以使用的正式认知结构。

Leave a Reply

Your email address will not be published. Required fields are marked *