第216章 Behavior Class|行为类
第215章完成了:
Method
↓
Evaluation
↓
Selection
↓
Selected Method
第216章不直接进入 Action,而是在 Method 与 Action 之间建立一个新的核心对象:
Method
↓
Behavior
↓
Action
这一层非常重要,因为 Method 是“如何处理”的结构,而 Behavior 是“系统将如何表现”的动态行为结构。
216.1 Behavior 的位置
ICAI 当前链路调整为:
Element
↓
Object
↓
Relation
↓
Scene
↓
State
↓
Cognition
↓
Dynamic Method
↓
Method Evaluation
↓
Method Selection
↓
Method
↓
Behavior
↓
Action
↓
Device
↓
Feedback
因此第216章首先建立一个明确边界:
Method ≠ Behavior
Behavior ≠ Action
216.2 Method 是方法,Behavior 是行为
可以简单理解:
Method
=
采用什么处理方式
Behavior
=
按照该 Method 当前表现出什么行为
Action
=
执行具体动作
例如:
Cognition:
需要寻找符合条件的供应商
Method:
MultiConditionSearch
Behavior:
持续搜索 → 筛选 → 比较 → 保留候选
Action:
Search
Filter
Compare
Store
因此:
Method
↓
Behavior
↓
Action
不是简单的:
Method
↓
Action
中间增加的 Behavior 层,使 ICAI 获得了行为连续性。
216.3 为什么需要 Behavior
如果没有 Behavior:
Method
↓
Action
系统容易变成:
选择一个方法
↓
执行一组动作
↓
结束
这种结构更接近:
Procedure Engine
而不是一个持续运行的智能系统。
加入 Behavior:
Method
↓
Behavior
↓
Action
↓
Feedback
↓
Behavior Update
就形成:
行为
→ 动作
→ 反馈
→ 行为变化
因此 Behavior 是 ICAI 从“方法执行”进入“持续行为”的关键层。
216.4 Behavior 的定义
可以定义:
Behavior
=
Method 在当前 State 下形成的动态行为状态及其行动倾向。
形式化:
B = F(M, S, G, R)
其中:
B = Behavior
M = Method
S = Current State
G = Goal
R = Feedback / Result
所以:
Method
提供行为的方法基础。
而:
State
决定当前 Behavior 的具体表现。
216.5 Behavior Object
建立第一版 Behavior:
<?php
class Behavior
{
protected string $behaviorId;
protected string $name;
protected ?Method $method = null;
protected array $state = [];
protected array $actions = [];
protected string $status = 'created';
protected array $feedback = [];
public function __construct(
string $behaviorId,
string $name
) {
$this->behaviorId = $behaviorId;
$this->name = $name;
}
public function setMethod(Method $method): void
{
$this->method = $method;
}
public function getMethod(): ?Method
{
return $this->method;
}
public function setState(array $state): void
{
$this->state = $state;
}
public function addAction(array $action): void
{
$this->actions[] = $action;
}
public function addFeedback(array $feedback): void
{
$this->feedback[] = $feedback;
}
public function setStatus(string $status): void
{
$this->status = $status;
}
public function getStatus(): string
{
return $this->status;
}
public function toArray(): array
{
return [
'behavior_id' => $this->behaviorId,
'name' => $this->name,
'method_id' => $this->method
? $this->method->getId()
: null,
'state' => $this->state,
'actions' => $this->actions,
'status' => $this->status,
'feedback' => $this->feedback
];
}
}
这一版只定义 Behavior 的对象边界。
216.6 Behavior 不是 Method 的别名
必须避免:
Method = Behavior
因为二者生命周期不同。
Method
可以长期存在:
SearchMethod
CompareMethod
RepairMethod
SelectionMethod
Behavior
是当前状态下产生的:
SearchBehavior
CompareBehavior
RepairBehavior
同一个 Method 在不同 State 下可以产生不同 Behavior:
Method M
│
├── State A → Behavior A
│
├── State B → Behavior B
│
└── State C → Behavior C
因此:
Method = reusable method structure
Behavior = state-dependent manifestation
这是第216章最核心的定义。
216.7 一个 Method 可以产生多个 Behavior
例如:
Method:
SearchMethod
当前状态:
没有候选对象
产生:
Behavior:
ExploratorySearch
状态变化:
已经有候选对象
同一个 Method 可能产生:
Behavior:
TargetedSearch
再变化:
搜索结果不足
可能产生:
Behavior:
ExtendedSearch
所以:
Method
│
┌────┼────┐
▼ ▼ ▼
B1 B2 B3
Method 是稳定的。
Behavior 是动态的。
216.8 Behavior 的状态
Behavior 本身需要生命周期。
基础状态:
created
↓
ready
↓
active
↓
acting
↓
waiting
↓
completed
异常:
acting
↓
blocked
↓
recovery
或者:
acting
↓
failed
然后:
failed
↓
rebuild
↓
new Behavior
所以 Behavior 不是一个简单数组,而是一个动态状态对象。
216.9 Behavior 与 Action
Behavior 到 Action:
Behavior
↓
Action
意味着 Behavior 不直接执行设备。
例如:
Behavior:
SupplierSearchBehavior
内部可能形成:
Action 1: Retrieve
Action 2: Filter
Action 3: Compare
Action 4: Store
所以:
Behavior
├── Action
├── Action
├── Action
└── Action
Behavior 决定:
动作序列
动作条件
动作持续状态
动作转换
而 Action 负责:
执行具体动作
216.10 Behavior 是动态 Action Structure
可以把 Behavior 看成:
Action
+
Order
+
Condition
+
State
+
Transition
形成:
Behavior
│
├── Action
├── Action
├── Condition
├── Transition
├── State
└── Feedback
因此 Behavior 不等于“动作列表”。
例如:
Action A
↓
Condition
├── true → Action B
└── false → Action C
这已经是行为结构。
216.11 Behavior Transition
行为必须能够变化。
定义:
Behavior A
↓
Condition
↓
Behavior B
例如:
Searching
↓
results >= required
↓
Comparing
如果:
results < required
则:
Searching
↓
ExtendSearching
所以:
Behavior Transition
成为后续 Behavior Engine 的基础。
216.12 Behavior Class 的第一版边界
第216章不要直接实现复杂行为引擎。
第一版只需要:
Behavior
├── Identity
├── Method
├── Current State
├── Actions
├── Status
└── Feedback
结构:
Method
│
▼
Behavior
│
├── State
├── Action Sequence
├── Status
└── Feedback
这样已经足够建立工程边界。
216.13 Method → Behavior 的转换
需要一个独立转换器:
Method
↓
Behavior Builder
↓
Behavior
例如:
class BehaviorBuilder
{
public function build(
Method $method,
State $state
): Behavior {
$behavior = new Behavior(
uniqid('behavior_'),
$method->getName() . ' Behavior'
);
$behavior->setMethod($method);
$behavior->setState(
$state->all()
);
return $behavior;
}
}
于是:
Selected Method
↓
BehaviorBuilder
↓
Behavior
而不是:
Selected Method
↓
直接 Action
216.14 Behavior 的核心计算
第216章可以进一步定义:
B = Behavior(M,S)
也就是:
Method
+
Current State
↓
Behavior
例如:
M = SearchMethod
S = NoCandidate
得到:
B = ExploratorySearchBehavior
而:
M = SearchMethod
S = CandidateExists
得到:
B = TargetedSearchBehavior
因此:
Same Method
+
Different State
=
Different Behavior
这正是 Dynamic Method 在行为层面的延伸。
216.15 Behavior 与 Feedback
行为真正具有动态性,是因为它可以接收反馈。
完整过程:
Method
↓
Behavior
↓
Action
↓
Result
↓
Feedback
↓
Behavior Update
例如:
Behavior:
Search
执行:
Action:
Retrieve
结果:
candidate_count = 0
Feedback:
NoResult
Behavior 发生变化:
Search
↓
ExtendedSearch
所以 Behavior 可以根据反馈改变。
216.16 Behavior 与 Method 的关系
最终可以明确为:
Method
│
│ defines
▼
Behavior
│
│ produces
▼
Action
更准确:
Method
=
方法结构
Behavior
=
方法在当前状态下形成的动态行为
Action
=
行为中的实际执行单元
可以表示为:
Current State
│
▼
Method
│
▼
Behavior Formation
│
▼
Behavior
│
┌──────┼──────┐
▼ ▼ ▼
Action Action Action
│ │ │
└──────┼──────┘
▼
Result
│
▼
Feedback
│
└────────► Behavior
216.17 Behavior 与 Decision 的边界
这里也要提前保持边界。
Decision
解决:
选择什么
而:
Method Selection
解决:
选择什么方法
Behavior 则解决:
选择的方法如何表现为连续行为
因此:
Decision
↓
Method Selection
↓
Method
↓
Behavior
↓
Action
当然,在当前 ICAI 架构中,具体的 Decision 层还需要后续正式定义,不能在 Behavior 中提前实现。
216.18 第216章核心结构
本章最终建立:
┌───────────────────┐
│ Method │
│ │
│ 方法结构 │
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ Behavior │
│ │
│ 当前动态行为 │
│ 当前状态 │
│ 行动序列 │
│ 状态转换 │
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ Action │
│ │
│ 具体执行 │
└───────────────────┘
核心关系正式确定为:
Method
↓
Behavior
↓
Action
而不是:
Method
↓
Action
216.19 本章最终定义
可以把 ICAI 的 Behavior 定义为:
Behavior 是 Method 在当前 State、Goal 和 Feedback 条件下形成的动态行为对象,它负责维持行为状态、组织 Action、处理行为转换,并将执行结果反馈到后续行为变化。
数学上:
Bₜ = F(Mₜ, Sₜ, Gₜ, Fₜ)
其中:
Bₜ = 当前 Behavior
Mₜ = 当前 Method
Sₜ = 当前 State
Gₜ = 当前 Goal
Fₜ = 当前 Feedback
于是 ICAI 的核心执行链进一步变成:
Cognition
↓
Dynamic Method
↓
Evaluation
↓
Selection
↓
Method
↓
Behavior
↓
Action
↓
Device
↓
Feedback
↓
State
↺
第216章真正完成的不是增加一个 Behavior.php,而是确立一个新的本体层:
Method = 方法
Behavior = 方法的动态行为表现
Action = 行为的具体执行
这样 ICAI 才开始具备从**“知道怎么做”到“持续表现出怎么做”**的中间层。