You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core-concepts/tools-function-calling.md
+69Lines changed: 69 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -388,6 +388,75 @@ use Prism\Prism\Facades\Tool;
388
388
$tool = Tool::make(CurrentWeatherTool::class);
389
389
```
390
390
391
+
## Client-Executed Tools
392
+
393
+
Sometimes you need tools that are executed by the client (e.g., frontend application) rather than on the server. Client-executed tools are defined without a handler function.
394
+
395
+
### Explicit Declaration (Recommended)
396
+
397
+
Use the `clientExecuted()` method to explicitly mark a tool as client-executed:
398
+
399
+
```php
400
+
use Prism\Prism\Facades\Tool;
401
+
402
+
$clientTool = Tool::as('browser_action')
403
+
->for('Perform an action in the user\'s browser')
404
+
->withStringParameter('action', 'The action to perform')
405
+
->clientExecuted();
406
+
```
407
+
408
+
This makes your intent clear and self-documenting.
409
+
410
+
### Implicit Declaration
411
+
412
+
You can also create a client-executed tool by simply omitting the `using()` call:
413
+
414
+
```php
415
+
use Prism\Prism\Facades\Tool;
416
+
417
+
$clientTool = Tool::as('browser_action')
418
+
->for('Perform an action in the user\'s browser')
419
+
->withStringParameter('action', 'The action to perform');
420
+
// No using() call - tool is implicitly client-executed
421
+
```
422
+
423
+
When the AI calls a client-executed tool, Prism will:
424
+
1. Stop execution and return control to your application
425
+
2. Set the response's `finishReason` to `FinishReason::ToolCalls`
426
+
3. Include the tool calls in the response for your client to execute
427
+
428
+
### Handling Client-Executed Tools
429
+
430
+
```php
431
+
use Prism\Prism\Facades\Prism;
432
+
use Prism\Prism\Enums\FinishReason;
433
+
434
+
$response = Prism::text()
435
+
->using('anthropic', 'claude-3-5-sonnet-latest')
436
+
->withTools([$clientTool])
437
+
->withMaxSteps(3)
438
+
->withPrompt('Click the submit button')
439
+
->asText();
440
+
441
+
```
442
+
443
+
### Streaming with Client-Executed Tools
444
+
445
+
When streaming, client-executed tools emit a `ToolCallEvent` but no `ToolResultEvent`:
446
+
447
+
```php
448
+
449
+
$response = Prism::text()
450
+
->using('anthropic', 'claude-3-5-sonnet-latest')
451
+
->withTools([$clientTool])
452
+
->withMaxSteps(3)
453
+
->withPrompt('Click the submit button')
454
+
->asStream();
455
+
```
456
+
457
+
> [!NOTE]
458
+
> Client-executed tools are useful for scenarios like browser automation, UI interactions, or any operation that must run on the user's device rather than the server.
459
+
391
460
## Tool Choice Options
392
461
393
462
You can control how the AI uses tools with the `withToolChoice` method:
0 commit comments