Search by

adachsoft / ai-agent-stats

Arkadiusz Adach

Library for calculating statistics from adachsoft/ai-agent conversation history.

Package info

gitlab.com/a.adach/ai-agent-stats

Issues

pkg:composer/adachsoft/ai-agent-stats

Statistics

Installs: 26

Dependents: 0

Suggesters: 0

Stars: 0

v0.3.0 2026-11-13 22:33 UTC

This package is auto-updated.

Last update: 2026-11-13 21:37:57 UTC


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