Skip to content

Conversation

@vinitkadam03
Copy link
Contributor

Description

Summary

This PR introduces support for client-executed tools (also referred to as "deferred tools") - tools that are defined without a handler function and are intended to be executed by the client/caller rather than by Prism.

Motivation

Client-executed tools enable scenarios where tool execution must happen on the client side, such as:

  • UI interactions requiring client-side execution
  • Any tool where the server should not (or cannot) execute the logic

Changes

Core Implementation

src/Tool.php

  • Added isClientExecuted() method that returns true when no handler function is defined ($this->fn === null)
public function isClientExecuted(): bool
{
    return $this->fn === null;
}

src/Concerns/CallsTools.php

  • Modified callTools() to filter out client-executed tools from execution
  • Added hasDeferredTools() method to check if any tool calls are for client-executed tools

Behavior:

  • Client-executed tools are skipped during tool execution
  • Server-executed tools in the same request are still executed normally
  • When client-executed tools are detected, execution stops and control is returned to the caller
  • The LLM is not called for the next turn, allowing the client to execute the tool and continue the conversation
  • Response/stream ends with FinishReason::ToolCalls

Usage Example

use Prism\Prism\Facades\Prism;
use Prism\Prism\Facades\Tool;

// Define a client-executed tool (no `using()` call)
$clientTool = Tool::as('client_tool')
    ->for('A tool that executes on the client')
    ->withStringParameter('input', 'Input parameter');
    // Note: No ->using() call!

Breaking Changes

None. This is a backward-compatible addition. Existing tools with handlers continue to work exactly as before.

@vinitkadam03 vinitkadam03 marked this pull request as draft December 22, 2025 19:04
@vinitkadam03 vinitkadam03 marked this pull request as ready for review December 22, 2025 19:17
@vinitkadam03 vinitkadam03 changed the title Draft: Feat: Add support for client-executed tools Feat: Add support for client-executed tools Dec 22, 2025
@vinitkadam03 vinitkadam03 marked this pull request as draft December 22, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant