The simplest pattern is calling a single tool. This is useful for straightforward operations like getting weather data or sending an email.
Copy
$weatherTool = new WeatherTool();$response = Prism::text() ->using(config('toolbox.ai.provider')) ->withSystemPrompt("You can get weather data for any location. Provide a natural, conversational response including: - Temperature - Conditions - Humidity - Wind speed") ->withPrompt("What's the weather in London?") ->withTools([$weatherTool]) ->withMaxSteps(2) // One for tool call, one for summary ->generate();
For more complex operations, you can chain multiple tools together. This is useful for workflows like getting weather data and sending it via email.
Copy
$weatherTool = new WeatherTool();$emailTool = new EmailTool();$response = Prism::text() ->using(config('toolbox.ai.provider')) ->withSystemPrompt("You can get weather data and send it via email. For weather + email operations: 1. First use the weather tool to get the data 2. Then use the email tool to send that data 3. Format the weather data nicely in the email body When sending emails: - Use 'Weather Update' as subject if not specified - Format the weather data in a readable way") ->withPrompt("Send the current weather in London to user@example.com") ->withTools([$weatherTool, $emailTool]) ->withMaxSteps(5) // Important: More steps needed for multiple tools ->generate();
Here’s an example of chaining three tools to send both weather and crypto data via email:
Copy
$weatherTool = new WeatherTool();$cryptoTool = new CryptoTool();$emailTool = new EmailTool();$response = Prism::text() ->using(config('toolbox.ai.provider')) ->withSystemPrompt("You can get weather data, crypto prices, and send emails. For this combined operation: 1. Get the weather data for the specified location 2. Get the crypto price for the specified coin 3. Send an email containing both pieces of information Format the data nicely in the email, with sections for: - Current Weather Conditions - Cryptocurrency Prices") ->withPrompt("Send London's weather and Bitcoin's price to user@example.com") ->withTools([$weatherTool, $cryptoTool, $emailTool]) ->withMaxSteps(7) // (2 × number of tools) + 1 ->generate();
When one tool’s output is needed for the next tool’s input:
Copy
// Example: Get weather and email it$response = Prism::text() ->withSystemPrompt("First get the weather, then email it to the user") ->withPrompt("Send London's weather to user@example.com") ->withTools([$weatherTool, $emailTool]) ->withMaxSteps(5) // 2 for weather, 2 for email, 1 for final summary ->generate();
When the choice of second tool depends on the first tool’s result:
Copy
// Example: Check weather and either send warning email or update status$response = Prism::text() ->withSystemPrompt("Check the weather. If severe conditions, send warning email. Otherwise, just log the status.") ->withPrompt("Monitor weather conditions in Miami") ->withTools([$weatherTool, $emailTool, $statusTool]) ->withMaxSteps(5) // 2 for weather, 2 for chosen action, 1 for summary ->generate();
When you need to combine data from multiple tools:
Copy
// Example: Send both weather and crypto data in one email$response = Prism::text() ->withSystemPrompt("Get both weather and crypto data, then send combined report") ->withPrompt("Send London weather and Bitcoin price to user@example.com") ->withTools([$weatherTool, $cryptoTool, $emailTool]) ->withMaxSteps(7) // 2 for weather, 2 for crypto, 2 for email, 1 for summary ->generate();
When you need multiple interactions with the same tool:
Copy
// Example: Compare weather in multiple cities$response = Prism::text() ->withSystemPrompt("Get weather for multiple cities and compare them") ->withPrompt("Compare weather in London, Paris, and New York") ->withTools([$weatherTool]) ->withMaxSteps(7) // 2 steps per city (3 cities) + 1 for comparison ->generate();