1. Go to this page and download the library: Download wcflabs/ai-ledger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
protected function gate(): void
{
Gate::define('viewAiLedger', function ($user) {
return in_array($user?->email, [
'[email protected]',
]);
});
}
use WCFLabs\AiLedger\Facades\AiLedger;
AiLedger::auth(function ($request) {
return $request->user()?->isAdmin();
});
use WCFLabs\AiLedger\Attributes\Tag;
use Laravel\Ai\Agent;
#[Tag('checkout', 'billing')]
class CheckoutAgent extends Agent
{
// ...
}
use WCFLabs\AiLedger\Facades\AiLedger;
AiLedger::tag('user:premium', 'feature:recommendations');
$result = $agent->handle($input);
use WCFLabs\AiLedger\Facades\AiLedger;
$result = AiLedger::withoutLogging(function () use ($agent, $input) {
return $agent->handle($input);
});
use WCFLabs\AiLedger\Mcp\LoggingMcpClientDecorator;
$client = new LoggingMcpClientDecorator($mcpClient);
$result = $client->callTool('search', ['query' => 'example']);
use WCFLabs\AiLedger\Events\FilteringInvocation;
use Illuminate\Support\Facades\Event;
Event::listen(FilteringInvocation::class, function (FilteringInvocation $event) {
// Skip invocations triggered by internal health-check agents
if (str_contains($event->data['agent_class'] ?? '', 'HealthCheck')) {
return false;
}
});
use WCFLabs\AiLedger\Events\FilteringToolCall;
use Illuminate\Support\Facades\Event;
Event::listen(FilteringToolCall::class, function (FilteringToolCall $event) {
if ($event->data['tool_name'] === 'internal_ping') {
return false;
}
});