Skip to Content
Module developmentIntegrations

AI tools of a module

How a module describes its actions for the AI assistant through CapabilityRegistry and ToolRegistry: permissions, argument schema, confirmation of risky calls, and what happens without the FluteAi module.

By the end, the assistant can read your module's data and change it on behalf of an administrator, with permission checks and confirmation of risky actions. The assistant itself is the FluteAi module, sold by subscription, but a module can register capabilities at any time: without FluteAi they stay available through the REST API.

Minimal example

The Example module shows player reports. The example capability returns open reports and closes one. The permissions are the ones from module permissions: admin.example.view to read, admin.example to write.

app/Modules/Example/Assistant/ExampleCapability.php
<?php

declare(strict_types = 1);

namespace Flute\Modules\Example\Assistant;

use Flute\Core\Ai\Capabilities\Attributes\Capability;
use Flute\Core\Ai\Capabilities\Attributes\Method;
use Flute\Core\Ai\Capabilities\Support\Act;
use Flute\Modules\Example\database\Entities\Report;
use Flute\Modules\Example\Exceptions\ReportRefused;
use Flute\Modules\Example\Services\Reports;

#[Capability(
    'example',
    summary: 'Player reports: list the open ones, close one with a reason',
    terms: 'complaint abuse ticket',
    guide: 'Call open() first and close only the report the owner named; repeat the reason back.',
)]
final class ExampleCapability
{
    #[Method(
        permission: 'admin.example.view',
        summary: 'open(limit = 20) — open reports: id, author, text, created (ISO, UTC)',
    )]
    public function open(int $limit = 20): array
    {
        return app(Reports::class)->open(max(1, min($limit, 50)));
    }

    #[Method(
        permission: 'admin.example',
        summary: 'close(id, reason) — close a report; its author gets the reason',
        writes: Report::class,
        approve: true,
    )]
    public function close(int $id, string $reason): array
    {
        $report = Act::run(
            static fn(): Report => app(Reports::class)->close(Act::by(), $id, $reason),
            [ReportRefused::class],
        );

        return ['closed' => $report->id, 'undo' => 'none'];
    }
}
app/Modules/Example/Providers/ExampleProvider.php
<?php

declare(strict_types = 1);

namespace Flute\Modules\Example\Providers;

use DI\Container;
use Flute\Core\Ai\Capabilities\CapabilityRegistry;
use Flute\Core\Support\ModuleServiceProvider;
use Flute\Modules\Example\Assistant\ExampleCapability;

final class ExampleProvider extends ModuleServiceProvider
{
    public function register(Container $container): void
    {
    }

    public function boot(Container $container): void
    {
        $this->bootstrapModule();

        $container->get(CapabilityRegistry::class)->register(ExampleCapability::class);
    }
}

The assistant gets two tools: example_open (a read) and example_close (a write that always asks for confirmation). The Wipes, GiveCore and BattlePass modules build their capabilities the same way.

How it works

Registration happens in boot(), by class name. The assistant also runs from the queue and cron, and a provider's boot() runs in every context. The object is created only on first use, so requests without the assistant pay nothing for the registration. The class is created with new and no arguments: take dependencies inside methods through app(), as the Wipes module does.

A capability is the set of public methods of the class marked with #[Method]. A method without the attribute and a static method are invisible to everyone. A method with writes: is a write, one without it is a read.

FluteAi names the tool <id>_<method in snake_case>, builds the argument schema from parameter types (int → integer, float → number, bool → boolean, array, anything else string), and treats parameters without a default that are not nullable as required. The model reads the summary as the description, so write the signature with defaults and the answer fields into it.

Every call checks the permission from permission:. A list means "any one of them", null lets in any admin user, and admin.boss always passes.

The method runs on behalf of the caller: Act::by() returns that user. The model reads an InvalidArgumentException as a refusal and can fix its arguments. Turn your own refusal exception into one with Act::run($work, [ReportRefused::class]).

FluteAi decides who confirms a write. Reads run at once. A write asks for confirmation in the mode with confirmations and runs by itself in the mode without them.

approve: true asks in every mode: put it on money, permissions, commands to a live server and deletions. Writes with delete, remove, ban, revoke or reset in the name, as well as publish and activate, always ask in FluteAi, even without approve.

Without FluteAi

Without FluteAi, capabilities stay registered and work through the REST API: POST /api/v1/actions/{capability}/{method} with the body {"args":{…}}. An API key gets the actions.example:read scope for methods without writes: and actions.example:write for the rest, and the call runs with the key's permissions. Through the API, a method with approve: true requires an Idempotency-Key header, and such calls go into the audit log. How to issue a key is described in REST API.

Tools from ToolRegistry::later() are never built without FluteAi: only the assistant reads the registry. So later() costs a site without a subscription nothing.

Reference

ParameterTypeDefaultMeaning
#[Capability] idstring—the capability name, global. One taken by the core or another module throws
summarystring''what the capability does, in English
termsstring''English synonyms for tool search; the model never sees them
guidestring''how to do the usual jobs: call order, what to ask first. The model gets it with the first tool
#[Method] permissionstring, list, nullnullthe permission for the call
summarystring''the method description for the model
writesstring, nullnullthe entity class the method changes, or Change::FILE, Change::BALANCE and others. null means a read
undoboolfalsethe change can be reverted from the journal; the method returns a Change
approveboolfalsea human confirms every call
toolbooltruefalse when your own tool already covers this method
costint1how many units of the write budget a call spends

CapabilityRegistry::register(object|string $capability): void takes a class name or a ready object. ToolRegistry::later(\Closure $contribute): void defers registering your own tools until the registry is first read.

Common mistakes

What you seeCause
InvalidArgumentException: …ExampleCapability is not marked with #[Capability].the class has no attribute, or the import is wrong
InvalidArgumentException: Capability 'example' is already registered.register() was called twice, or the id is taken
InvalidArgumentException: AI tool 'example_report' is already registered.the tool name clashes with another one, including a tool built from a capability method
Permission 'admin.example' is required for example.close().the user or the API key lacks the permission
example.close() writes data and this run is read-only.a write was called in read-only mode
Capability 'example' has no method 'list'; it has: open, close.the model or an API client called a method without #[Method]
the assistant does not see the capability from the queuethe registration sits in an admin package or in bootRequest() instead of boot()

See also

On this page