第22章 InformationReceiver
本章大纲
- InformationReceiver 定义
- 信息接收
- 信息验证
- 信息分类
- 信息登记
- 信息分发
- 信息队列
- InformationReceiver 与 Central
- 完整接收流程
- 实际代码案例
22.1 InformationReceiver 定义
**InformationReceiver(信息接收器)**是 SAI Framework 中负责接收外部信息,并将其转换为统一 Information 对象的基础组件。
它解决的问题是:
外部信息如何进入 SAI Framework。
前一章已经定义了 InformationSource:
InformationSource
↓
信息从哪里产生
本章的 InformationReceiver 则负责:
InformationSource
↓
InformationReceiver
↓
Information
因此两者职责不同:
| 对象 | 主要职责 |
|---|---|
| InformationSource | 描述信息来源 |
| InformationReceiver | 接收进入系统的信息 |
| Information | 保存已经接收的信息 |
| InformationType | 描述信息属于什么类型 |
| Perception | 对信息进行感知和组织 |
| Central | 协调后续内部处理 |
可以表示为:
外部世界
│
▼
InformationSource
│
▼
InformationReceiver
│
├── 接收
├── 验证
├── 分类
├── 登记
└── 排队 / 分发
│
▼
Information
│
▼
Perception
InformationReceiver 不负责认知。
它不负责:
理解
推理
决策
学习
它的核心任务是把外部输入可靠地送入 SAI 信息处理链。
22.2 信息接收
SAI Framework 可以接收多种形式的信息。
例如:
Human
↓
文字
Sensor
↓
温度数据
Device
↓
设备状态
API
↓
JSON数据
Database
↓
数据记录
Environment
↓
场景信息
InformationReceiver 可以面对不同输入,但最终应该尽可能转换成统一结构。
例如:
人输入
“打开客厅风扇”
接收后:
type = language
source = human
content = 打开客厅风扇
温度传感器
32
接收后:
type = data
source = sensor-001
content = 32
设备状态
fan = ON
接收后:
type = state
source = fan-001
content = ON
因此:
不同外部输入
↓
InformationReceiver
↓
统一 Information
这一步对于 SAI 非常重要。
因为后面的:
Perception
Cognition
Memory
Reasoning
Decision
不应该分别处理几十种完全不同的入口格式。
22.3 信息验证
接收到信息之后,不能立即进入后续处理。
首先需要进行基本验证。
例如:
是否存在信息?
↓
来源是否存在?
↓
来源是否有效?
↓
内容是否有效?
↓
类型是否有效?
↓
时间是否有效?
基本验证可以包括:
1. Source 验证
source_id
必须能够识别来源。
例如:
sensor-001
human-001
api-001
device-001
2. Content 验证
信息不能是完全无效的数据。
例如:
NULL
空字符串
非法数据结构
需要根据具体信息类型判断。
3. Type 验证
例如:
text
language
instruction
data
event
state
device
scene
external
4. Time 验证
信息通常应该具有接收时间或者产生时间。
例如:
2026-09-12 14:20:00
5. Metadata 验证
必要情况下检查:
device_id
sensor_id
location
protocol
version
验证的意义
验证不是认知。
例如:
温度 = 32
验证:
32 是否为合法数字?
这是信息验证。
而:
32℃
意味着房间温度较高
属于后续认知/判断。
所以:
Validation ≠ Cognition
22.4 信息分类
验证通过之后,可以对信息进行分类。
InformationReceiver 可以根据:
Source
Content
Structure
Metadata
Context
确定信息类型。
例如:
“打开风扇”
可能得到:
source = human
type = instruction
温度数据:
source = sensor
type = data
设备状态:
source = device
type = state
外部 API:
source = api
type = external
因此:
接收
↓
验证
↓
分类
↓
Information
这里的分类只是信息类型识别,不是理解信息含义。
22.5 信息登记
接收到的信息需要登记。
所谓登记,就是给信息建立一个系统可以追踪的记录。
可以包括:
Information
├── id
├── source
├── type
├── content
├── time
├── state
├── context
└── metadata
例如:
Information ID: info-000001
Source: sensor-001
Type: data
Content: 32
Time: 2026-09-12 14:20:00
State: received
这样系统以后可以知道:
这条信息是什么?
从哪里来?
什么时候收到?
目前处于什么状态?
Information ID
信息最好具有唯一标识:
info-000001
info-000002
info-000003
例如:
sensor-001
↓
info-000021
这样可以建立:
Source
↓
Information
↓
Perception
↓
Memory
完整追踪关系。
22.6 信息分发
信息登记以后,需要进入对应的处理路径。
例如:
Information
↓
Information Type
│
├── language
│ ↓
│ Perception
│
├── instruction
│ ↓
│ Instruction Processing
│
├── data
│ ↓
│ Data Processing
│
├── state
│ ↓
│ State Processing
│
└── scene
↓
Scene Processing
InformationReceiver 可以负责分发入口。
但它不应该承担所有后续处理。
例如:
InformationReceiver
↓
Information
↓
Dispatcher
├── Perception
├── State
├── Event
└── Device
这样可以保持职责清晰。
22.7 信息队列
当信息持续进入 SAI 时,不一定能够立即全部处理。
例如传感器:
每秒产生 10 条信息
或者:
Camera
↓
Scene Information
↓
Scene Information
↓
Scene Information
↓
Scene Information
如果接收和处理速度不同,就需要队列。
基本结构:
InformationReceiver
↓
InformationQueue
↓
┌───────────────┐
│ info-001 │
│ info-002 │
│ info-003 │
│ info-004 │
└───────────────┘
↓
Processor
Queue 的基本操作
push()
加入信息。
pop()
取出最早的信息。
peek()
查看第一条信息但不删除。
count()
查看当前队列数量。
为什么需要 Queue?
例如:
Receiver
↓
100 条信息
↓
Queue
↓
逐条处理
这样可以把:
信息接收速度
与:
信息处理速度
分离。
这也是 SAI 面向真实设备、机器人、传感器时非常重要的基础结构。
22.8 InformationReceiver 与 Central
这是本章非常重要的一个区别。
InformationReceiver
负责:
信息进入系统
Central
负责:
协调 Individual 内部运行
因此:
External
│
▼
InformationReceiver
│
▼
Information
│
▼
Central
│
├── Perception
├── Cognition
├── Memory
├── Reasoning
├── Decision
└── Behavior
两者不是同一个组件。
为什么 Receiver 不能代替 Central?
假设收到:
房间温度 32℃
Receiver 的工作:
接收
↓
验证
↓
分类
↓
登记
↓
进入队列
然后交给 Central。
Central 才负责协调:
Information
↓
Perception
↓
Cognition
↓
Memory
↓
Reasoning
↓
Decision
↓
Behavior
所以:
InformationReceiver = 信息入口
Central = Individual 内部协调中心
22.9 完整接收流程
现在建立一个完整的信息接收流程。
假设:
TemperatureSensor
产生:
32℃
第一步:InformationSource
sensor-001
表示温度传感器。
InformationSource
│
└── sensor-001
第二步:InformationReceiver
接收:
32
第三步:验证
检查:
source = sensor-001
content = 32
验证通过。
第四步:分类
判断:
type = data
第五步:登记
生成:
info-000001
形成:
{
id: "info-000001",
source: "sensor-001",
type: "data",
content: 32
}
第六步:进入队列
InformationQueue
[
info-000001
]
第七步:Central 获取
InformationQueue
↓
Central
第八步:Perception
32
↓
Temperature Element
形成:
Element
name = temperature
value = 32
第九步:Object
Room
形成:
Room.temperature = 32
第十步:后续认知
然后才进入:
Cognition
↓
Memory
↓
Reasoning
↓
Decision
↓
Behavior
整个流程:
TemperatureSensor
↓
InformationSource
↓
InformationReceiver
↓
Validation
↓
Classification
↓
Registration
↓
InformationQueue
↓
Central
↓
Perception
↓
Element
↓
Object
↓
Cognition
↓
Reasoning
↓
Decision
↓
Behavior
22.10 实际代码案例
下面设计一个最基础的 InformationReceiver。
首先定义 Information:
<?php
namespace SAI\Information;
class Information
{
protected $id;
protected $source;
protected $type;
protected $content;
protected $time;
protected $state;
public function __construct(
$id,
$source,
$type,
$content
) {
$this->id = $id;
$this->source = $source;
$this->type = $type;
$this->content = $content;
$this->time = time();
$this->state = 'received';
}
public function getId()
{
return $this->id;
}
public function getSource()
{
return $this->source;
}
public function getType()
{
return $this->type;
}
public function getContent()
{
return $this->content;
}
public function getTime()
{
return $this->time;
}
public function getState()
{
return $this->state;
}
public function setState($state)
{
$this->state = $state;
}
}
InformationReceiver
<?php
namespace SAI\Information;
class InformationReceiver
{
protected $counter = 0;
public function receive($source, $type, $content)
{
if (!$this->validate($source, $type, $content)) {
return null;
}
$this->counter++;
$id = 'info-' . str_pad(
$this->counter,
6,
'0',
STR_PAD_LEFT
);
return new Information(
$id,
$source,
$type,
$content
);
}
protected function validate($source, $type, $content)
{
if (empty($source)) {
return false;
}
if (empty($type)) {
return false;
}
if ($content === null) {
return false;
}
return true;
}
}
这个 Receiver 当前完成:
接收
↓
验证
↓
创建 Information
22.11 增加信息队列
可以继续建立:
<?php
namespace SAI\Information;
class InformationQueue
{
protected $queue = array();
public function push(Information $information)
{
$this->queue[] = $information;
}
public function pop()
{
if (empty($this->queue)) {
return null;
}
return array_shift($this->queue);
}
public function peek()
{
if (empty($this->queue)) {
return null;
}
return $this->queue[0];
}
public function count()
{
return count($this->queue);
}
}
于是可以形成:
Receiver
↓
Information
↓
Queue
22.12 完整调用案例
<?php
use SAI\Information\InformationReceiver;
use SAI\Information\InformationQueue;
$receiver = new InformationReceiver();
$queue = new InformationQueue();
$information = $receiver->receive(
'sensor-001',
'data',
32
);
if ($information !== null) {
$queue->push($information);
}
echo $queue->count();
结果逻辑:
sensor-001
↓
receive()
↓
validate()
↓
Information
↓
push()
↓
Queue
然后 Central 可以从队列中取出:
$information = $queue->pop();
if ($information !== null) {
echo $information->getId();
echo $information->getSource();
echo $information->getType();
echo $information->getContent();
}
形成:
InformationQueue
↓
pop()
↓
Information
↓
Central
22.13 多种信息接收
同一个 Receiver 可以接收不同来源的信息。
人
$receiver->receive(
'human-001',
'instruction',
'打开客厅风扇'
);
温度传感器
$receiver->receive(
'sensor-001',
'data',
32
);
设备
$receiver->receive(
'fan-001',
'state',
'ON'
);
API
$receiver->receive(
'api-001',
'external',
array(
'temperature' => 32,
'humidity' => 65
)
);
最终都变成:
Information
├── source
├── type
├── content
├── time
└── state
这就是统一信息入口。
22.14 InformationReceiver 的职责边界
可以把本章内容进一步压缩成:
InformationReceiver
│
├── Receive
│
├── Validate
│
├── Classify
│
├── Register
│
├── Queue
│
└── Dispatch
而以下工作不属于 Receiver:
Cognition
Reasoning
Decision
Learning
Behavior
Memory Analysis
完整职责链:
InformationSource
↓
InformationReceiver
↓
Information
↓
InformationQueue
↓
Central
↓
Perception
↓
Cognition
↓
Memory
↓
Reasoning
↓
Decision
↓
Behavior
22.15 InformationSource、Receiver、Information 三者关系
这是前两章和本章连接起来后的核心结构。
InformationSource
│
│ 提供 / 产生
▼
InformationReceiver
│
│ 接收 / 验证 / 分类 / 登记
▼
Information
│
│ 进入 SAI
▼
Perception
可以用一个非常简单的例子理解:
温度传感器
是:
InformationSource
InformationReceiver
负责接收:
32℃
而:
32℃
经过结构化以后就是:
Information
所以:
Source 解决“信息从哪里来”,Receiver 解决“信息如何进入系统”,Information 解决“进入系统的信息是什么”。
本章完整架构
SAI Framework
│
▼
InformationReceiver
│
┌────────────────┼────────────────┐
▼ ▼ ▼
Receive Validate Classify
│ │ │
└────────────────┼────────────────┘
▼
Registration
│
▼
Information
│
▼
InformationQueue
│
▼
Dispatch
│
▼
Central
│
┌────────────┬───────┼────────┬────────────┐
▼ ▼ ▼ ▼ ▼
Perception Cognition Memory Reasoning Decision
│
▼
Behavior
本章小结
InformationReceiver 是 SAI Framework 的信息入口组件。
它主要负责:
信息接收
↓
信息验证
↓
信息分类
↓
信息登记
↓
信息排队
↓
信息分发
核心关系:
InformationSource
→ 信息从哪里来
InformationReceiver
→ 信息如何进入系统
Information
→ 进入系统的具体信息
Perception
→ 系统感知到了什么
Cognition
→ 系统理解了什么
因此 SAI 的信息入口可以正式形成:
世界 / 人 / 设备 / 传感器 / 系统
↓
InformationSource
↓
InformationReceiver
↓
Information
↓
InformationQueue
↓
Central
↓
Perception
↓
Cognition
以上 PHP 代码是本章的设计示例,用于说明 SAI Framework 的 OOP 结构,未作为实际项目代码执行验证。