Skip to main content
Phantom Tools follow the same interface as regular tools but instead of automatic execution, they return the tool call details to your application — giving you full control over when and how the tool is executed.

What are Phantom Tools?

When the LLM calls a regular tool, LarAgent automatically executes it and feeds the result back to the LLM. Phantom Tools break this cycle — they return the tool call details to your application, allowing you to:
  • Handle execution externally (different service, API, etc.)
  • Request user confirmation before proceeding
  • Expose tool calls through your own API
  • Queue execution for background processing

Creating Phantom Tools

At Runtime

In Agent Class

Define phantom tools in the registerTools() method:

Handling Phantom Tool Calls

When the LLM decides to call a phantom tool, the agent returns an array with tool_calls instead of a text response (or ToolCallMessage when using ->returnMessage()):
Use ->returnMessage() before respond() to get a ToolCallMessage instance instead of an array, giving you access to the getToolCalls() method with ToolCall objects.

Multiple Phantom Tool Calls

When parallel tool calls are enabled, the LLM may request multiple phantom tools at once:

Use Cases

Phantom Tools where created to support user provided external tools while exposing Agents via API, but they can be useful in many scenarios

External Services

Hand off execution to external APIs or microservices that require special authentication or handling.

User Confirmation

Pause for user approval before executing sensitive or irreversible actions.

API Exposure

Make tool calls available through your API for frontend or mobile app handling.

Async Processing

Queue tool execution for background processing with job queues.

User Confirmation Example

Background Processing Example

The job handler would then:

Mixing Regular and Phantom Tools

You can use both regular and phantom tools in the same agent:
When mixing regular and phantom tools: if the LLM calls both types in parallel, regular tools execute first, then the phantom tool call is returned. The conversation only returns to you when all regular tool executions are complete and at least one phantom tool was called.
Use regular tools for safe, read-only operations and phantom tools for actions that modify state, cost money, or require confirmation.

Using returnMessage() for Type-Safe Access

For more control, use returnMessage() to get a ToolCallMessage instance instead of an array:

Phantom Tool Properties

Phantom tools support the same property definitions as regular tools:

With Enum Constraints

Next Steps

Tool Configuration

Configure tool choice, parallel execution, and runtime management.

Attribute Tools

Create tools using the #[Tool] attribute.

Tool Classes & Inline

Build reusable tool classes or create tools dynamically.

Responses

Learn about handling agent responses.