PHP code example of jordanpartridge / laravel-ai-parallel-tools

1. Go to this page and download the library: Download jordanpartridge/laravel-ai-parallel-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jordanpartridge / laravel-ai-parallel-tools example snippets




namespace App\Ai\Tools;

use Illuminate\Contracts\JsonSchema\JsonSchema;
use JordanPartridge\ParallelTools\Attributes\Concurrent;
use Laravel\Ai\Contracts\Tool;
use Laravel\Ai\Tools\Request;
use Stringable;

#[Concurrent]
class WeatherLookup implements Tool
{
    /**
     * Get the description of the tool's purpose.
     */
    public function description(): Stringable|string
    {
        return 'Look up the current weather for a city.';
    }

    /**
     * Execute the tool.
     */
    public function handle(Request $request): Stringable|string
    {
        return '72F and clear in '.$request['city'];
    }

    /**
     * Get the tool's schema definition.
     */
    public function schema(JsonSchema $schema): array
    {
        return [
            'city' => $schema->string()->



namespace App\Ai\Agents;

use App\Ai\Tools\WeatherLookup;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasTools;
use Laravel\Ai\Promptable;

class TravelAgent implements Agent, HasTools
{
    use Promptable;

    public function instructions(): string
    {
        return 'You help travelers. Use your tools, then answer.';
    }

    public function tools(): iterable
    {
        return [
            new WeatherLookup,
        ];
    }
}

use App\Ai\Agents\TravelAgent;

$response = (new TravelAgent)->prompt('What is the weather in Paris and Oslo?');

return (string) $response;