> 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/quickstart.md). Agents can also search and read this documentation through its [MCP server](https://tinyhumans.gitbook.io/openhuman/~gitbook/mcp).

# 快速入门

让一个代理针对本地 fixture 运行，然后为宿主选择提供方和工作目录。

从仓库检出开始并运行 `cargo run -p openhuman-embed --example run_turn`。该示例启动一个短暂运行时，创建其自己的本地提供方/后端夹具，并打印 `来自存根的问候`。它不需要推理账户，也不会连接真实后端。

## 创建一个代理并发送一轮对话

完整示例会在此摘录之前构造运行时。 `AgentSpec` 为代理命名，并为其提供一个仅带有 `HostOnly` 工具的空白提示。由于没有附加主机工具，这就是一个仅文本代理：它无法继承操作员内置的工具目录。

```rust
    let agent = runtime.agent(
        AgentSpec::new("hello").definition(
            AgentDefinitionSpec::new()
                .bare_prompt("简短回复。")
                .tools(ToolScopeSpec::HostOnly),
        ),
    )?;
    let outcome = agent.run("Say hello").await?;
    assert!(!outcome.reply.is_empty());
    if support::offline() {
        assert_eq!(outcome.reply, "来自存根的问候");
    }
    println!("{}", outcome.reply);
```

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

`Agent::run` 返回一个 `TurnOutcome` ，其中包含回复和会话标识。使用 `Agent::turn(...).session(...)` 用于同一会话中的后续消息，或者在需要界面在增量到达时显示差异时使用 [流式传输进度](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/concepts/turns-sessions.md) 。

## 连接你自己的主机

将夹具提供方替换为一个明确的 OpenAI 兼容 `Provider` ，或者原生自定义模型。为工具提供明确的动作目录，决定是否启用自治强制，并将运行时状态与执行工具文件夹分离。按照 [安装](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/installation.md).

该示例的在线路径需要 `OPENHUMAN_EXAMPLE_LIVE=1` 以及 `OPENHUMAN_EXAMPLE_BASE_URL`, `OPENHUMAN_EXAMPLE_API_KEY` 和 `OPENHUMAN_EXAMPLE_MODEL`。选择在线路径是一个明确的决定；仅设置凭据并不会把默认示例变成真实调用。

对于托管的 TinyHumans 推理，请使用 [TinyHumans 主机集成](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/integrations/tinyhumans-managed.md)，它会安装后端传输层。仅仅嵌入本身不会安装它。

## 扩展示例

* 为分析员和撰稿人分别提供不同的工具和文件夹： [多个代理](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/guides/multi-agent.md).
* 通过你自己的 HTTP 传输层提供请求服务： [部署服务器](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/guides/deploy-server.md).
* 附加应用函数： [工具](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/concepts/tools.md).
* 隔离经过身份验证的客户： [SaaS 指南](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/guides/saas-multi-tenant.md).
* 保持设置离线且确定性： [模拟后端测试](https://tinyhumans.gitbook.io/openhuman/zh/kai-fa/embed/guides/mock-backend-testing.md).

在关闭运行时之前，移除监听器和代理句柄。若要提前移除，请等待 `remove_agent` ，这样保留的句柄就会停止接受轮次，而旧 ID 只会在清理完成后释放。
