Skip to content

librefang_tool_execution_seconds has no agent dimension — per-tool latency can't be attributed per-agent #6244

Description

@neo-wanderer

Summary

librefang_tool_execution_seconds (added in #6228 / #6233) is the per-tool latency histogram, but it carries only a tool label — no agent dimension:

// crates/librefang-runtime/src/agent_loop/tool_call.rs  (record_tool_call_metric)
if let Some(ms) = execution_ms {
    metrics::histogram!(
        "librefang_tool_execution_seconds",
        "tool" => tool,            // <-- only label
    )
    .record(ms as f64 / 1000.0);
}

The sibling counter emitted from the same function already carries agent:

metrics::counter!(
    "librefang_tool_call_total",
    "agent" => sanitize_tool_label(agent_id),
    "tool" => tool.clone(),
    ...
);

So you can attribute a tool failure to an agent (tool_call_total{agent,tool}, added in #6226), but you cannot attribute a tool latency to an agent. On a host running many agents that share tools, the per-tool p95 is an unweighted blend across every caller — a slow agent and a fast agent on the same tool are indistinguishable.

Proposal

Add the agent label to the histogram, sourced from the agent_id already in scope in record_tool_call_metric:

metrics::histogram!(
    "librefang_tool_execution_seconds",
    "agent" => sanitize_tool_label(agent_id),
    "tool" => tool,
)
.record(ms as f64 / 1000.0);

Cardinality stays bounded — same (agent × tool) product already accepted for librefang_tool_call_total, both labels sanitized/capped.

Secondary: agent label value is inconsistent across the agent-telemetry counters

While adding the label, please make it match the value scheme the other counters use, because right now the three agent-scoped counters disagree on what agent even means:

Metric agent value Site
agent_loop_exits_total manifest name agent_loop/mod.rs (record_agent_loop_exit, agent_label = manifest.name)
cron_fires_total agent UUID (AgentId) kernel/src/cron.rs (record_cron_fire_metric)
tool_call_total agent UUID (session.agent_id) agent_loop/tool_call.rs

Because agent_loop_exits_total keys on the human name while the other two key on the UUID, a dashboard cannot join loop-exit data to tool-call/cron data on agent, and a single agent can appear under two identities across panels.

Suggested fix: standardize agent to the UUID everywhere (stable; names can change or collide, and hands share names), so the new histogram should use the UUID too. Optionally add a separate low-cardinality agent_name label across all four metrics for human-readable grouping — the join key stays the UUID, the display label is the name.

Acceptance

  • librefang_tool_execution_seconds carries an agent label, enabling per-agent latency p50/p95/p99.
  • The agent label value scheme is consistent across tool_call_total, tool_execution_seconds, agent_loop_exits_total, and cron_fires_total (or an agent_name companion label is added so a stable join key exists).

Notes

Direct follow-up to #6226 (agent dimension on tool_call_total) and #6228 (the histogram). Same dispatch path; the fix is a one-line label add plus aligning record_agent_loop_exit's identifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-prA pull request has been linked to this issueneeds-triageAuto-applied when the issue title/body matched no area label — needs maintainer review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions