> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用指南

> 使用 PHP Agent SDK 运行工具循环、人工审核、重试和可恢复的 Agent。

## 准备运行时

Agent SDK 包尚未发布到 Packagist。请按照[从源码安装的说明](./agent-sdk-installation.mdx)操作。

## 快速入门

```php theme={null}
<?php
require "vendor/autoload.php";

use Phaseo\AgentSdk\AgentDefinition;
use Phaseo\AgentSdk\AgentSdk;

$agent = AgentSdk::createAgent(new AgentDefinition(
    id: "quickstart-agent",
    model: "openai/gpt-5.4-nano",
    instructions: "Answer concisely and helpfully."
));

$result = $agent->run(
    input: "Give me one fun fact about cURL.",
    client: AgentSdk::createGatewayAgentClient()
);

echo $result->output . PHP_EOL;
```

## 功能概览

* `AgentSdk::createAgent(...)`
* `AgentSdk::defineTool(...)`
* `AgentSdk::createGatewayAgentClient(...)`
* 通过 Phaseo `responses` API 实现的有界工具循环

## 高级运行时

PHP 支持验证和审批回调、HITL 与手动工具、进度、可恢复错误、可重放迭代器、停止辅助方法、动态轮次、持久化的下一轮参数、规范化用量/成本以及 `StateAccessor`。

## 流式传输与取消

`Agent::stream(...)` 和 `Agent::continueStream(...)` 会在消费返回的迭代器时，通过 Fiber 驱动网关的 Responses SSE 流。使用 `textStream()`、`reasoningStream()`、`itemStream()` 或 `fullStream()`；调用 `cancel()` 可停止 Fiber 并关闭生成器。已完成步骤会保留请求 ID、提供方元数据、结束原因、警告、用量和成本。

## 相关内容

* [Agent SDK 概览](../agent-sdk/overview.mdx)
* [TypeScript Agent SDK](../typescript/agent-sdk.mdx)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.