Add Laravel AI SDK tool format support#33
Add Laravel AI SDK tool format support#33pushpak1300 wants to merge 12 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 |
|
I'm trying to work out the best way to consume MCP servers with Laravel AI SDK. Is the intention for something like the PR to end up in Prism, or do we need to create our own wrappers? |
|
I'll be taking care of this in the laravel/mcp itself so it's easier to handle. Added to my list will be tackled in few weeks. |
|
@pushpak1300 brilliant, v happy to test for you, we have 3 clients actively using this with prism relay and the ai sdk right 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.