Skip to content

docs(nips): add NIP-AM draft for durable agent turn metrics#1441

Open
wpfleger96 wants to merge 2 commits into
mainfrom
paul/nip-am-agent-turn-metrics
Open

docs(nips): add NIP-AM draft for durable agent turn metrics#1441
wpfleger96 wants to merge 2 commits into
mainfrom
paul/nip-am-agent-turn-metrics

Conversation

@wpfleger96

Copy link
Copy Markdown
Collaborator

Adds docs/nips/NIP-AM.md — a draft NIP defining durable, encrypted per-turn agent token/usage metrics.

Summary

  • New regular stored kind 44200 ("Agent Turn Metric"): one immutable event per completed agent turn, published by the agent, NIP-44 v2 encrypted to the owner, #p-gated with the same p/agent tag layout as NIP-AO telemetry.
  • Payload carries harness, model, correlation ids (channelId/sessionId/turnId — encrypted, not tagged), per-turn usage (turn), session-cumulative usage (cumulative), a deltaReliable flag for restart-mid-session cases, estimated costUsd, and stopReason.
  • Relay obligations: ownership verification on publish, NIP-42 #p-gated reads, durable owner-scoped storage, exclusion from full-text search.

This is the design doc only — no code. Implementation (kind registry entry, P_GATED_KINDS + NULL search_tsv migration, goose + buzz-agent adapters, emit hook at TurnCompletedGuard) follows in separate PRs once the NIP clears review.

v1 scope covers goose and buzz-agent harnesses; codex/claude-code are deferred because they expose only context-window usage over ACP today, not per-turn tokens.

npub1fgdl5qqnh3k3f2xkqrvt7cujalhm623x4s7fdjdj5yrtp5fzjl9qrjpucw and others added 2 commits July 1, 2026 16:21
Defines kind:44200 — a regular stored event, one per completed agent turn,
NIP-44 encrypted agent-to-owner and #p-gated like NIP-AO telemetry, carrying
per-turn and cumulative token/cost usage so owners can account for agent
token consumption across harnesses without relaying transcript content.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Address design-review findings: forbid the id-lookup exemption from the
44200 owner gate (a non-owner learning an event id must not retrieve the
envelope), require sessionId + a monotonic turnSeq whenever cumulative
usage is present so consumers can deterministically recompute deltas
(created_at is seconds-precision and unordered within a second), define
counter-reset behavior as null-not-negative, and add normative numeric
validity and cache-token-folding rules.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
@wpfleger96 wpfleger96 marked this pull request as ready for review July 1, 2026 20:34
wpfleger96 added a commit that referenced this pull request Jul 1, 2026
reader_authorized_for_event in filter.rs now gates KIND_AGENT_TURN_METRIC
alongside KIND_DM_VISIBILITY — reader must match the #p tag (owner).
This single function closes all kindless-ids retrieval paths: WS
historical pull (req.rs:330, req.rs:652), HTTP bridge (bridge.rs:608,
bridge.rs:863), and live fan-out (event.rs).

Live fan-out extended likewise: owner_only_kind now covers both 44200
and 30622, so kindless-ids subscriptions cannot receive 44200 events
for non-owners.

Tests added: reader_authorized_for_event_gates_agent_turn_metric_by_p
(owner allow, non-owner deny, authoring-agent deny).

Case-2 rationale in the existing req.rs test updated: pass-through at
the filter-authorization gate is correct because the result-level gate
is now the enforcement point for this path.

NIP-AM ref: docs/nips/NIP-AM.md at 19889ba (PR #1441).
Resolves blocking gap from PR #1445 review.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant