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

第15章 Individual

第15章 Individual

本章大纲

  1. Individual 定义
  2. 模拟人工个体
  3. Individual 身份
  4. Individual 状态
  5. Individual 能力
  6. Individual 记忆
  7. Individual 认知
  8. Individual 行为
  9. Individual 学习
  10. Individual 生命周期
  11. Individual 类设计
  12. 创建第一个 Individual

15.1 Individual 定义

在 SAI Framework 中,Individual 是整个框架最终要构建和运行的核心主体

前面的章节分别介绍了:

Application
Bootstrap
Container
Request
Response
Controller
Model
Engine

这些都是构建 Individual 所需要的工程基础。

Individual 则把这些能力组织起来,形成一个具有自身身份、状态、能力、记忆、认知、行为和学习机制的模拟人工个体

可以定义为:

Individual 是 SAI Framework 中对一个具有独立身份、内部状态、能力、记忆、认知、学习和行为能力的模拟人工个体的软件表示。

最基本结构:

Individual
│
├── Identity
├── State
├── Ability
├── Memory
├── Cognition
├── Learning
└── Behavior

Individual 不是一个普通的 PHP 对象名称,而是 SAI Framework 最核心的概念之一。


15.2 模拟人工个体

传统程序通常是:

Input
 ↓
Logic
 ↓
Output

Individual 的运行过程更加完整:

外部世界
 ↓
Information
 ↓
Perception
 ↓
Cognition
 ↓
Memory
 ↓
Reasoning
 ↓
Decision
 ↓
Behavior
 ↓
Action
 ↓
外部世界
 ↓
Feedback
 ↓
Experience
 ↓
Learning
 ↓
Update

这意味着 Individual 不是简单的:

Input → Output

而是:

感知世界
 ↓
理解世界
 ↓
结合记忆
 ↓
进行推理
 ↓
形成决策
 ↓
产生行为
 ↓
作用于世界
 ↓
获得反馈
 ↓
形成经验
 ↓
学习和更新

这里的“人工”是指由软件构造出来的人工个体结构

这里的“模拟”则表示:

Individual 通过软件机制模拟部分人工个体所具有的信息处理、认知、决策、行为和学习过程。

它并不意味着必须复制真实人的全部生理和心理机制。


15.3 Individual 身份

一个 Individual 首先需要拥有自己的身份。

例如:

Individual
ID: SAI-001
Name: Assistant-01
Type: general

Identity 可以包含:

ID
Name
Type
Version
Created Time
Owner
Status

例如:

$identity = array(
    'id' => 'SAI-001',
    'name' => 'Assistant-01',
    'type' => 'general',
    'version' => '1.0.0'
);

Identity 的作用是回答:

“我是谁?”

例如系统中同时存在:

SAI-001
SAI-002
SAI-003

三个 Individual 可以拥有完全独立的:

Memory
State
Ability
Experience

因此 Individual 必须具有明确的身份边界。


15.4 Individual 状态

State 表示 Individual 当前所处的状态。

例如:

Individual State
├── status = running
├── energy = 80
├── location = room01
├── task = cooling
└── mode = normal

状态具有动态性。

例如:

idle
 ↓
working
 ↓
completed
 ↓
idle

或者:

normal
 ↓
warning
 ↓
error
 ↓
repairing
 ↓
normal

State 会影响认知、推理和决策。

例如:

IF
energy < 20

THEN
reduce_nonessential_actions

所以:

State
 ↓
Cognition / Reasoning
 ↓
Decision

Individual 的状态不是静态属性,而是整个运行过程中的动态信息。


15.5 Individual 能力

Ability 表示 Individual 当前能够执行什么任务。

例如:

Ability
├── perceive
├── reason
├── decide
├── communicate
├── control_device
└── learn

不同 Individual 可以拥有不同能力。

例如:

Individual A
├── perception
├── reasoning
└── communication

而:

Individual B
├── perception
├── reasoning
├── navigation
├── device_control
└── learning

因此:

Ability 决定 Individual 能够应用哪些能力资源。

能力并不等于 Engine。

例如:

Reasoning Ability

可以由:

ReasoningEngine

提供处理机制。

关系可以表示为:

Individual
   ↓
Ability
   ↓
Engine
   ↓
Processing

15.6 Individual 记忆

Individual 需要保存过去获得的信息、事实、状态和经验。

因此:

Individual
   ↓
Memory

Memory 可以进一步分为:

Memory
├── ShortMemory
├── LongMemory
├── FactMemory
├── StateMemory
└── ExperienceMemory

例如 Individual 当前记住:

Room01 temperature = 32
Fan01 state = OFF

过去的经验:

temperature > 30
 ↓
fan.turnOn()
 ↓
temperature decreased

记忆使 Individual 不只是处理“当前信息”,还能够使用过去的信息。

基本关系:

Current Information
        +
Memory
        ↓
Cognition
        ↓
Reasoning

15.7 Individual 认知

Cognition 是 Individual 对信息进行理解、组织和匹配的能力。

可以表示:

Information
 ↓
Perception
 ↓
Element
 ↓
Object
 ↓
Relation
 ↓
Cognition

例如:

temperature = 32

通过对象和关系组织:

Room01
temperature = 32

再结合当前状态:

Room01
temperature = 32
Fan01 = OFF
Person = PRESENT

Individual 可以形成当前场景的认知结构。

需要明确:

Cognition 不是简单的数据读取,也不是最终决策。

它处于:

Perception
 ↓
Cognition
 ↓
Reasoning

之间。


15.8 Individual 行为

Behavior 是 Individual 对决策结果进行外部表现或执行的机制。

基本过程:

Decision
 ↓
Behavior
 ↓
Action
 ↓
External World

例如:

Decision:
Turn on fan

形成:

Behavior:
TurnOnFan

然后:

Action:
fan01.turnOn()

行为可以表现为不同形式:

Web Output
API Output
Device Control
Robot Movement
Machine Command
Communication

因此 Behavior 不只是“说话”。

它可以是 Individual 对外部世界产生的任何有组织行为。


15.9 Individual 学习

Individual 的学习来自自身运行过程中的反馈和经验。

基本过程:

Information
 ↓
Cognition
 ↓
Decision
 ↓
Behavior
 ↓
Action
 ↓
Feedback
 ↓
Experience
 ↓
Learning
 ↓
Update

例如:

条件:
temperature > 30

行为:
fan.turnOn()

结果:
temperature decreased

形成经验:

Experience
{
    condition: temperature > 30,
    action: fan.turnOn,
    result: success
}

LearningEngine 可以处理这条经验:

Experience
 ↓
LearningEngine
 ↓
Knowledge / Pattern
 ↓
Ability Update
 ↓
Memory Update

因此 Individual 的学习不是简单地“增加数据”,而是通过:

行为
→ 结果
→ 反馈
→ 经验
→ 学习
→ 更新

不断改变自身可使用的资源和经验结构。


15.10 Individual 生命周期

Individual 也具有生命周期。

可以定义为:

Created
 ↓
Initialized
 ↓
Ready
 ↓
Running
 ↓
Learning
 ↓
Updating
 ↓
Running
 ↓
Stopping
 ↓
Stopped

其中最重要的是:

Running

运行阶段可以不断重复:

Information
 ↓
Perception
 ↓
Cognition
 ↓
Memory
 ↓
Reasoning
 ↓
Decision
 ↓
Behavior
 ↓
Feedback
 ↓
Experience
 ↓
Learning
 ↓
Update
 ↓
Information

因此 Individual 并不是执行一次任务之后就结束。

它可以持续运行:

Cycle 1
 ↓
Cycle 2
 ↓
Cycle 3
 ↓
Cycle 4
 ↓
...

这也是 Individual 与普通一次性程序的重要区别之一。


15.11 Individual 类设计

在 PHP OOP 中,可以使用一个 Individual 类表示模拟人工个体。

以下代码为教程设计示例,不代表已经实际验证运行。

<?php

namespace SAI\Individual;

class Individual
{
    protected $identity;
    protected $state;
    protected $ability;
    protected $memory;
    protected $cognition;
    protected $learning;
    protected $behavior;

    public function __construct(
        $identity,
        $state = array(),
        $ability = array()
    ) {
        $this->identity = $identity;
        $this->state = $state;
        $this->ability = $ability;
        $this->memory = array();
        $this->cognition = null;
        $this->learning = null;
        $this->behavior = null;
    }

    public function getIdentity()
    {
        return $this->identity;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setState($name, $value)
    {
        $this->state[$name] = $value;
    }

    public function getAbility()
    {
        return $this->ability;
    }

    public function remember($data)
    {
        $this->memory[] = $data;
    }

    public function getMemory()
    {
        return $this->memory;
    }
}

创建 Individual:

$individual = new Individual(
    'SAI-001',
    array(
        'status' => 'ready'
    ),
    array(
        'perception',
        'reasoning',
        'decision',
        'behavior',
        'learning'
    )
);

此时可以得到:

Individual
│
├── ID
│   └── SAI-001
│
├── State
│   └── ready
│
├── Ability
│   ├── perception
│   ├── reasoning
│   ├── decision
│   ├── behavior
│   └── learning
│
└── Memory
    └── empty

15.12 创建第一个 Individual

现在创建一个最简单的 SAI Individual。

定义:

ID:
SAI-001

Name:
Room Assistant

State:
ready

Ability:
perception
reasoning
decision
behavior
learning

PHP:

<?php

require_once __DIR__ . '/bootstrap.php';

use SAI\Individual\Individual;

$individual = new Individual(
    array(
        'id' => 'SAI-001',
        'name' => 'Room Assistant'
    ),
    array(
        'status' => 'ready',
        'location' => 'room01'
    ),
    array(
        'perception',
        'reasoning',
        'decision',
        'behavior',
        'learning'
    )
);

$individual->remember(array(
    'type' => 'fact',
    'room' => 'room01',
    'temperature' => 32
));

print_r($individual);

逻辑结果可以理解为:

SAI-001
│
├── Identity
│   ├── id = SAI-001
│   └── name = Room Assistant
│
├── State
│   ├── status = ready
│   └── location = room01
│
├── Ability
│   ├── perception
│   ├── reasoning
│   ├── decision
│   ├── behavior
│   └── learning
│
└── Memory
    └── temperature = 32

接下来给它输入一个场景:

Room01
temperature = 32
Fan01
state = OFF
Person
state = PRESENT

Individual 的运行过程:

Information
 ↓
PerceptionEngine
 ↓
CognitionEngine
 ↓
MemoryEngine
 ↓
ReasoningEngine
 ↓
DecisionEngine
 ↓
BehaviorEngine
 ↓
Action

规则:

IF
Room01.temperature > 30
AND
Fan01.state = OFF
AND
Person.state = PRESENT

THEN
Fan01.turnOn()

行为执行:

Fan01
OFF
 ↓
turnOn()
 ↓
ON

随后获得反馈:

temperature
32℃
 ↓
29℃

形成经验:

temperature > 30
+
fan OFF
+
person PRESENT
 ↓
fan ON
 ↓
temperature decreased

再进入:

LearningEngine
 ↓
Experience
 ↓
Memory Update

这样,一个最简单的 Individual 就形成了一个完整的运行闭环。


Individual 完整结构

经过前面章节的学习,可以把 SAI Framework 的 Individual 进一步表示为:

                         Individual
                              │
             ┌────────────────┼────────────────┐
             │                │                │
          Identity          State           Ability
             │                │                │
             └────────────────┼────────────────┘
                              │
                           Central
                              │
        ┌─────────────┬───────┼───────┬─────────────┐
        │             │       │       │             │
   Perception     Cognition Memory Reasoning     Decision
        │             │       │       │             │
        └─────────────┴───────┼───────┴─────────────┘
                              │
                           Behavior
                              │
                            Action
                              │
                       External World
                              │
                           Feedback
                              │
                         Experience
                              │
                          Learning
                              │
                            Update
                              │
                         Individual

这时可以看到,前面介绍的:

Application
Bootstrap
Container
Request
Response
Controller
Model
Engine

最终都开始围绕 Individual 进行组织。


本章小结

Individual 是 SAI Framework 的最终运行主体

它不是:

普通 PHP Class
Web Controller
Model
Engine
Chatbot
Rule Engine

而是由多个内部能力共同组成的模拟人工个体:

Individual
├── Identity
├── State
├── Ability
├── Memory
├── Cognition
├── Learning
└── Behavior

Individual 的完整运行过程:

外部世界
 ↓
Information
 ↓
Perception
 ↓
Cognition
 ↓
Memory
 ↓
Reasoning
 ↓
Decision
 ↓
Behavior
 ↓
Action
 ↓
外部世界
 ↓
Feedback
 ↓
Experience
 ↓
Learning
 ↓
Update
 ↓
Individual

因此,本章可以得到一个非常重要的结论:

SAI Framework 的目标不是单独开发一个 PerceptionEngine、ReasoningEngine 或 LearningEngine,而是通过这些基础组件最终构建一个能够持续感知、认知、记忆、推理、决策、行为、反馈和学习的 Individual。

从下一阶段开始,Framework 的各个核心模块就可以围绕这个 Individual 逐步展开。

Leave a Reply

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