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

第210章 ICAI Behavior Engine

第210章 ICAI Behavior Engine

210.1 ICAI Behavior Engine概述

第209章建立了ICAI Cognitive Engine,将:

Object
State
Relation
Scene
Knowledge

统一形成:

CognitiveContext

认知结构完成以后,ICAI还必须解决一个更加具体的问题:

当前个体已经知道“是什么、处于什么状态、具有什么关系以及当前是什么场景”之后,应该如何形成一个可以实际执行的行为?

这就进入Behavior Engine。

ICAI中的行为不是突然产生的。

一个完整行为必须经过:

Goal
↓
Capability
↓
Matching
↓
Method
↓
Decision
↓
Behavior
↓
Action

因此,本章定义:

BehaviorEngine=Goal+Capability+Matching+Method+Decision+Behavior+ActionBehaviorEngine = Goal + Capability + Matching + Method + Decision + Behavior + Action

这里并不是说BehaviorEngine吞并这些Engine,而是表示:

Behavior的形成依赖这些认知和行动结构。

各层职责分别为:

GoalEngine
    ↓
CapabilityEngine
    ↓
MatchingEngine
    ↓
MethodEngine
    ↓
DecisionEngine
    ↓
BehaviorEngine
    ↓
ActionEngine

最终由:

ExecutionEngine

负责实际运行。

因此:

BehaviorEngine≠ActionEngine≠ExecutionEngineBehaviorEngine \neq ActionEngine \neq ExecutionEngine

BehaviorEngine负责的是:

把已经确定的目标、能力、匹配结果、方法和决策组织成当前可执行的行为结构。


210.2 为什么Behavior需要完整的前置链

如果直接定义:

Behavior
↓
Action

就会产生一个严重问题:

为什么执行这个Action?

因此Behavior必须具有来源。

完整来源:

Need
↓
Goal
↓
Capability
↓
Matching
↓
Method
↓
Decision
↓
Behavior
↓
Action

其中:

Goal

说明:

要达到什么结果?
Capability

说明:

是否具有完成目标所需要的能力?
Matching

说明:

当前对象、状态、条件、能力和方法是否匹配?
Method

说明:

采用什么过程完成目标?
Decision

说明:

多个可行方案中选择哪一个?
Behavior

说明:

已经选定的方法如何组织成当前行为?
Action

说明:

具体执行什么动作?

因此:

Goal→Capability→Matching→Method→Decision→Behavior→ActionGoal \rightarrow Capability \rightarrow Matching \rightarrow Method \rightarrow Decision \rightarrow Behavior \rightarrow Action

构成ICAI行为形成的基本链。


210.3 Goal——行为的目标来源

Goal是Behavior的最终方向。

Goal模型:

G=(ID,N,T,C,P,S)G=(ID,N,T,C,P,S)

其中:

  • ID:Goal唯一标识;
  • N:Name,目标名称;
  • T:Type,目标类型;
  • C:Condition,目标条件;
  • P:Priority,目标优先级;
  • S:State,目标状态。

例如:

Goal-G1

Type:
process

Target:
Object-A

Condition:
Resource >= 2

Priority:
high

State:
active

这个Goal本身不是Behavior。

Goal只回答:

希望最终达到什么状态或结果?

例如:

Goal:
Object-A processing completed

并没有说明:

采用什么方法
执行哪些动作
动作按照什么顺序执行

因此:

Goal≠MethodGoal\neq Method Goal≠BehaviorGoal\neq Behavior


210.4 Goal与Behavior的关系

Behavior必须服务于Goal。

定义:

BehaviorGoalRelation=(B,G,C)BehaviorGoalRelation=(B,G,C)

其中:

  • B:Behavior;
  • G:Goal;
  • C:Goal Condition。

基本关系:

B→GB\rightarrow G

表示:

Behavior
服务于
Goal

例如:

Goal-G1
完成Object-A处理

Behavior-B1
执行标准处理流程

则:

Behavior-B1
achieves
Goal-G1

但必须注意:

Behavior建立

不代表:

Goal完成

只有实际执行:

Behavior
↓
Action
↓
Execution
↓
Result
↓
Verification

并且结果满足Goal条件以后,才能判断:

Goal = completed

210.5 Capability——行为的能力基础

Behavior不能脱离Capability。

Capability模型:

Ca=(T,Co,S,R,V)C_a=(T,Co,S,R,V)

其中:

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

Capability回答:

当前个体是否具备执行目标所需要的能力?

例如:

Capability-C1

Type:
process_object

Condition:
Resource >= 2

State:
available

Range:
Object-A

Verification:
verified

则:

Goal
↓
Required Capability
↓
Capability Check

如果能力不存在:

No Capability

则不能直接建立Behavior。


210.6 Capability与Behavior的关系

Behavior需要能力作为前提。

定义:

BehaviorReady=GoalValid∧CapabilityAvailable∧MethodMatched∧DecisionSelectedBehaviorReady = GoalValid \land CapabilityAvailable \land MethodMatched \land DecisionSelected

其中:

  • GoalValid:目标有效;
  • CapabilityAvailable:能力当前可用;
  • MethodMatched:方法与当前条件匹配;
  • DecisionSelected:已经产生有效决策。

因此:

Capability

不是Behavior本身。

Capability表示:

能做

Behavior表示:

现在准备按照选定过程去做

210.7 Matching——能力与方法之间的条件检查

Capability存在,并不代表一定适合当前Goal。

例如:

Capability:
process_object

Current Object:
Object-A

Current State:
blocked

Required Condition:
ready

此时:

Capability Exists

但是:

Capability Match = false

因此必须经过MatchingEngine。

统一匹配:

Match(X,R,C)→MMatch(X,R,C) \rightarrow M

其中:

  • X:候选对象;
  • R:要求;
  • C:当前条件;
  • M:匹配结果。

Matching结果不能只返回:

true
false

而应该保留:

matched
partial
unmatched
unknown
blocked
conflicted
expired
invalid

210.8 Behavior建立前的完整匹配

Behavior建立之前至少需要检查:

Goal
↓
Object
↓
State
↓
Capability
↓
Method
↓
Condition
↓
Resource
↓
Relation
↓
Scene

因此可以定义:

BehaviorMatch=G∧O∧S∧Ca∧M∧Co∧RBehaviorMatch = G \land O \land S \land C_a \land M \land Co \land R

其中:

  • G:Goal有效;
  • O:Object有效;
  • S:State允许;
  • C_a:Capability可用;
  • M:Method匹配;
  • Co:Condition满足;
  • R:Resource满足。

只有匹配通过以后,才允许进入Decision。


210.9 Method——Behavior的过程来源

Method定义:

M=(T,C,P,A,R)M=(T,C,P,A,R)

其中:

  • T:Method Type;
  • C:Condition;
  • P:Process;
  • A:Action Sequence;
  • R:Expected Result。

Method回答:

通过什么过程完成Goal?

例如:

Method-M1

Type:
standard_process

Condition:
Resource >= 2

Process:
Step-1
Step-2
Step-3

Actions:
A1
A2
A3

Expected Result:
success

Method已经描述了:

做什么过程

但它仍然不是Behavior。


210.10 Method与Behavior的区别

二者非常容易混淆。

Method:

定义应该采用什么过程

Behavior:

当前个体按照选定Method形成的运行实例

例如:

Method-M1
标准处理方法

可以被:

Individual-I1

在:

Object-A

上实例化为:

Behavior-B1

因此:

Method→BehaviorMethod \rightarrow Behavior

可以理解为:

Method = 可复用过程结构
Behavior = 当前运行实例

210.11 Decision——从多个方法中选择一个

当只有一个有效Method时:

Method-M1

可以直接进入Behavior。

但实际ICAI中通常可能存在:

Method-M1
Method-M2
Method-M3

因此需要DecisionEngine。

Decision模型:

D=(C,Ca,R,H)D=(C,Ca,R,H)

其中:

  • C:Decision Condition;
  • Ca:Candidates;
  • R:Decision Result;
  • H:Decision History。

DecisionEngine计算:

Candidate
↓
Condition
↓
Evaluation
↓
Score
↓
Selection
↓
Decision Result

210.12 Decision与Method的关系

MethodEngine负责:

Method计算
Method组合
Method验证
Method候选

DecisionEngine负责:

多个候选中选择

因此:

MethodEngine≠DecisionEngineMethodEngine \neq DecisionEngine

例如:

Method-M1
Score = 80

Method-M2
Score = 72

Method-M3
Score = 55

DecisionEngine得到:

Selected = M1

然后:

M1
↓
BehaviorEngine
↓
Behavior-B1

210.13 Behavior——行为结构

Behavior模型:

B=(G,C,M,O,S,A,E,R)B=(G,C,M,O,S,A,E,R)

其中:

  • G:Goal;
  • C:Condition;
  • M:Selected Method;
  • O:Object;
  • S:Current State;
  • A:Action Sequence;
  • E:Execution Reference;
  • R:Result Reference。

Behavior不是单一动作。

例如:

Behavior-B1

包含:

Goal-G1
Method-M1
Object-A
Current State=ready

Actions:
A1
A2
A3

因此:

Behavior=Goal+Method+Object+State+ActionSequenceBehavior = Goal + Method + Object + State + ActionSequence


210.14 Behavior的建立条件

可以定义:

BehaviorReady=Gv∧Ov∧Sv∧Ca∧Mv∧Dv∧CovBehaviorReady = G_v \land O_v \land S_v \land C_a \land M_v \land D_v \land Co_v

其中:

  • G_v:Goal有效;
  • O_v:Object有效;
  • S_v:State允许行为;
  • C_a:Capability可用;
  • M_v:Method有效;
  • D_v:Decision已经产生有效选择;
  • Co_v:当前条件有效。

如果任意必要条件不成立:

