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 with deterministic output that reports whether a PHP runtime is available. The agent calls it when asked about the runtime. 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
  • Deterministic tool results keep multi-step HTTP recordings replayable

Example