Skip to content

Add Agentmetry package with OCSF mapping - #211

Merged
mavam merged 2 commits into
tenzir:mainfrom
blitzcrieg1:agentmetry-package
Nov 3, 2026
Merged

mavam merged 2 commits into
tenzir:mainfrom
blitzcrieg1:agentmetry-package

Conversation

@blitzcrieg1

@blitzcrieg1 blitzcrieg1 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Problem

Agentmetry is an open-source recorder for AI coding agents. It records each tool call from the agents' own hooks (Claude Code, Cursor, Codex, GitHub Copilot, Qwen, Kimi and a few more), writes them to a hash-chained JSONL trail, and correlates the calls of a session into detections. The library has no mapping for its events, so agent activity from Cursor, Copilot and the other hook-only agents cannot join the OCSF pipelines next to the anthropic and openai packages.

As discussed with @mavam on Discord.

🛠️ Solution

A new agentmetry package with two operators, laid out like kunai. Tenzir reads Agentmetry's JSON natively, so the package starts at the mapper.

  • agentmetry::ocsf::normalize normalizes a stream of Agentmetry events.
  • agentmetry::ocsf::map agentmetry, ocsf maps a structured event and consumes it. Whatever has no OCSF attribute stays under unmapped.
  • It reads both forms the recorder emits: the canonical event that its webhook sink posts, and a trail line, which wraps the same event with its hash-chain position. The position becomes metadata.sequence.
  • Classes, following the choices in the anthropic package and the agent-to-OCSF blog post:
    • Shell tool calls are Process Activity Launch, with the command as process.cmd_line.
    • File tool calls are File System Activity when the event names the file.
    • MCP tools and every other tool are API Activity Invoke, with the tool as api.operation and the MCP server as api.service.
    • detection events and a changed MCP tools/list fingerprint are Detection Findings.
    • Session boundaries and anything unknown are Base Events.
  • Tool calls get the AI Operation profile, with the harness as ai_agent.name and the session as ai_agent.instance_uid and metadata.correlation_uid.
  • Decisions get the Security Control profile: a policy denial is Denied and Blocked, with the rule as policy; a person's answer to an approval request is Approved or Rejected.
  • A detection keeps its severity, its ATT&CK tactics and techniques as attacks, the calls it matched as finding_info.related_events, and the agent as an evidences entry.

💬 Review

  • Fixtures come from Agentmetry's real ingest API with synthetic sessions (agentmetry demo plus a generated session per event type). Host and user names are replaced, and the trail excerpt is re-chained so that it still verifies.
  • Judgment calls I'd like your view on:
    • A changed MCP tools/list fingerprint (the shape of an MCP rug pull) is a Detection Finding with severity Unknown, because Agentmetry assigns it none. A Base Event would be the conservative alternative.
    • MITRE ATLAS ids (for example AML.T0109) stay under unmapped, so that ATT&CK consumers of attacks don't misread them. I wasn't sure whether attacks is meant to carry other frameworks.
    • Agentmetry keeps only a hash of the tool arguments unless the operator turns on full capture, so a file tool call on a default install has no path. It becomes API Activity rather than a File System Activity without a file.
    • The trail's chain hashes stay under unmapped. Record Integrity looked like a fit, but an attestation covers the OCSF event, and these hashes cover the Agentmetry event, so they would not verify.
    • An approval request that was still open when the session ended is recorded by Agentmetry as denied. It maps to action Denied with disposition Unknown, and the reason as status_detail.
  • unmapped keeps Agentmetry's own classification of each call (tool.mitre, tool.atlas), DLP matches, and source_topic. Happy to trim it.

✅ Validation

  • Written with Claude Code with the tenzir skill loaded, and kunai, anthropic and openai as the style references.
  • uvx tenzir-test agentmetry: 7 tests pass on Tenzir v6.20.1, and with --prerelease allow.
  • The schema test runs ocsf_cast over all 20 fixture events, so an attribute that OCSF 1.9.0 does not know fails the run.
  • Each new .tql file passes the syntax check (--dump-ir for examples and tests, --dump-ast for operators).
  • Not tested: a live Agentmetry webhook posting into accept_http. The fixtures are the recorder's output, captured to file.

I maintain Agentmetry, and the canonical schema changes only additively within 1.x, so the fields this mapping reads are not renamed or moved. I'll keep the package current when the schema grows.

🤖 Generated with Claude Code

📚 Docs PR: tenzir/content#558

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-02T18:52:43.656042Z
We couldn’t complete this review. Comment @codex review to try again.
3f94ccf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@mavam
mavam enabled auto-merge (squash) November 3, 2026 13:29
blitzcrieg1 and others added 2 commits November 3, 2026 14:33
Agentmetry records the tool calls of AI coding agents from their own
hooks and correlates them into detections. The library had no mapping
for its events, so activity from Cursor, Copilot and the other
hook-only agents could not join the OCSF pipelines next to the
anthropic and openai packages.

The package maps the canonical event and the trail line to OCSF 1.9.0:
shell calls to Process Activity, file calls with a path to File System
Activity, other tools to API Activity, and detections and changed MCP
tool listings to Detection Findings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace nested conditional mappings with lookups and classify tool
results once for message selection. Rely on null propagation instead
of defensive checks and leave empty source records intact.

Preserve unknown agent attributes that cleanup previously discarded.
Cover missing and null optional fields and update output snapshots.
@mavam
mavam force-pushed the agentmetry-package branch from 4578855 to ba1245b Compare November 3, 2026 13:34
@mavam
mavam merged commit 932bfb2 into tenzir:main Nov 3, 2026
3 checks passed
@blitzcrieg1

blitzcrieg1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for merging, and for the simplification pass. The lookup table for file activities and the optional-fields test are cleaner than what I had, and I'll follow that style as the schema grows.

One related note: 0.10.5 went out today, and an event from an oversized command now carries tool.classification: "partial" over HTTP (an earlier release dropped it at our receiver). It lands in unmapped with no change on your side.

And a question, not a request: do you see Tenzir users rolling out Claude Code, Cursor or Codex across a team? If one of them wanted to try the package on a few laptops, I'd set it up with them and fix whatever breaks the same day. "Not yet" is a useful answer too.

zedoraps added a commit that referenced this pull request Nov 3, 2026
Integrate the Agentmetry package added by #211. The merge has no
conflicts; follow-up validation aligns its OCSF tests with this branch.
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.

2 participants