A minimal reference toolkit for Coqui that demonstrates how to create custom toolkits. Use this as a starting point for building your own.
Requirements
- PHP 8.4+
- Coqui
Installation
Add the example as a path repository in your workspace composer.json, then require it:
composer require coquibot/hello-toolkitWhen installed alongside Coqui, the toolkit is auto-discovered via extra.php-agents.toolkits — no manual registration needed.
Tools Provided
hello_world
Returns a friendly greeting, optionally personalized with a name.
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | No | The name to greet (default: World) |
Example output: Hello, Alice! 👋
hello_time
Returns the current server date and time.
| Parameter | Type | Required | Description |
|---|---|---|---|
format | string | No | PHP date format string (default: ISO 8601) |
Example output: Current time: 2026-02-14T10:30:00-05:00
Project Structure
hello-toolkit/
├── composer.json # Package manifest with auto-discovery config
├── README.md # This file
└── src/
└── HelloToolkit.php # Main toolkit class implementing ToolkitInterfaceHow It Works
composer.jsondeclares the toolkit class inextra.php-agents.toolkits- Coqui’s
ToolkitDiscoveryreads this declaration at boot - The toolkit is instantiated and its tools are registered with the agent
- The LLM can now call
hello_worldandhello_timeas tool calls
Creating Your Own Toolkit
See the Toolkit Development Guide for a comprehensive walkthrough, or use this project as a template:
- Copy this directory
- Update
composer.jsonwith your package name, namespace, and dependencies - Rename and modify
src/HelloToolkit.phpto implement your tools - Install into Coqui with
composer require
License
MIT
Source Files
- examples/hello-toolkit/
- examples/hello-toolkit/src/
- examples/hello-toolkit/composer.json
- examples/hello-toolkit/README.md
- examples/hello-toolkit/src/HelloToolkit.php
composer.json
{
"name": "coquibot/hello-toolkit",
"description": "Hello World toolkit for Coqui — demonstrates how to create custom toolkits",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Carmelo Santana"
}
],
"autoload": {
"psr-4": {
"CoquiBot\\HelloToolkit\\": "src/"
}
},
"require": {
"php": "^8.4",
"carmelosantana/php-agents": "^0.2 || @dev"
},
"extra": {
"php-agents": {
"toolkits": [
"CoquiBot\\HelloToolkit\\HelloToolkit"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}HelloToolkit.php
<?php
declare(strict_types=1);
namespace CoquiBot\HelloToolkit;
use CarmeloSantana\PHPAgents\Contract\ToolInterface;
use CarmeloSantana\PHPAgents\Contract\ToolkitInterface;
use CarmeloSantana\PHPAgents\Tool\Tool;
use CarmeloSantana\PHPAgents\Tool\ToolResult;
use CarmeloSantana\PHPAgents\Tool\Parameter\StringParameter;
/**
* A minimal reference toolkit demonstrating how to create Coqui toolkits.
*
* This toolkit provides two simple tools:
* - hello_world: Returns a personalized greeting
* - hello_time: Returns the current server time
*
* Use this as a template when building your own toolkits. Key patterns:
* - Implement ToolkitInterface with tools() and guidelines()
* - Each tool is built via a private method returning a Tool instance
* - Parameters use typed parameter classes (StringParameter, NumberParameter, etc.)
* - Callbacks return ToolResult::success() or ToolResult::error()
* - Declare the toolkit in composer.json extra.php-agents.toolkits for auto-discovery
*/
final class HelloToolkit implements ToolkitInterface
{
/**
* @return ToolInterface[]
*/
public function tools(): array
{
return [
$this->helloWorldTool(),
$this->helloTimeTool(),
];
}
/**
* Usage guidelines injected into the LLM's system prompt.
*
* Wrap guidelines in XML-style tags for clear boundaries.
* Keep them concise — every token counts against the context window.
*/
public function guidelines(): string
{
return <<<'GUIDELINES'
<HELLO-TOOLKIT-GUIDELINES>
- Use hello_world to greet the user. Optional parameter: name.
- Use hello_time to report the current server time in any format.
</HELLO-TOOLKIT-GUIDELINES>
GUIDELINES;
}
/**
* Build the hello_world tool.
*
* Each tool should be constructed in its own private method for readability.
* The Tool class takes: name, description, parameters array, and a callback.
*/
private function helloWorldTool(): ToolInterface
{
return new Tool(
name: 'hello_world',
description: 'Return a friendly greeting. Optionally personalize it with a name.',
parameters: [
new StringParameter(
'name',
'The name to greet (default: "World")',
required: false,
),
],
callback: function (array $input): ToolResult {
$name = trim((string) ($input['name'] ?? 'World'));
if ($name === '') {
$name = 'World';
}
return ToolResult::success("Hello, {$name}! 👋");
},
);
}
/**
* Build the hello_time tool.
*
* Demonstrates using a parameter with a default value and
* returning dynamic data (current time).
*/
private function helloTimeTool(): ToolInterface
{
return new Tool(
name: 'hello_time',
description: 'Return the current server date and time.',
parameters: [
new StringParameter(
'format',
'PHP date format string (default: "c" for ISO 8601). Examples: "Y-m-d", "H:i:s", "l, F j, Y"',
required: false,
),
],
callback: function (array $input): ToolResult {
$format = trim((string) ($input['format'] ?? 'c'));
if ($format === '') {
$format = 'c';
}
$time = date($format);
return ToolResult::success("Current time: {$time}");
},
);
}
}Last updated