adachsoft / ai-agent-stats
Library for calculating statistics from adachsoft/ai-agent conversation history.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/adachsoft/ai-agent-stats
Requires
- php: ^8.2
- adachsoft/ai-agent: v0.8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
- rector/rector: ^2.3
This package is not auto-updated.
Last update: 2026-02-03 05:21:03 UTC
README
Library for calculating statistics from adachsoft/ai-agent conversation history.
Requirements
- PHP ^8.2
- adachsoft/ai-agent
Installation
composer require adachsoft/ai-agent-stats
Usage
The main entry point is AdachSoft\AiAgentStats\AgentStatsCalculator. It takes a ChatMessageDtoCollection (from adachsoft/ai-agent) and returns an AgentStatsDto with detailed metrics.
use AdachSoft\AiAgentStats\AgentStatsCalculator;
use AdachSoft\AiAgent\PublicApi\Dto\Collection\ChatMessageDtoCollection;
// Assume $messages is your ChatMessageDtoCollection from the agent
/** @var ChatMessageDtoCollection $messages */
$calculator = new AgentStatsCalculator();
$stats = $calculator->calculate($messages);
// Accessing statistics:
// 1. Message counts per role
echo "User messages: " . $stats->messageCountByRole['user'] . PHP_EOL;
echo "Assistant messages: " . $stats->messageCountByRole['assistant'] . PHP_EOL;
// 2. Total size of all messages (content length)
echo "Total size: " . $stats->totalMessagesSize . " bytes" . PHP_EOL;
// 3. Tool usage statistics
foreach ($stats->toolStats as $toolName => $toolStat) {
echo "Tool: $toolName" . PHP_EOL;
echo " - Usage count: " . $toolStat->usageCount . PHP_EOL;
echo " - Input size: " . $toolStat->inputSize . " bytes" . PHP_EOL;
echo " - Output size: " . $toolStat->outputSize . " bytes" . PHP_EOL;
}
// 4. Advanced metrics
echo "Size of messages with tool calls: " . $stats->messagesWithToolCallsSize . PHP_EOL;
echo "Size of tool output messages: " . $stats->toolRoleMessagesSize . PHP_EOL;
License
MIT