PHPackages                             aerobit/openai-agents - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aerobit/openai-agents

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aerobit/openai-agents
=====================

Laravel OpenAI Agents SDK

v0.1.3-beta(1y ago)04MITPHPPHP ^8.3CI passing

Since Jun 19Pushed 1y agoCompare

[ Source](https://github.com/EdEscudero/openai-agents)[ Packagist](https://packagist.org/packages/aerobit/openai-agents)[ RSS](/packages/aerobit-openai-agents/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

OpenAI Agents for Laravel
=========================

[](#openai-agents-for-laravel)

This package provides a lightweight integration of the [OpenAI PHP client](https://github.com/openai-php/client) with Laravel 12, inspired by the [OpenAI Agents Python SDK](https://github.com/openai/openai-agents-python).

Installation
------------

[](#installation)

```
composer require aerobit/openai-agents
```

Publish the configuration file:

```
php artisan vendor:publish --tag=config --provider="Aerobit\\OpenaiAgents\\AgentServiceProvider"
```

Set your `OPENAI_API_KEY` in the environment file or edit `config/agents.php`.

Usage
-----

[](#usage)

Send a message to the default agent:

```
php artisan agent:chat "Hello"
```

You can control the number of turns or provide a system prompt using options:

```
php artisan agent:chat "Hello" --system="You are helpful" --max-turns=3
```

You can also resolve the `AgentManager` service from the container to create agents programmatically.

```
use Aerobit\OpenaiAgents\AgentManager;

$manager = app(AgentManager::class);
$response = $manager->agent()->chat('Hello world');
```

The returned `Agent` instance retains the conversation history, allowing for multi-turn chats:

```
$agent = $manager->agent();

// First user message
$agent->chat('Hello');

// Follow-up message uses previous context
$reply = $agent->chat('What did I just say?');
```

The agent can also convert text responses to speech:

```
$audio = $agent->speak('Hello world');
file_put_contents('output.mp3', $audio);
```

You can optionally provide a system prompt when constructing the agent:

```
use Aerobit\OpenaiAgents\Agent;
use OpenAI\OpenAI;

$client = OpenAI::factory()->withApiKey(env('OPENAI_API_KEY'))->make();
$agent = new Agent($client, [], 'You are a helpful assistant.');
```

For more advanced scenarios you can use the `Runner` class which loops until the agent returns a final response or a turn limit is reached. Tools and basic handoffs can be registered on the runner:

```
use Aerobit\OpenaiAgents\Runner;

$runner = new Runner($agent, maxTurns: 3);
$runner->registerTool('echo', fn($text) => $text);
$helper = new Agent($client, [], 'Espanol agente');
$runner->registerAgent('spanish', $helper);
$reply = $runner->run('Start');
// inside the conversation use [[handoff:spanish]] to switch
```

The runner can request structured JSON output by providing an output schema:

```
$schema = ['required' => ['done']];
$runner = new Runner($agent, maxTurns: 3, tracer: null, outputType: $schema);
$result = $runner->run('Start'); // returns an associative array
```

Tools may also be defined with JSON schemas for OpenAI function calling:

```
$runner->registerFunctionTool('echo', fn(array $args) => $args['text'], [
    'type' => 'object',
    'properties' => ['text' => ['type' => 'string']],
    'required' => ['text'],
]);

// Or let the runner derive the schema automatically
$runner->registerAutoFunctionTool('echo_auto', function (string $text) {
    return $text;
});
```

If you need non-blocking execution you can run the runner inside a PHP `Fiber`:

```
$fiber = $runner->runAsync('Hello');
$fiber->start();
$result = $fiber->getReturn();
```

You can also stream results as they're generated:

```
foreach ($runner->runStreamed('Hello') as $chunk) {
    echo $chunk;
}
```

### Voice pipeline

[](#voice-pipeline)

Use the `VoicePipeline` class to handle audio transcription and text-to-speech in one step:

```
$pipeline = new VoicePipeline($client, $agent);
$audio = $pipeline->run('input.wav');
file_put_contents('reply.mp3', $audio);
```

### Tracing

[](#tracing)

The package includes a simple tracing system that lets you observe each turn of a `Runner` execution. Enable tracing in `config/agents.php` and register one or more processors to handle trace records:

```
return [
    // ...
    'tracing' => [
        'enabled' => true,
        'processors' => [
            fn(array $record) => logger()->info('agent trace', $record),
            new \Aerobit\OpenaiAgents\Tracing\HttpProcessor('https://example.com/trace'),
        ],
    ],
];
```

When enabled, each call to `Runner::run()` will emit start and end span events as well as per-turn events containing the input and output.

### Guardrails

[](#guardrails)

Guardrails let you validate input and output during a run. They can transform the content or throw an exception to stop execution.

```
use Aerobit\OpenaiAgents\Guardrails\InputGuardrail;
use Aerobit\OpenaiAgents\Guardrails\OutputGuardrail;
use Aerobit\OpenaiAgents\Guardrails\OutputGuardrailException;

$runner->addInputGuardrail(new class extends InputGuardrail {
    public function validate(string $content): string
    {
        return strtoupper($content);
    }
});

$runner->addOutputGuardrail(new class extends OutputGuardrail {
    public function validate(string $content): string
    {
        if (str_contains($content, 'bad')) {
            throw new OutputGuardrailException('Bad content');
        }
        return $content;
    }
});
```

Configuration
-------------

[](#configuration)

The `config/agents.php` file allows you to customize the default model and parameters used when interacting with OpenAI. It also contains options to enable tracing and provide custom processors for handling trace data.

License
-------

[](#license)

Released under the MIT license.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance49

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

374d ago

PHP version history (2 changes)v0.1.1-betaPHP ^8.4

v0.1.2-betaPHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/edda64060c604dadf6887b4d4d0ec6c8eba153a6a1952cd94490803838f065ab?d=identicon)[EdEscudero](/maintainers/EdEscudero)

---

Top Contributors

[![EdEscudero](https://avatars.githubusercontent.com/u/47765431?v=4)](https://github.com/EdEscudero "EdEscudero (46 commits)")

### Embed Badge

![Health badge](/badges/aerobit-openai-agents/health.svg)

```
[![Health](https://phpackages.com/badges/aerobit-openai-agents/health.svg)](https://phpackages.com/packages/aerobit-openai-agents)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.0k](/packages/craftcms-cms)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[sproutcms/cms

Enterprise content management and framework

242.5k4](/packages/sproutcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
