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

# Laravel AI SDK 集成

> 说明如何在 Laravel Copilot SDK 中启用实验性的 Laravel AI SDK 集成，并使用文本生成与流式输出。

## Laravel AI SDK 集成

* 实验性实现
* 仅支持文本生成。其他功能尚未支持。

这是仅在安装了 Laravel AI SDK 时才会启用的可选功能。

```shell theme={null}
composer require laravel/ai
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
```

在 `config/ai.php` 中添加配置。

```php theme={null}
// config/ai.php
    'default' => 'copilot',

    'providers' => [
        'copilot' => [
            'driver' => 'copilot',
            'key' => '',
        ],
    ],
```

使用 `agent()` 辅助函数的方式。

```php theme={null}
use function Laravel\Ai\agent;

$response = agent(
    instructions: 'You are an expert at software development.',
)->prompt('Tell me about Laravel');

echo $response->text;
```

也支持流式输出。除 `TextDelta` 之外都未实现。

```php theme={null}
use Laravel\Ai\Streaming\Events\TextDelta;

use function Laravel\Ai\agent;

$stream = agent(
    instructions: 'You are an expert at software development.',
)->stream('Tell me about Laravel');

foreach ($stream as $event) {
    if ($event instanceof TextDelta) {
        echo $event->delta;
    }
}
```

也可以像常规的 Laravel AI SDK 那样创建 Agent 类来使用，但只支持部分功能。

<Info>
  最新信息请参考 [GitHub 仓库](https://github.com/invokable/laravel-copilot-sdk)。
</Info>


## Related topics

- [Laravel AI SDK 集成 - VOICEVOX for Laravel](/zh/packages/laravel-voicevox/ai-sdk.md)
- [引擎 API 模式：Talk（文本语音合成） - VOICEVOX for Laravel](/zh/packages/laravel-voicevox/engine-talk.md)
- [VOICEVOX for Laravel](/zh/packages/laravel-voicevox/index.md)
- [2026 年 3 月 Laravel 更新](/zh/blog/changelog/202603.md)
- [Laravel 13 新功能汇总](/zh/blog/laravel-13-new-features.md)