Behavior
=
blocked

而不是强制创建一个可执行Behavior。


210.15 Behavior的状态

Behavior可以具有:

created
↓
validated
↓
ready
↓
running
↓
completed

异常状态:

blocked
failed
cancelled
interrupted

因此:

SB=f(SG,SM,SA,SE,C)S_B = f(S_G,S_M,S_A,S_E,C)

其中:

  • S_B:Behavior State;
  • S_G:Goal State;
  • S_M:Method State;
  • S_A:Action State;
  • S_E:Execution State;
  • C:Current Condition。

Behavior状态必须能够根据实际Action和Execution结果进行更新。


210.16 Action——行为中的具体动作

Action模型:

A=(T,O,C,P,R,S)A=(T,O,C,P,R,S)

其中:

  • T:Action Type;
  • O:Target Object;
  • C:Condition;
  • P:Parameters;
  • R:Expected Result;
  • S:Action State。

Action回答:

具体操作什么?

例如:

A1:
load object

A2:
process object

A3:
save result

这些Action共同组成:

Behavior-B1

因此:

Behavior={A1,A2,…,An}Behavior = \{A_1,A_2,\ldots,A_n\}


210.17 Behavior不是Action集合这么简单

虽然Behavior包含Action,但Behavior还有更高层结构:

Goal
Method
Condition
Object
State
Action Sequence
Execution
Result

例如:

Behavior-B1
Goal = G1
Method = M1
Object = A
State = ready

Actions:
A1 → A2 → A3

如果只有:

A1 → A2 → A3

只能称为:

Action Sequence

而不能完整称为Behavior。

因此:

Behavior⊃ActionSequenceBehavior \supset ActionSequence


210.18 Action Sequence

Behavior必须保持Action顺序。

定义:

AS={A1,A2,…,An}AS=\{A_1,A_2,\ldots,A_n\}

并定义:

A1→A2→A3→⋯→AnA_1 \rightarrow A_2 \rightarrow A_3 \rightarrow \cdots \rightarrow A_n

每一个Action都可能具有:

Precondition
Input
Target
Parameter
Expected Result
Next Condition

例如:

A1 completed
↓
Condition C1
↓
A2 allowed

如果A1失败:

A1 failed
↓
A2 blocked

因此Behavior Engine必须维护Action依赖关系。


210.19 Behavior Engine的核心职责

本章定义:

BehaviorEngine=BehaviorCalculation+BehaviorValidation+BehaviorConstruction+ActionOrganizationBehaviorEngine = BehaviorCalculation + BehaviorValidation + BehaviorConstruction + ActionOrganization

即:

Behavior Calculation
Behavior Validation
Behavior Construction
Action Organization

BehaviorEngine主要负责:

  1. 接收Goal;
  2. 接收Capability结果;
  3. 接收Matching结果;
  4. 接收Method;
  5. 接收Decision;
  6. 建立Behavior;
  7. 建立Action Sequence;
  8. 检查Behavior条件;
  9. 管理Behavior状态;
  10. 输出Action执行结构。

210.20 Behavior Engine输入

为了避免第209章出现的输入循环问题,本章明确BehaviorEngine输入。

定义:

BI=(I,CC,G,Ca,Mt,D,M,Ru,Co,T)BI= (I,CC,G,C_a,Mt,D,M,Ru,Co,T)

其中:

  • I:Individual;
  • CC:CognitiveContext;
  • G:Goal;
  • C_a:Capability Result;
  • Mt:Matching Result;
  • D:Decision Result;
  • M:Selected Method;
  • Ru:Rule;
  • Co:Condition;
  • T:Time。

这里:

CognitiveContext

来自第209章。

而:

Goal
Capability
Matching
Method
Decision

来自上层认知与决策Engine。


210.21 Behavior Engine输出

定义:

BO=(B,A,S,E,R,V,T)BO= (B,A,S,E,R,V,T)

其中:

  • B:Behavior;
  • A:Action Sequence;
  • S:Behavior State;
  • E:Execution Reference;
  • R:Result Reference;
  • V:Verification;
  • T:Time。

在Behavior刚建立时:

Execution Reference

和:

Result Reference

可能为空。

这是合法状态,因为:

Behavior建立

发生在:

Execution

之前。


210.22 Behavior Engine完整计算流程

完整流程:

CognitiveContext
↓
Goal
↓
Capability Calculation
↓
Capability Matching
↓
Method Matching
↓
Method Candidates
↓
Decision
↓
Selected Method
↓
Behavior Calculation
↓
Behavior Validation
↓
Action Sequence Construction
↓
Behavior Ready
↓
ActionEngine

因此:

CC→G→Ca→Matching→M→D→B→ACC \rightarrow G \rightarrow C_a \rightarrow Matching \rightarrow M \rightarrow D \rightarrow B \rightarrow A


210.23 Goal到Behavior的统一计算

可以进一步建立:

B=F(G,Ca,Mt,M,D,O,S,Co)B= F(G,C_a,Mt,M,D,O,S,Co)

其中:

  • G:Goal;
  • C_a:Capability;
  • Mt:Matching;
  • M:Method;
  • D:Decision;
  • O:Object;
  • S:State;
  • Co:Condition。

Behavior不是随机生成。

它必须能够追溯:

为什么产生这个Behavior?

答案必须是:

Goal
+
Capability
+
Matching
+
Method
+
Decision

210.24 Behavior可追溯链

每个Behavior应该保存来源ID:

behavior_id
goal_id
capability_id
matching_id
method_id
decision_id
object_id

因此可以形成:

Behavior-B1
├── Goal-G1
├── Capability-C1
├── Matching-MT1
├── Method-M1
├── Decision-D1
└── Object-O1

这样当Behavior执行失败时,可以追溯:

Behavior
↓
Decision
↓
Method
↓
Matching
↓
Capability
↓
Goal

为后续DiagnosisEngine提供完整证据。


210.25 Behavior与Risk

Behavior建立以后,还不能认为一定安全。

必须检查:

Risk
Conflict
Condition
Resource
State

例如:

Behavior-B1

可能需要:

Resource-R1

但是当前:

Resource-R1
State=blocked

则:

Behavior

不能进入Ready。

因此:

BehaviorSafe=BehaviorReady∧RiskAllowed∧ConflictFreeBehaviorSafe = BehaviorReady \land RiskAllowed \land ConflictFree

如果风险超过规则允许范围:

Behavior = blocked

或者:

Decision Recalculation

210.26 Behavior与Conflict

如果两个Action发生资源冲突:

A1 uses Resource-R1
A2 uses Resource-R1

并且规则规定:

R1 cannot be used simultaneously

则:

ConflictEngine

检测冲突。

BehaviorEngine不能自行忽略这个冲突。

处理流程:

Behavior
↓
Conflict Detection
↓
Conflict Result
↓
Decision
↓
Action Sequence Adjustment

因此:

Conflict→Decision→BehaviorUpdateConflict \rightarrow Decision \rightarrow BehaviorUpdate


210.27 Behavior与State

Behavior的建立必须考虑当前State。

例如:

Object-A
State=ready

允许:

Behavior-B1

但如果:

Object-A
State=blocked

则:

Behavior-B1

可能变为:

blocked

或者等待合法状态转换:

blocked
↓
Repair
↓
ready
↓
Behavior Ready

BehaviorEngine不直接修改State。

State变化由:

StateEngine
+
StateService

负责。


210.28 Behavior与ActionEngine

二者边界必须明确。

BehaviorEngine:

组织Action

ActionEngine:

计算Action

例如Behavior:

B1
A1 → A2 → A3

BehaviorEngine负责:

A1先执行
A1成功后允许A2
A2成功后允许A3

ActionEngine负责:

A1具体参数
A1目标
A1条件
A1执行准备

因此:

BehaviorEngine→ActionEngineBehaviorEngine \rightarrow ActionEngine


210.29 Behavior与ExecutionEngine

ActionEngine准备好Action以后:

ActionEngine
↓
ExecutionEngine

ExecutionEngine负责:

真实运行

例如:

Action:
process Object-A

ExecutionEngine产生:

Execution-E1

实际结果:

success

或者:

failed

因此:

Action≠ExecutionAction \neq Execution Behavior≠ExecutionBehavior \neq Execution


210.30 Behavior完成条件

Behavior完成不能只看:

所有Action执行结束

还必须考虑:

Result
State
Condition
Verification

定义:

BehaviorCompleted=ActionsCompleted∧ResultValid∧StateValid∧ConditionSatisfiedBehaviorCompleted = ActionsCompleted \land ResultValid \land StateValid \land ConditionSatisfied

如果:

Action全部执行

但最终Result失败:

Behavior
=
failed

而不是:

completed

210.31 Behavior与Goal完成的区别

必须严格区分:

BehaviorCompleted≠GoalCompletedBehaviorCompleted \neq GoalCompleted

例如:

Behavior-B1

已经执行完所有Action。

但Result:

processing failed

则:

Behavior = failed
Goal = failed

另一种情况:

Behavior completed

但是目标要求:

Verification

尚未完成。

则:

Behavior = completed
Goal = pending

因此Goal完成必须由GoalEngine结合Result和Verification判断。


210.32 Behavior Engine的PHP实现

以下采用PHP 5.6/7兼容结构。

<?php

class BehaviorEngine
{
    protected $goalEngine;
    protected $capabilityEngine;
    protected $matchingEngine;
    protected $methodEngine;
    protected $decisionEngine;

    public function __construct(
        $goalEngine,
        $capabilityEngine,
        $matchingEngine,
        $methodEngine,
        $decisionEngine
    ) {
        $this->goalEngine = $goalEngine;
        $this->capabilityEngine = $capabilityEngine;
        $this->matchingEngine = $matchingEngine;
        $this->methodEngine = $methodEngine;
        $this->decisionEngine = $decisionEngine;
    }

