> For the complete documentation index, see [llms.txt](https://tinyhumans.gitbook.io/openhuman/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/installation.md). Agents can also search and read this documentation through its [MCP server](https://tinyhumans.gitbook.io/openhuman/~gitbook/mcp).

# 安装

添加 Embed 依赖，选择编译期开关，并有意识地配置宿主的运行时和状态。

`openhuman-embed` 目前是一个未发布的工作区 crate。在此仓库中开发时使用本地路径依赖，或使用指向 `https://github.com/tinyhumansai/openhuman` 与 `package = "openhuman-embed"`。为已部署应用固定一个经过审查的 Git 修订版；嵌套的 vendored 库是该修订版构建输入的一部分。

从仓库根目录运行命令。使用以下命令构建门面层： `cargo check -p openhuman-embed`；使用以下命令验证一个精简依赖图： `cargo check -p openhuman-embed --no-default-features`。运行时权重预设和 Cargo 功能控制的是不同的内容。

## 编译时门控与运行时选择

| 选项                                  | 它控制的内容            |
| ----------------------------------- | ----------------- |
| Cargo 默认功能                          | 编译进制品的代码和依赖       |
| 例如名为 Embed 的功能，如 `mcp` 或 `skills`   | 公开门面项以及转发的核心门控    |
| `RuntimeBuilder::modules`, 域、服务和工具组 | 运行时暴露或启动哪些已编译的功能族 |
| 代理工具范围和访问权限                         | 单个代理可以使用的子集       |

Embed 默认设置会转发核心默认设置，并启用名为 Embed 的 `渠道` 功能。核心默认设置可包含 MCP 和技能，而无需启用 Embed 另外单独门控的 `McpServer`/agent MCP 设置器或技能设置器。添加 `--features mcp,skills` 在使用这些公开 API 时。运行时选择无法启用已在编译时排除的 Cargo 门控；请检查 [生成的编译矩阵](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/api-reference/capability-matrix.md) 以及 [源清单](https://github.com/tinyhumansai/openhuman/blob/main/crates/openhuman-embed/Cargo.toml).

`RuntimeBuilder::lean()` 会缩小运行时活动范围；但它本身不会减少依赖图。将其与以下选项配合使用： `--no-default-features` 以进行精简构建，并显式添加所需的门控。使用 `scripts/assert-shed.sh` 或仓库依赖模拟器，在声称依赖减少之前先验证。参见 [精简/无头指南](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/guides/lean-headless.md).

## 宿主运行时与凭据

使用以下配置构建一个 Tokio 多线程运行时： `enable_all`、较大的工作线程栈和有界的阻塞线程池。已验证的示例使用 [核心运行时常量](https://github.com/tinyhumansai/openhuman/blob/main/crates/openhuman-core/src/core/runtime/mod.rs) 通过其仓库支持模块：目前是 20 MiB 的工作线程栈和 64 个阻塞工作线程。Tokio 默认的 2 MiB 工作线程栈不足以应对嵌套的代理轮次。请遵循完整示例中的宿主设置，而不是添加一个未配置的 `#[tokio::main]` 到大型代理工作负载中。

通过以下方式初始化凭据主密钥： `openhuman_embed::process::init_master_key` 在持久化运行时 API 密钥之前。无头主机可以提供受保护的 64 位十六进制字符 `OPENHUMAN_KEYRING_MASTER_KEY` 或配置的密钥文件；请将此凭据排除在源代码和日志之外。离线示例创建的是一次性测试密钥，而非生产凭据。

## 状态、配置与检查

`Workspace::Ephemeral` 是库预设的默认值。 `Workspace::Dir` 会同时移动内部状态和凭据根目录； `workspace_dir` 仅覆盖内部状态，而将凭据根目录保留在解析后的配置路径。请将 action 目录放在内部工作区之外。Operator 宿主预设使用发现到的配置，而提供的 `Config` 是解析后的宿主配置。

[Runtime 默认值](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/concepts/runtime-defaults.md) 说明继承关系。生成的 [构建器设置器](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/api-reference/builder-setters.md) 是源代码派生的配置选项列表，而 `RuntimeBuilder::describe` 会在不启动服务的情况下报告构建前计划。

```rust
    let info = runtime.capabilities();
    assert_eq!(info.schema_version, 1);
    assert!(info.defaults.routed_provider);
    let serialized = serde_json::to_string(&info)?;
    assert!(!serialized.contains("sk-test"));
    assert!(!serialized.contains(&provider.uri()));
    assert!(!serialized.contains(&runtime.workspace_dir().display().to_string()));
    println!("{}", serde_json::to_string_pretty(&info)?);
```

[完整可运行示例](https://github.com/tinyhumansai/openhuman/blob/main/crates/openhuman-embed/examples/capability_report.rs)，包括运行时构造、导入和测试夹具设置。

该示例在启动后检查最终报告，并证明凭据、提供方 URL 和工作区路径都不存在。生成的矩阵使用固定的默认功能报告命令；它描述的是该构建，而不是宿主可能编译的每一种功能组合。
