Skip to main content

Overview

Build a custom tool by extending BaseTool. Override __invoke(mixed ...$args) to implement the tool logic, use $this->arg() to extract named parameters, and override toToolSchema() to define the parameter schema for the LLM. This example creates a SystemInfoTool that reports memory usage, PHP version, and other runtime information. The agent calls it when asked about the system. Key concepts:
  • BaseTool: Abstract base class for custom tools
  • __invoke(mixed ...$args): The method the agent calls
  • $this->arg(): Extract named or positional parameters from args
  • toToolSchema(): Define the JSON Schema the LLM sees for this tool
  • $this->agentState: Access current agent state from within a tool

Example