Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:42 evey Hermes plugins telemetry tracking

From Leeroopedia
Knowledge Sources
Domains Observability, Telemetry, Event_Logging
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for structured JSON event logging and session metrics tracking, providing observability for agent delegations, tool calls, and errors.

Description

The evey-telemetry plugin provides module-level functions for emitting structured events to a rotating JSONL log file, plus a telemetry_query tool for the agent to inspect its own performance.

Key functions:

  • emit_event(event_type, data) — writes a JSON event with timestamp and session ID to ~/.hermes/telemetry/events.jsonl; rotates at 10MB (keeps last 5 rotated files).
  • track_delegation(model, task_type, duration_ms, success, tokens, error) — increments session delegation counter and emits a "delegation" event.
  • track_error(source, error_msg, severity) — increments error counter and emits an "error" event.
  • track_tool_call(tool_name, duration_ms, success, tokens, error) — increments tool call counter and emits a "tool_call" event.
  • track_cron(job_name, status, duration_ms, output_preview) — emits a "cron" event.
  • query_handler(args) — the registered telemetry_query tool supporting 5 query types: session_metrics, recent_errors, recent_events, delegation_stats, tool_stats.

SESSION_METRICS is a module-level dict tracking the current session's tool_calls, delegations, errors, total_tokens, and events_emitted. This module is uniquely imported by evey-delegate-model (the only sibling import in the repo).

Usage

Import this module when you need to emit structured telemetry events from a plugin. The agent calls telemetry_query to inspect its own performance. Registered as telemetry_query on the evey_telemetry toolset.

Code Reference

Source Location

  • Repository: hermes-plugins
  • File: evey-telemetry/__init__.py
  • Lines: L51-241 (emit_event L51-66, track_* L69-119, query_handler L171-229, schema L124-146)

Signature

def emit_event(event_type: str, data: dict = None) -> None:
    """Write a structured event to the telemetry log."""

def track_delegation(model: str, task_type: str, duration_ms: int = 0,
                     success: bool = True, tokens: int = 0, error: str = None) -> None:
    """Track a delegation event."""

def track_error(source: str, error_msg: str, severity: str = "error") -> None:
    """Track an error event."""

def track_tool_call(tool_name: str, duration_ms: int = 0,
                    success: bool = True, tokens: int = 0, error: str = None) -> None:
    """Track a tool call event."""

def track_cron(job_name: str, status: str, duration_ms: int = 0,
               output_preview: str = None) -> None:
    """Track a cron job execution."""

def query_handler(args: dict, **kwargs) -> str:
    """
    Query telemetry data.
    Args: {query_type: str (required), limit: number}
    query_type: session_metrics | recent_errors | recent_events | delegation_stats | tool_stats
    """

Import

# As a module (used by evey-delegate-model):
from importlib import import_module
_telemetry = import_module("evey-telemetry")
_telemetry.track_delegation(model="...", task_type="...", success=True, tokens=100)

# As a Hermes tool:
tool_call("telemetry_query", {"query_type": "delegation_stats"})

I/O Contract

Inputs (track_delegation)

Name Type Required Description
model str Yes Model used for the delegation
task_type str Yes Task category (code, research, etc.)
duration_ms int No Call duration in milliseconds (default 0)
success bool No Whether the delegation succeeded (default True)
tokens int No Tokens consumed
error str No Error message if failed

Outputs (emit_event)

Name Type Description
events.jsonl file JSON event appended to ~/.hermes/telemetry/events.jsonl
SESSION_METRICS dict In-memory counters updated (delegations, errors, tokens)

Outputs (query_handler: delegation_stats)

Name Type Description
models dict Per-model: calls, successes, total_tokens, avg_ms, success_rate
total_delegations int Total delegation events read

Usage Examples

Emitting a Delegation Event

from importlib import import_module
_telemetry = import_module("evey-telemetry")

_telemetry.track_delegation(
    model="claude-sonnet-4-20250514",
    task_type="code",
    duration_ms=3200,
    success=True,
    tokens=850,
)
# Appends to events.jsonl:
# {"ts":"2026-10-29T...","sid":"a1b2c3","type":"delegation",
#  "model":"claude-sonnet-4-20250514","task_type":"code","duration_ms":3200,
#  "success":true,"tokens":850,"error":null}

Querying Delegation Stats

result = tool_call("telemetry_query", {
    "query_type": "delegation_stats"
})
# {"status":"ok","models":{
#   "claude-sonnet-4-20250514":{"calls":12,"successes":11,"success_rate":"92%",
#     "total_tokens":5400,"avg_ms":2100}},
#   "total_delegations":12}

Querying Recent Errors

result = tool_call("telemetry_query", {
    "query_type": "recent_errors",
    "limit": 5
})
# {"status":"ok","count":2,"errors":[{ts, type, source, message, severity}, ...]}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment