Skip to main content
Glama

aggregate

Roll up row dicts by a group key to compute metrics such as counts, sessions, edits, and tokens for auditing AI coding agent history.

Instructions

Roll a list of row dicts up by group_by — the generic stats verb.

Reproduces session_stats (group_byagent/dir/date/ kind over a session inventory) and file_frequency (group_by="file" over a find_file_edits record stream) as a pure fold over already-materialized rows — no re-parsing. session_stats is now a thin preset over this verb (rank_by="stats" + kind_split).

Args: rows: The row dicts to fold (query output, find_file_edits records, or a session inventory). group_by: The bucket key — a row field name (agent / dir / date / kind / file / model — query rows carry the producing model where the format records one / …). Missing/empty values bucket under "(unknown)". metrics: Which numbers each bucket carries. One or more of count / sessions / edits / intents / agents / messages / files / tokens / component_tokens. Defaults to ["count"]. tokens (F3.3) folds per-row tokens blocks (the shape session_stats(with_tokens=True) rows carry, or a bare int total) into {input, output, reasoning, cache_read, cache_write, total, exact, estimated, unknown} — sums over rows that carry each field (null when none does) plus honest provenance counters (exact + estimated + unknown == len(rows)). component_tokens (F3.3) folds per-row component_tokens blocks (the shape :func:ai_r.tokens.component_tokens produces, as read_session(with_tokens=True) attaches) into summed event-taxonomy components (user_turn / assistant_turn / thinking / plan and a tool_call per-kind sub-dict) + total + provenance counters (estimated / unknown; never exact — always an estimate). A component/kind no row carried stays absent (never a fabricated 0). rank_by: Group ordering — "default" (edits→sessions→count→label, the file_frequency order) or "stats" (sessions→edits→label, the session_stats order). kind_split: When True, add the session_stats RISK-4 fields (kind_split_available + a degenerate-split note).

Returns: {"group_by", "groups": [...], "totals": {...}} (plus kind_split_available/note when kind_split) or the standard {"error": ..., "message": ...} dict on an unknown metric/rank_by.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rowsYes
metricsNo
rank_byNodefault
group_byYes
kind_splitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full responsibility. It is exceptionally transparent: it states it is a 'pure fold' with 'no re-parsing', details how missing/empty group_by values bucket under '(unknown)', explains the exact folding behavior for tokens and component_tokens including provenance counters and the rule that absent components stay absent (never fabricated 0). It also describes the error return format. This goes far beyond what annotations would typically provide.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Although lengthy, every sentence earns its place. The description is front-loaded with purpose, then uses a structured Args/Returns layout. The detailed explanations of metrics are necessary for correct usage and are not redundant. The structure is logical and the density is appropriate for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (5 parameters, two complex metric types, multiple ordering options) and the fact that an output schema exists, the description is remarkably complete. It covers return format, edge cases, parameter constraints, and error conditions. It even specifies the ordering of groups for each rank_by option. There are no gaps that would leave an agent guessing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must compensate, and it does thoroughly. It explains rows (what counts as valid input), group_by (valid values and unknown handling), metrics (allowed values, default, and detailed behavior for nested token/component_tokens structures), rank_by (both options and their ordering), and kind_split (what happens when True). This provides full semantic clarity for all 5 parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with 'Roll a list of row dicts up by group_by — the generic stats verb', which clearly states the action (rolling up rows) and resource (row dicts). It further distinguishes itself by noting it reproduces session_stats and file_frequency, making its purpose distinct from sibling tools. The purpose is specific and well-differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use the tool: it operates on already-materialized rows from query output, find_file_edits records, or a session inventory, and avoids re-parsing. It references session_stats as a thin preset, implying a relationship. However, it does not explicitly state when not to use this tool or name alternative tools outside of session_stats/file_frequency, so it lacks explicit exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pro-target/ai-r'

If you have feedback or need assistance with the MCP directory API, please join our Discord server