Add Laravel AI SDK tool format support#33
Add Laravel AI SDK tool format support#33pushpak1300 wants to merge 11 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>
|
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 looks amazing, thank you! |
|
Looking forward to this. This will be epic! |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
this is exactly what i've been waiting for ... TY! |
|
@sixlive please could you get this merged 🙏 I just had a to create an adapter as a workaround for now |
Relay currently only returns Prism
Toolobjects, making it incompatible 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.