    public function calculate($input)
    {
        if (!is_array($input)) {
            $input = array();
        }

        $goal = isset($input['goal'])
            ? $input['goal']
            : array();

        $capability = isset($input['capability'])
            ? $input['capability']
            : array();

        $matching = isset($input['matching'])
            ? $input['matching']
            : array();

        $method = isset($input['method'])
            ? $input['method']
            : array();

        $decision = isset($input['decision'])
            ? $input['decision']
            : array();

        $object = isset($input['object'])
            ? $input['object']
            : array();

        $state = isset($input['state'])
            ? $input['state']
            : array();

        $condition = isset($input['condition'])
            ? $input['condition']
            : array();

        $ready = $this->checkBehaviorReady(
            $goal,
            $capability,
            $matching,
            $method,
            $decision,
            $object,
            $state,
            $condition
        );

        if (!$ready['ready']) {
            return array(
                'engine' => 'BehaviorEngine',
                'status' => 'blocked',
                'reason' => $ready['reason'],
                'behavior' => array(),
                'actions' => array()
            );
        }

        $behavior = $this->buildBehavior(
            $goal,
            $capability,
            $matching,
            $method,
            $decision,
            $object,
            $state,
            $condition
        );

        $actions = $this->buildActions(
            $method,
            $behavior
        );

        return array(
            'engine' => 'BehaviorEngine',
            'status' => 'ready',
            'behavior' => $behavior,
            'actions' => $actions,
            'state' => 'ready'
        );
    }

    protected function checkBehaviorReady(
        $goal,
        $capability,
        $matching,
        $method,
        $decision,
        $object,
        $state,
        $condition
    ) {
        if (empty($goal)) {
            return array(
                'ready' => false,
                'reason' => 'goal_missing'
            );
        }

        if (empty($object)) {
            return array(
                'ready' => false,
                'reason' => 'object_missing'
            );
        }

        if (empty($capability)) {
            return array(
                'ready' => false,
                'reason' => 'capability_missing'
            );
        }

        if (empty($method)) {
            return array(
                'ready' => false,
                'reason' => 'method_missing'
            );
        }

        if (empty($decision)) {
            return array(
                'ready' => false,
                'reason' => 'decision_missing'
            );
        }

        if (!$this->isMatchingValid($matching)) {
            return array(
                'ready' => false,
                'reason' => 'matching_invalid'
            );
        }

        if (!$this->isStateAllowed($state)) {
            return array(
                'ready' => false,
                'reason' => 'state_not_allowed'
            );
        }

        if (!$this->isConditionValid($condition)) {
            return array(
                'ready' => false,
                'reason' => 'condition_not_valid'
            );
        }

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

    protected function isMatchingValid($matching)
    {
        if (!is_array($matching)) {
            return false;
        }

        if (isset($matching['status'])) {
            return $matching['status'] === 'matched';
        }

        if (isset($matching['matched'])) {
            return $matching['matched'] === true;
        }

        return false;
    }

    protected function isStateAllowed($state)
    {
        if (!is_array($state)) {
            return false;
        }

        if (!isset($state['value'])) {
            return false;
        }

        $allowed = array(
            'ready',
            'available',
            'active'
        );

        return in_array(
            $state['value'],
            $allowed,
            true
        );
    }

    protected function isConditionValid($condition)
    {
        if (!is_array($condition)) {
            return false;
        }

        if (isset($condition['valid'])) {
            return $condition['valid'] === true;
        }

        return true;
    }

    protected function buildBehavior(
        $goal,
        $capability,
        $matching,
        $method,
        $decision,
        $object,
        $state,
        $condition
    ) {
        return array(
            'id' => $this->createBehaviorId(),
            'goal' => $goal,
            'capability' => $capability,
            'matching' => $matching,
            'method' => $method,
            'decision' => $decision,
            'object' => $object,
            'state' => $state,
            'condition' => $condition,
            'status' => 'ready'
        );
    }

    protected function buildActions(
        $method,
        $behavior
    ) {
        $actions = array();

        if (
            isset($method['actions']) &&
            is_array($method['actions'])
        ) {
            foreach (
                $method['actions']
                as $index => $action
            ) {
                $actions[] = array(
                    'sequence' => $index + 1,
                    'behavior_id' =>
                        $behavior['id'],
                    'action' => $action,
                    'status' => 'ready'
                );
            }
        }

        return $actions;
    }

    protected function createBehaviorId()
    {
        return 'B-' . date('YmdHis') .
            '-' . mt_rand(1000, 9999);
    }
}

这段代码的关键并不是简单地创建一个数组,而是建立:

Goal
↓
Capability
↓
Matching
↓
Method
↓
Decision
↓
Behavior
↓
Actions

的结构来源。


210.33 Behavior Engine计算结果示例

输入:

$input = array(
    'goal' => array(
        'id' => 'G1',
        'status' => 'active'
    ),

    'capability' => array(
        'id' => 'C1',
        'status' => 'available'
    ),

    'matching' => array(
        'id' => 'MT1',
        'status' => 'matched'
    ),

    'method' => array(
        'id' => 'M1',
        'status' => 'valid',
        'actions' => array(
            'A1',
            'A2',
            'A3'
        )
    ),

    'decision' => array(
        'id' => 'D1',
        'selected' => 'M1'
    ),

    'object' => array(
        'id' => 'O1',
        'type' => 'device'
    ),

    'state' => array(
        'value' => 'ready'
    ),

    'condition' => array(
        'valid' => true
    )
);

经过BehaviorEngine:

Goal G1
↓
Capability C1
↓
Matching MT1
↓
Method M1
↓
Decision D1
↓
Behavior B1
↓
A1 → A2 → A3

得到:

Behavior-B1
State = ready

然后交给:

ActionEngine

继续处理。


210.34 Behavior Engine不直接执行动作

必须明确:

BehaviorEngine

不能直接:

execute()

实际执行应该是:

BehaviorEngine
↓
ActionEngine
↓
ExecutionEngine

原因是:

BehaviorEngine负责:

组织

ActionEngine负责:

动作计算

ExecutionEngine负责:

真实执行

这样可以避免一个Engine承担全部职责。


210.35 Behavior Engine与Runtime

Behavior不是静态结构。

它必须在Runtime中运行。

Runtime:

Runtime=(I,O,S,C,T)Runtime=(I,O,S,C,T)

Behavior Runtime可以进一步表示:

BRt=(B,O,S,C,A,E,T)BRt=(B,O,S,C,A,E,T)

其中:

