adachsoft / ai-agent-stats
Library for calculating statistics from adachsoft/ai-agent conversation history.
v0.3.0
2026-11-13 22:33 UTC
Requires
- php: ^8.3
- adachsoft/ai-agent: ^0.13
Requires (Dev)
- adachsoft/php-code-style: ^0.7.2
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^13.0
- rector/rector: ^2.6
- symplify/phpstan-rules: ^14.9
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Library for calculating statistics from adachsoft/ai-agent conversation history.
Requirements
- PHP ^8.2
adachsoft/ai-agent^0.13
Conversation history uses the provider-neutral types from the shared conversation model, including ChatMessageDtoCollection, ChatMessageDto, ChatRoleEnum, ContentPartCollection, ToolCallDto, and ToolResultDto. Tool messages carry results as content parts and do not contain message content of their own.
Installation
composer require adachsoft/ai-agent-stats
Usage
The main entry point is AdachSoft\AiAgentStats\AgentStatsCalculator. It takes a ChatMessageDtoCollection from the shared conversation model and returns an AgentStatsDto with detailed metrics.
use AdachSoft\AiAgentStats\AgentStatsCalculator;
use AdachSoft\AiConversationModel\Message\Collection\ChatMessageDtoCollection;
// Assume $messages is a ChatMessageDtoCollection from the shared conversation model.
/** @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 in bytes (content plus tool result content)
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