Add Laravel AI SDK tool format support#33
Open
pushpak1300 wants to merge 8 commits intoprism-php:mainfrom
Open
Add Laravel AI SDK tool format support#33pushpak1300 wants to merge 8 commits intoprism-php:mainfrom
pushpak1300 wants to merge 8 commits intoprism-php:mainfrom
Conversation
- 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>
Collaborator
Author
|
Once you configure Relay to return 1. Configure the tool formatEither globally via 'tool_format' => ToolFormat::AI_SDK,Or per-call: $tools = Relay::make('puppeteer')->format(ToolFormat::AI_SDK)->tools();2. Use the tools in an agentuse 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 Mixing Relay tools with hand-written toolsSince public function tools(): iterable
{
return [
new RandomNumberGenerator,
...Relay::make('puppeteer')->format(ToolFormat::AI_SDK)->tools(),
];
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relay currently only returns Prism
Toolobjects, making it compatible with apps built on the Laravel AI SDK. This adds aToolFormat::AI_SDKoption soRelay::tools()can returnLaravel\Ai\Contracts\Tool\instances.Usage
Breaking Changes
PHP 8.4 and Laravel 12 are now required (previously PHP 8.2+ / Laravel 11+).
The
laravel/aipackage, a first-party Laravel package included in Laravel 12, requires PHP 8.4. This PR promoteslaravel/aias a hard dependency, providing theToolcontract andilluminate/json-schematypes used in its type signatures. Therefore, Relay’s minimum requirements must align with it. Supporting Laravel 11 or PHP < 8.4 with a hardlaravel/aidependency is complex and not feasible.