Skip to content

Comments

Add Laravel AI SDK tool format support#33

Open
pushpak1300 wants to merge 8 commits intoprism-php:mainfrom
pushpak1300:ai_sdk_compatible
Open

Add Laravel AI SDK tool format support#33
pushpak1300 wants to merge 8 commits intoprism-php:mainfrom
pushpak1300:ai_sdk_compatible

Conversation

@pushpak1300
Copy link
Collaborator

@pushpak1300 pushpak1300 commented Feb 21, 2026

Relay currently only returns Prism Tool objects, making it compatible with apps built on the Laravel AI SDK. This adds a ToolFormat::AI_SDK option so Relay::tools() can return Laravel\Ai\Contracts\Tool\ instances.

Usage

// Globally via config or env var (RELAY_TOOL_FORMAT=aisdk)
'tool_format' => ToolFormat::AI_SDK,

// Per-call override
$tools = Relay::make('puppeteer')->format(ToolFormat::AI_SDK)->tools();

Breaking Changes

PHP 8.4 and Laravel 12 are now required (previously PHP 8.2+ / Laravel 11+).

The laravel/ai package, a first-party Laravel package included in Laravel 12, requires PHP 8.4. This PR promotes laravel/ai as a hard dependency, providing the Tool contract and illuminate/json-schema types used in its type signatures. Therefore, Relay’s minimum requirements must align with it. Supporting Laravel 11 or PHP < 8.4 with a hard laravel/ai dependency is complex and not feasible.

@pushpak1300 pushpak1300 marked this pull request as draft February 21, 2026 15:07
pushpak1300 and others added 5 commits February 21, 2026 20:43
- Upgrade phpstan workflow to PHP 8.4 (required by laravel/ai) and
  install laravel/ai explicitly so PHPStan can resolve its types
- Conditionally install laravel/ai in the test matrix only for
  PHP 8.4 + Laravel 12 + prefer-stable (the only compatible combo)
- Skip AI SDK tests with a clear message when laravel/ai is not
  installed, preventing failures on incompatible matrix combinations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pushpak1300
Copy link
Collaborator Author

pushpak1300 commented Feb 21, 2026

Once you configure Relay to return aisdk format tools, you can pass them directly into any Laravel AI agent's tools() method.

1. Configure the tool format

Either globally via config/relay.php (or the RELAY_TOOL_FORMAT=aisdk env var):

'tool_format' => ToolFormat::AI_SDK,

Or per-call:

$tools = Relay::make('puppeteer')->format(ToolFormat::AI_SDK)->tools();

2. Use the tools in an agent

use Laravel\Ai\Agent;
use Laravel\Ai\Contracts\Tool;
use Prism\Relay\Facades\Relay;
use Prism\Relay\Enums\ToolFormat;

class BrowserAgent extends Agent
{
    /**
     * Get the tools available to the agent.
     *
     * @return Tool[]
     */
    public function tools(): iterable
    {
        return Relay::make('puppeteer')
            ->format(ToolFormat::AI_SDK)
            ->tools();
    }
}

This lets you expose any MCP server's tools to a Laravel AI agent without writing any Tool implementations by hand — Relay introspects the MCP server's schema and generates compliant Laravel\Ai\Contracts\Tool instances automatically.

Mixing Relay tools with hand-written tools

Since tools() returns an iterable, you can spread Relay tools alongside your own:

public function tools(): iterable
{
    return [
        new RandomNumberGenerator,
        ...Relay::make('puppeteer')->format(ToolFormat::AI_SDK)->tools(),
    ];
}

@pushpak1300 pushpak1300 marked this pull request as ready for review February 21, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant