Skip to main content
Tools (also known as function calling) allow your AI agents to interact with external systems and services, expanding their capabilities beyond text generation. When an LLM needs to perform an action, it calls a tool and uses the result to formulate its response.

What are Tools?

In LarAgent, a Tool is a function or class that an agent can invoke to perform actions or retrieve information. Tools bridge the gap between AI reasoning and real-world operations. Common use cases include:
  • Fetching data from APIs or databases
  • Sending emails or notifications
  • Performing calculations
  • Interacting with external services
When an agent determines it needs information or needs to take action, it calls the appropriate tool, receives the result, and uses it to continue the conversation.

Creating Tools

LarAgent offers three ways to define tools, each suited for different use cases:

Quick Examples

The simplest approach — add the #[Tool] attribute to any method in your agent class:
use LarAgent\Attributes\Tool;

#[Tool('Get the current weather for a location')]
public function getWeather(string $location, string $unit = 'celsius'): string
{
    return WeatherService::get($location, $unit);
}

Tool Execution Flow

When an agent uses tools:
1

LLM Decision

The LLM analyzes the conversation and determines a tool call is needed.
2

Tool Invocation

LarAgent automatically executes the requested tool with the provided arguments.
3

Result Processing

The tool’s return value is sent back to the LLM as context.
4

Response Generation

The LLM uses the tool result to formulate its final response.
LarAgent handles the entire tool execution loop automatically — you just define your tools and the agent does the rest.

Next Steps