  • B:当前Behavior;
  • O:当前Object;
  • S:当前State;
  • C:当前Condition;
  • A:当前Action;
  • E:当前Execution;
  • T:当前Time。

因此:

Behavior
+
Runtime

才形成当前运行中的行为。


210.36 Behavior的动态变化

例如:

Behavior-B1
State=ready

执行:

A1

之后:

Behavior-B1
State=running
CurrentAction=A1

A1成功:

CurrentAction=A2

A2失败:

Behavior-B1
State=failed

然后:

Feedback
↓
Diagnosis
↓
Repair

因此Behavior状态是动态的。


210.37 Behavior与Feedback

Behavior执行后:

Execution
↓
Result
↓
Feedback

FeedbackEngine得到:

Expected Result
Actual Result
State Change
Environment Change

再反馈给Behavior。

因此:

Behaviort→Executiont→Resultt→Feedbackt→Behaviort+1Behavior_t \rightarrow Execution_t \rightarrow Result_t \rightarrow Feedback_t \rightarrow Behavior_{t+1}

Behavior可能因此:

continue
pause
blocked
failed
retry
replanned
completed

210.38 Behavior失败后的处理

如果:

A2 failed

不能直接认为:

Capability failed

必须进入:

Feedback
↓
Abnormality
↓
Diagnosis
↓
Cause

例如原因:

Resource insufficient

则:

Repair
↓
Resource replacement
↓
Re-execution

Behavior可以恢复:

failed
↓
ready
↓
running
↓
completed

具体状态转换仍由StateEngine控制。


210.39 Behavior与Learning

Behavior本身不负责学习。

实际流程:

Behavior
↓
Action
↓
Execution
↓
Result
↓
Feedback
↓
Memory
↓
Experience
↓
Learning

LearningEngine可能发现:

Method-M1
Condition不足

然后形成:

Update Candidate

交给:

UpdateEngine

更新Method。

更新后:

CognitiveEngine
↓
CapabilityEngine
↓
MatchingEngine
↓
MethodEngine
↓
DecisionEngine
↓
BehaviorEngine

重新计算。


210.40 Behavior Engine完整闭环

因此完整行为循环:

CognitiveContext
↓
Goal
↓
Capability
↓
Matching
↓
Method
↓
Decision
↓
Behavior
↓
Action
↓
Execution
↓
Result
↓
Feedback
↓
Diagnosis / Risk / Conflict
↓
Repair / Protection
↓
Verification
↓
Learning
↓
Update
↓
CognitiveContext

数学表示:

Behaviort=F(Goalt,Capabilityt,Matchingt,Methodt,Decisiont,Runtimet)Behavior_t = F( Goal_t, Capability_t, Matching_t, Method_t, Decision_t, Runtime_t )

执行后:

Resultt=Execution(Behaviort)Result_t = Execution(Behavior_t)

更新后:

Behaviort+1=F(Goalt+1,Capabilityt+1,Matchingt+1,Methodt+1,Decisiont+1,Runtimet+1)Behavior_{t+1} = F( Goal_{t+1}, Capability_{t+1}, Matching_{t+1}, Method_{t+1}, Decision_{t+1}, Runtime_{t+1} )


210.41 Behavior Engine的数据库结构

Behavior本身需要独立保存。

可以建立:

behaviors
behavior_actions
behavior_conditions
behavior_executions
behavior_results
behavior_history

其中:

behaviors

保存:

id
individual_id
goal_id
capability_id
matching_id
method_id
decision_id
object_id
state
status
created_at
updated_at

behavior_actions

保存:

id
behavior_id
action_id
sequence
condition
state
status

behavior_executions

保存:

id
behavior_id
action_id
execution_id
status
started_at
ended_at

behavior_results

保存:

id
behavior_id
expected_result
actual_result
status
verification_status
created_at

behavior_history

保存:

id
behavior_id
previous_state
new_state
event
reason
created_at

这样:

Behavior

可以完整追踪自己的生命周期。


210.42 Behavior数据与Method数据的区别

Method数据库保存:

可复用的方法结构

Behavior数据库保存:

某个Individual在某个Goal下实际产生的行为实例

例如:

Method-M1

可以被:

Individual-I1

使用产生:

Behavior-B1

也可以被:

Individual-I2

使用产生:

Behavior-B2

因此:

M1→B1M1 \rightarrow B1

同时:

M1→B2M1 \rightarrow B2

Method可以复用,Behavior是具体实例。


210.43 Behavior与Individual

Behavior必须属于某个Individual的运行过程。

因此:

Behavior⊂IndividualBehavior\subset Individual

例如:

Individual-I1
├── Goal-G1
├── Capability-C1
├── Method-M1
├── Decision-D1
└── Behavior-B1

另一个Individual:

Individual-I2
├── Goal-G2
├── Capability-C2
├── Method-M1
├── Decision-D2
└── Behavior-B2

即使使用相同Method:

M1

由于:

Individual
Object
State
Condition
Decision

不同,最终Behavior也可以不同。


210.44 Behavior Engine中的确定性原则

ICAI Behavior Engine不通过:

随机生成

形成Behavior。

也不通过:

LLM
Transformer
Embedding
Vector Search
Prompt Engineering
Neural Network
LLM API

产生行为。

Behavior来源必须可以追溯:

Behavior=F(Goal,Capability,Matching,Method,Decision,Object,State,Condition,Rule)Behavior = F( Goal, Capability, Matching, Method, Decision, Object, State, Condition, Rule )

因此每一个Behavior都应该能够回答:

目标是什么?
↓
需要什么能力?
↓
是否匹配?
↓
使用什么方法?
↓
为什么选择这个方法?
↓
产生什么Behavior?
↓
包含哪些Action?

这构成ICAI行为计算的可解释性。


210.45 Behavior Engine与七级结构

本章可以把Behavior形成过程正式定义为七级:

第一层:Goal

回答:

我要达到什么目标?
第二层:Capability

回答:

我是否具备完成目标的能力?
第三层:Matching

回答:

当前条件是否匹配?
第四层:Method

回答:

采用什么过程?
第五层:Decision

回答:

多个候选中选择哪个?
第六层:Behavior

回答:

当前如何组织成一个行为?
第七层:Action

回答:

具体执行什么?

因此:

Goal→Capability→Matching→Method→Decision→Behavior→ActionGoal \rightarrow Capability \rightarrow Matching \rightarrow Method \rightarrow Decision \rightarrow Behavior \rightarrow Action

构成:

ICAI行为形成链。


210.46 七级结构的职责边界

层级 核心问题 核心Engine
Goal 达到什么? GoalEngine
Capability 能不能做? CapabilityEngine
Matching 是否匹配? MatchingEngine
Method 怎么做? MethodEngine
Decision 选哪个? DecisionEngine
Behavior 当前如何组织? BehaviorEngine
Action 具体做什么? ActionEngine

最后:

ExecutionEngine

负责:

实际发生什么

所以:

Action≠ExecutionAction\neq Execution


210.47 Behavior Engine与Execution Engine完整边界

最终形成:

Goal
↓
Capability
↓
Matching
↓
Method
↓
Decision
↓
Behavior
↓
Action
↓
Execution

可以分别理解为:

Goal
= 目标

Capability
= 能力

Matching
= 条件适配

Method
= 方法

Decision
= 选择

Behavior
= 行为组织

Action
= 具体动作

Execution
= 实际发生

这八个概念不能混为一谈。


210.48 ICAI Behavior Engine统一公式

最终定义:

BE=F(G,Ca,Mt,M,D,O,S,Co,Ru,T)BE = F( G, C_a, Mt, M, D, O, S, Co, Ru, T )

其中:

