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

第213章 Dynamic Method|动态方法

第213章 Dynamic Method|动态方法

第213章开始,Method静态方法对象进一步演化为 Dynamic Method

核心变化只有一个:

Method 不再因为“场景是什么”而固定,而是根据当前状态、目标、约束、历史反馈等变量重新计算当前最适合的方法。


213.1 Static Method 的局限

前面的 Method 可以表示:

Scene
  ↓
Method
  ↓
Action

例如:

Scene = Supplier Search
Method = SupplierSearchMethod

这种结构容易形成:

一个场景
    ↓
一个固定方法

但真实系统中,同一个场景的状态可能完全不同。

例如:

Scene:寻找供应商

State A:
没有任何候选对象

State B:
已经发现20个候选对象

State C:
已经筛选出3个候选对象

State D:
3个候选对象中有2个数据缺失

State E:
历史方法执行成功率下降

显然:

Scene 相同
State 不同

因此不能要求:

Scene → 固定 Method

而应该变成:

Current State
      ↓
Method Calculation
      ↓
Dynamic Method

213.2 Dynamic Method 定义

ICAI 中:

Dynamic Method
=
根据当前状态动态计算出来的 Method

可以形式化为:

M = F(S, G, C, H, R)

其中:

M = Method
S = Current State
G = Goal
C = Constraints
H = History
R = Available Resources

也就是说:

Method ≠ Stored Procedure

而是:

Method = Result of Calculation

213.3 从 Scene → Method 转变为 State → Method

旧结构:

Scene
 ↓
Method

新结构:

Scene
 ↓
Current State
 ↓
State Analysis
 ↓
Method Calculation
 ↓
Method

所以 Scene 的作用下降了一层。

Scene 负责提供:

上下文

而 State 决定:

当前应该如何处理

形成:

Scene
   │
   ▼
State
   │
   ├── Goal
   ├── Objects
   ├── Relations
   ├── Constraints
   ├── History
   └── Resources
          │
          ▼
    Method Calculation
          │
          ▼
       Method

213.4 Current State

Dynamic Method 首先需要一个当前状态对象。

例如:

class State
{
    protected array $data = [];

    public function set(string $key, $value): void
    {
        $this->data[$key] = $value;
    }

    public function get(string $key, $default = null)
    {
        return $this->data[$key] ?? $default;
    }

    public function all(): array
    {
        return $this->data;
    }
}

状态可以包含:

$state->set('goal', 'find_supplier');

$state->set('candidate_count', 20);

$state->set('valid_candidate_count', 3);

$state->set('missing_data_count', 2);

$state->set('resource_available', true);

于是 Method 不再直接读取:

Scene = Supplier Search

而是读取:

Current State

213.5 Method Calculation

建立:

class DynamicMethod
{
    public function calculate(
        State $state,
        array $availableMethods
    ): ?Method {

        $candidates = [];

        foreach ($availableMethods as $method) {

            if (!$this->isApplicable($method, $state)) {
                continue;
            }

            $score = $this->calculateScore(
                $method,
                $state
            );

            $candidates[] = [
                'method' => $method,
                'score'  => $score
            ];
        }

        if (empty($candidates)) {
            return null;
        }

        usort(
            $candidates,
            fn($a, $b) =>
                $b['score'] <=> $a['score']
        );

        return $candidates[0]['method'];
    }

    protected function isApplicable(
        Method $method,
        State $state
    ): bool {
        return true;
    }

    protected function calculateScore(
        Method $method,
        State $state
    ): float {
        return $method->getPriority();
    }
}

这里出现一个非常重要的概念:

Available Methods
        ↓
Current State
        ↓
Calculation
        ↓
Selected Method

因此 Dynamic Method 并不是“随机生成一个方法”。

它是:

从方法空间中,根据当前状态计算当前方法。


213.6 Method Space

如果方法数量增加,ICAI 可以形成:

Method Space

例如:

Method Space
│
├── Search
│   ├── BroadSearch
│   ├── ExactSearch
│   └── LocalSearch
│
├── Filter
│   ├── BasicFilter
│   ├── StrictFilter
│   └── MultiConditionFilter
│
├── Compare
│   ├── SimpleCompare
│   └── WeightedCompare
│
└── Recovery
    ├── Retry
    ├── AlternativeMethod
    └── Rebuild

Dynamic Method 不需要:

Scene → 固定 Method

而是在:

Method Space

中进行选择和组合。


213.7 Method Score

动态计算至少需要一个基础评分函数:

Score(Method, State)

可以定义:

Score =
Applicability
+
Priority
+
HistoricalPerformance
+
StateFit
-
Cost
-
Risk

例如:

$score =
    $applicability
    + $priority
    + $historicalPerformance
    + $stateFit
    - $cost
    - $risk;

注意:

这里不是让 LLM 判断哪个方法好。

这是 ICAI 自己的:

机器计算
+
数据结构
+
规则
+
历史数据

213.8 Dynamic Method 的真正变化

静态 Method:

Method A
    ↓
固定 Procedure

动态 Method:

State
 ↓
Calculation
 ↓
Method Structure
 ↓
Procedure

因此:

Method = State-dependent

也就是说:

M1 = F(S1)

M2 = F(S2)

即使:

Scene(S1) = Scene(S2)

也可能:

M1 ≠ M2

这就是 Dynamic Method 的核心。


213.9 方法可以动态组合

Dynamic Method 不一定只能选择一个已有 Method。

还可以:

Method A
+
Method B
+
Method C

形成新的:

Dynamic Method

例如当前状态:

candidate_count = 20
valid_count = 3
missing_data = 2

系统可能计算:

Search
  ↓
Filter
  ↓
Repair Data
  ↓
Compare

形成:

Dynamic Method
{
    step1: Search
    step2: Filter
    step3: Repair
    step4: Compare
}

因此 Method 开始从:

固定对象

向:

动态结构

演化。


213.10 Method Graph

进一步可以表示成:

             Method Space
                  │
       ┌──────────┼──────────┐
       ▼          ▼          ▼
    Search      Filter     Compare
       │          │          │
       └──────┬───┴──────────┘
              ▼
       Dynamic Composition
              │
              ▼
        Current Method

当前 Method 可能是:

Search
   ↓
Filter
   ↓
Compare

下一次状态变化以后:

Search
   ↓
Repair
   ↓
Filter
   ↓
Compare

Method 本身因此可以变化。


213.11 Dynamic Method 与 Feedback

Dynamic Method 最重要的后续能力是反馈:

State
 ↓
Method Calculation
 ↓
Method
 ↓
Action
 ↓
Result
 ↓
Feedback
 ↓
State Update
 ↓
Method Recalculation

形成真正的动态闭环:

       ┌────────────────────┐
       │                    │
       ▼                    │
Current State               │
       │                    │
       ▼                    │
Method Calculation          │
       │                    │
       ▼                    │
Dynamic Method              │
       │                    │
       ▼                    │
Action                      │
       │                    │
       ▼                    │
Result                      │
       │                    │
       ▼                    │
Feedback ───────────────────┘

因此下一轮方法并不一定与上一轮相同。


213.12 Method 不再绑定 Scene

这里需要正式建立一个 ICAI 工程原则:

Scene ≠ Method

更准确地说:

Scene provides context.
State provides current condition.
Cognition provides goal.
Dynamic Method calculates processing strategy.
Action executes the strategy.

即:

Scene
 ↓
Context

State
 ↓
Current Condition

Cognition
 ↓
Goal

Dynamic Method
 ↓
Processing Strategy

Action
 ↓
Execution

这比:

Scene → Method → Action

更加动态。


213.13 Dynamic Method Class

因此第213章可以建立第一版:

class DynamicMethod
{
    public function calculate(
        State $state,
        array $methods
    ): ?Method {

        $bestMethod = null;
        $bestScore = -INF;

        foreach ($methods as $method) {

            if (!$this->isApplicable(
                $method,
                $state
            )) {
                continue;
            }

            $score = $this->score(
                $method,
                $state
            );

            if ($score > $bestScore) {
                $bestScore = $score;
                $bestMethod = $method;
            }
        }

        return $bestMethod;
    }

    protected function isApplicable(
        Method $method,
        State $state
    ): bool {

        return true;
    }

    protected function score(
        Method $method,
        State $state
    ): float {

        return $method->getPriority();
    }
}

这里故意保持简单。

第213章不应该提前把:

Learning
Optimization
Prediction
Planning

全部塞进去。


213.14 当前 ICAI 结构

到第213章:

Element
   ↓
Object
   ↓
Relation
   ↓
Scene
   ↓
State
   ↓
Cognition
   ↓
Dynamic Method
   ↓
Action
   ↓
Device
   ↓
Feedback
   ↓
State Update
   ↺

这里产生一个非常关键的变化:

Feedback

不再只是记录结果。

它可以改变:

State

而 State 的变化又可以改变:

Method

因此:

Feedback
   ↓
State Change
   ↓
Method Recalculation

这才真正开始形成 ICAI 的连续动态行为结构


213.15 第213章核心定义

可以把本章最终压缩成一个公式:

DynamicMethod
=
F(
    CurrentState,
    Goal,
    Constraints,
    AvailableMethods,
    History
)

以及一个工程关系:

             Current State
                  │
                  ▼
          ┌───────────────┐
          │ Method Engine │
          └───────┬───────┘
                  │
                  ▼
          Dynamic Method
                  │
                  ▼
               Action
                  │
                  ▼
                Result
                  │
                  ▼
               Feedback
                  │
                  ▼
            State Update
                  │
                  └──────────► Method Engine

第213章的核心不是增加一个 DynamicMethod.php 文件,而是改变 Method 的本体定义:

过去:
Method = 固定方法

现在:
Method = 当前状态计算的结果

由此,ICAI 的 Method 开始从静态知识进入动态计算

Leave a Reply

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