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

第16章 Identity

第16章 Identity

本章大纲

  1. Identity 定义
  2. Individual ID
  3. Name
  4. Type
  5. Version
  6. Identity Property
  7. Identity State
  8. 身份读取
  9. 身份修改
  10. Identity 实际案例

16.1 Identity 定义

在上一章中,我们定义了 Individual

一个 Individual 要能够作为一个独立的软件个体运行,首先必须能够回答一个基本问题:

“我是谁?”

这个问题就是 Identity 要解决的问题。

Identity 是 Individual 的身份描述结构,用于确定一个 Individual 的唯一标识、名称、类型、版本以及其他身份属性。

基本结构:

Individual
    │
    └── Identity
          ├── ID
          ├── Name
          ├── Type
          └── Version

因此可以定义:

Identity 是 SAI Individual 用于描述自身身份、识别自身以及区分其他 Individual 的身份信息结构。

Identity 本身不是 Cognition,也不是 Memory。

它主要负责:

身份定义
 ↓
身份识别
 ↓
身份读取
 ↓
身份管理

16.2 Individual ID

ID(Identity Identifier) 是 Individual 的核心标识。

例如:

SAI-001

系统中可以存在:

SAI-001
SAI-002
SAI-003

每个 Individual 都应该拥有能够区分自身的 ID。

例如:

Individual A
ID = SAI-001

Individual B
ID = SAI-002

ID 的主要作用:

Individual
 ↓
ID
 ↓
唯一识别

ID 可以被其他系统用于:

查找 Individual
绑定数据
绑定 Memory
绑定 Ability
记录 Experience
记录日志

例如:

$individual->getIdentity()->getId();

得到:

SAI-001

ID 与 Name 的区别

ID 和 Name 不能混为一谈。

ID
= 系统识别

Name
= 人或系统阅读

例如:

ID   = SAI-001
Name = Room Assistant

Name 可以改变,而 ID 通常应该保持稳定。


16.3 Name

Name 是 Individual 的名称。

例如:

ID:
SAI-001

Name:
Room Assistant

Name 主要用于:

显示
识别
管理
日志
调试

例如:

$identity->getName();

得到:

Room Assistant

一个 Individual 可以被重新命名:

Room Assistant
 ↓
Home Assistant

但:

ID
SAI-001

可以保持不变。

因此:

ID
→ 稳定身份标识

Name
→ 可读名称

16.4 Type

Type 用于描述 Individual 属于哪一种类型。

例如:

Type = general

或者:

Type = robot

也可以:

Type = vehicle

或者:

Type = industrial

因此:

Individual
├── ID = SAI-001
├── Name = Robot Assistant
├── Type = robot
└── Version = 1.0.0

Type 的作用不是决定 Individual 的全部能力。

例如:

Type = robot

并不意味着系统自动拥有机器人能力。

真正的能力由:

Ability

以及相应的 Engine、Adapter、Device 等提供。

因此:

Type ≠ Ability

Type 是身份分类。

Ability 是能力描述。


16.5 Version

Version 用于描述 Individual 当前使用的版本。

例如:

Version = 1.0.0

当 Individual 的软件能力发生变化,可以形成:

1.0.0
 ↓
1.1.0
 ↓
2.0.0

Version 可以帮助系统识别:

当前版本
能力版本
兼容关系
升级记录
运行环境

例如:

$identity->getVersion();

返回:

1.0.0

Version 与 State 也不同:

Version
→ 软件/Individual版本

State
→ 当前运行状态

例如:

Version = 1.0.0
State   = running

16.6 Identity Property

Identity 不一定只有:

ID
Name
Type
Version

还可以拥有其他身份属性。

例如:

Identity
├── ID
├── Name
├── Type
├── Version
├── CreatedAt
├── Description
└── Metadata

这些信息可以称为 Identity Property

例如:

$identity->setProperty(
    'description',
    'Room environment assistant'
);

形成:

description
=
Room environment assistant

Identity Property 可以用于描述 Individual 的基本身份信息,但不能无限扩张。

例如:

temperature
fan_state
energy
location

这些更适合属于:

State
Property

而不是 Identity。

因此需要保持边界:

Identity
 ↓
描述“我是谁”

State
 ↓
描述“我现在是什么状态”

Ability
 ↓
描述“我能够做什么”

16.7 Identity State

Identity 与 State 存在关系,但两者不是同一个概念。

Identity:

ID = SAI-001
Name = Room Assistant
Type = general
Version = 1.0.0

State:

status = running
location = room01
mode = normal

可以表示为:

Individual
│
├── Identity
│   ├── ID
│   ├── Name
│   ├── Type
│   └── Version
│
└── State
    ├── Status
    ├── Location
    └── Mode

Identity 通常具有较强稳定性。

State 则不断变化。

例如:

Identity
SAI-001

保持不变。

而 State:

ready
 ↓
running
 ↓
warning
 ↓
running

不断变化。

因此:

Identity 定义 Individual 的身份,State 描述 Individual 当前的运行状态。


16.8 身份读取

Identity 必须能够被 Individual 自身以及 Framework 其他组件读取。

例如:

$identity = $individual->getIdentity();

然后:

$id = $identity->getId();

$name = $identity->getName();

$type = $identity->getType();

$version = $identity->getVersion();

结果:

ID: SAI-001
Name: Room Assistant
Type: general
Version: 1.0.0

也可以直接读取:

$individual->getId();
$individual->getName();

这种方式适合 Framework 提供简洁接口。


16.9 身份修改

Identity 中不同属性的修改策略可以不同。

例如 Name:

$identity->setName(
    'Home Assistant'
);

可以变成:

Room Assistant
 ↓
Home Assistant

Version:

$identity->setVersion(
    '1.1.0'
);

但是 ID 通常不应该随意修改。

例如:

SAI-001

作为 Individual 的稳定标识,一旦已经产生关联数据:

SAI-001
 ↓
Memory
 ↓
Experience
 ↓
Ability
 ↓
Logs

如果直接修改:

SAI-001
 ↓
SAI-999

就可能破坏这些关联。

因此可以规定:

Individual ID 默认创建时确定,并作为稳定身份标识使用;Name、Type、Version 等身份属性可以根据 Framework 的生命周期规则进行修改。


16.10 Identity 实际案例

下面创建一个完整的 Identity。

说明:以下代码是本教程中的 PHP OOP 设计示例,用于说明 Identity 的结构和运行方式,并不代表已经实际创建或验证运行。

Identity 类

<?php

namespace SAI\Individual;

class Identity
{
    protected $id;
    protected $name;
    protected $type;
    protected $version;
    protected $properties = array();

    public function __construct(
        $id,
        $name,
        $type,
        $version
    ) {
        $this->id = $id;
        $this->name = $name;
        $this->type = $type;
        $this->version = $version;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getType()
    {
        return $this->type;
    }

    public function getVersion()
    {
        return $this->version;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function setType($type)
    {
        $this->type = $type;
    }

    public function setVersion($version)
    {
        $this->version = $version;
    }

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

    public function getProperty($name)
    {
        return isset($this->properties[$name])
            ? $this->properties[$name]
            : null;
    }
}

创建 Identity

$identity = new Identity(
    'SAI-001',
    'Room Assistant',
    'general',
    '1.0.0'
);

加入身份属性:

$identity->setProperty(
    'description',
    'Room environment assistant'
);

此时:

Identity
├── ID
│   └── SAI-001
│
├── Name
│   └── Room Assistant
│
├── Type
│   └── general
│
├── Version
│   └── 1.0.0
│
└── Property
    └── description
        └── Room environment assistant

读取:

echo $identity->getId();
echo $identity->getName();
echo $identity->getType();
echo $identity->getVersion();

得到的逻辑结果:

SAI-001
Room Assistant
general
1.0.0

修改名称:

$identity->setName(
    'Home Assistant'
);

修改版本:

$identity->setVersion(
    '1.1.0'
);

最终:

Identity
├── ID = SAI-001
├── Name = Home Assistant
├── Type = general
├── Version = 1.1.0
└── Description = Room environment assistant

Identity 与 Individual

Identity 不应该脱离 Individual 独立成为一个完整的人工个体。

正确关系是:

Individual
     │
     └── Identity

例如:

$individual = new Individual(
    $identity
);

最终:

Individual
│
├── Identity
│   ├── ID
│   ├── Name
│   ├── Type
│   └── Version
│
├── State
├── Ability
├── Memory
├── Cognition
├── Learning
└── Behavior

Identity 是 Individual 的身份基础。


Identity 在整个 SAI 中的位置

经过本章之后,可以把 Individual 的身份部分明确下来:

                    Individual
                         │
                     Identity
                         │
             ┌───────────┼───────────┐
             ↓           ↓           ↓
            ID          Name        Type
                         │
                      Version
                         │
                    Properties

而整个 Individual:

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

所以:

Identity
→ 我是谁

State
→ 我现在是什么状态

Ability
→ 我能做什么

Memory
→ 我记住了什么

Cognition
→ 我理解了什么

Learning
→ 我学到了什么

Behavior
→ 我做什么

本章小结

Identity 是 SAI Individual 的身份系统

它至少包括:

ID
Name
Type
Version

还可以扩展:

Identity Property
Metadata
Description
CreatedAt

最重要的区别是:

Identity
→ 定义“我是谁”

State
→ 定义“我现在怎么样”

Ability
→ 定义“我能够做什么”

因此,一个完整的 SAI Individual 可以从 Identity 开始:

Individual
 ↓
Identity
 ↓
State
 ↓
Ability
 ↓
Memory
 ↓
Cognition
 ↓
Learning
 ↓
Behavior

Identity 让 Individual 从一个普通的软件对象,开始具有明确、独立、可识别的“个体身份”。

Leave a Reply

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