  • G:Goal;
  • C_a:Capability;
  • Mt:Matching;
  • M:Method;
  • D:Decision;
  • O:Object;
  • S:State;
  • Co:Condition;
  • Ru:Rule;
  • T:Time。

输出:

BO=(B,A,SB,Ex,R,V,T)BO= (B,A,S_B,E_x,R,V,T)

其中:

  • B:Behavior;
  • A:Action Sequence;
  • S_B:Behavior State;
  • E_x:Execution Reference;
  • R:Actual Result Reference;
  • V:Verification;
  • T:Time。

因此:

BE(BI)→BOBE(BI) \rightarrow BO


210.49 ICAI Behavior Engine完整架构

至此,ICAI从认知到行为可以形成:

CognitiveEngine
│
├── ObjectEngine
├── StateEngine
├── RelationEngine
├── SceneEngine
└── KnowledgeEngine
        ↓
CapabilityEngine
        ↓
MatchingEngine
        ↓
MethodEngine
        ↓
DecisionEngine
        ↓
BehaviorEngine
        ↓
ActionEngine
        ↓
ExecutionEngine

再通过:

Result
↓
Feedback
↓
Memory
↓
Experience
↓
Learning
↓
Update

重新进入:

CognitiveEngine

210.50 Behavior Engine完整闭环模型

最终形成:

Cognitive→Goal→Capability→Matching→Method→Decision→Behavior→Action→Execution→ResultCognitive \rightarrow Goal \rightarrow Capability \rightarrow Matching \rightarrow Method \rightarrow Decision \rightarrow Behavior \rightarrow Action \rightarrow Execution \rightarrow Result

然后:

Result→Feedback→Diagnosis→Repair→Verification→Learning→UpdateResult \rightarrow Feedback \rightarrow Diagnosis \rightarrow Repair \rightarrow Verification \rightarrow Learning \rightarrow Update

最终:

Update→Cognitivet+1Update \rightarrow Cognitive_{t+1}

形成:

Cognitivet→Goalt→Capabilityt→Matchingt→Methodt→Decisiont→Behaviort→Actiont→Executiont→Resultt→Feedbackt→Learningt→Updatet→Cognitivet+1Cognitive_t \rightarrow Goal_t \rightarrow Capability_t \rightarrow Matching_t \rightarrow Method_t \rightarrow Decision_t \rightarrow Behavior_t \rightarrow Action_t \rightarrow Execution_t \rightarrow Result_t \rightarrow Feedback_t \rightarrow Learning_t \rightarrow Update_t \rightarrow Cognitive_{t+1}

这构成ICAI从:

认知 → 目标 → 能力 → 匹配 → 方法 → 决策 → 行为 → 动作 → 执行 → 结果 → 学习 → 更新 → 再认知

的完整离散计算闭环。


210.51 本章总结

第210章正式建立了:

ICAI Behavior Engine

Behavior不是一个孤立的Engine,也不是简单的Action集合。

它必须建立在完整的前置认知与决策链上:

Goal→Capability→Matching→Method→Decision→Behavior→ActionGoal \rightarrow Capability \rightarrow Matching \rightarrow Method \rightarrow Decision \rightarrow Behavior \rightarrow Action

其中:

Goal定义:

要达到什么?

Capability定义:

能不能做?

Matching判断:

当前是否匹配?

Method定义:

采用什么过程?

Decision选择:

采用哪个候选方案?

Behavior组织:

当前如何形成一个行为实例?

Action定义:

具体执行什么动作?

然后:

Action
↓
Execution

进入实际运行。

因此:

Behavior=F(Goal,Capability,Matching,Method,Decision,Object,State,Condition)Behavior = F( Goal, Capability, Matching, Method, Decision, Object, State, Condition )

而Behavior真正完成以后,还必须通过:

Result
+
State
+
Condition
+
Verification

进行确认。

所以:

BehaviorCompleted≠GoalCompletedBehaviorCompleted \neq GoalCompleted

最终ICAI形成:

CognitiveContext
↓
Goal
↓
Capability
↓
Matching
↓
Method
↓
Decision
↓
Behavior
↓
Action
↓
Execution
↓
Result
↓
Feedback
↓
Memory
↓
Experience
↓
Learning
↓
Update
↓
Re-Cognition

这说明ICAI中的“行为”并不是简单的程序动作,而是一个由目标、能力、匹配、方法、决策和当前运行状态共同约束形成的可追踪行为实例

其本质仍然是:

Object+State+Relation+Scene+Knowledge+Goal+Capability+Method+Decision+Rule+Condition+Discrete CalculationObject + State + Relation + Scene + Knowledge + Goal + Capability + Method + Decision + Rule + Condition + Discrete\ Calculation

共同形成的可验证行为工程体系。

同时必须保持严格工程边界:

BehaviorEngine = 行为组织与计算
ActionEngine   = 动作计算
ExecutionEngine = 实际执行

这样,ICAI才能把:

“为什么做”
→ Goal

“能不能做”
→ Capability

“适不适合做”
→ Matching

“怎么做”
→ Method

“选择哪个”
→ Decision

“现在如何行动”
→ Behavior

“具体做什么”
→ Action

“实际上发生了什么”
→ Execution

完整连接起来。

第210章由此把第209章的认知计算结构正式连接到了ICAI的行为计算结构,使ICAI从“认识当前世界”进一步进入“依据当前认知形成可执行行为”的工程阶段。

Leave a Reply

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