Skip to main content

6 of 16

Records library

Write session records from your own program, such as an LLM gateway.

docs/library.md

Records library

The Rust crate agenticspec-records holds what the agenticspec command uses: the transcript reader, redaction, the store, the KPIs and the queries. A program that sees model traffic, such as an LLM gateway, uses it to write the same records into a store that agenticspec reads.

[dependencies]
agenticspec-records = { git = "https://github.com/beyond10x/agenticspec", tag = "<version>" }
agenticspec-types = { git = "https://github.com/beyond10x/agenticspec", tag = "<version>" }

Record gateway traffic​

Per finished model call, lift the call into steps and hand them to the appender:

use std::path::Path;
use agenticspec_records::append::Appender;
use agenticspec_records::wire::{self, Answer, GatewayFacts, Wire, WireCall, WireSession};
use agenticspec_types::session::Harness;

let (appender, writer) = Appender::spawn(Path::new("sessions.db"), 1024)?;
let mut session = WireSession::new(); // keep one per gateway session

let call = WireCall {
wire: Wire::Messages,
request: request_body,
answer: Answer::Events(sse_payloads),
facts: GatewayFacts { /* call id, session hash, route, timings, ... */ },
};
let steps = wire::lift_call(&mut session, &call);
appender.append(&call.facts.session_hash, Harness::ClaudeCode, steps);
itemwhat it does
Wirethe API the client spoke: Messages, Chat or Responses
Answerthe answer as relayed: a whole JSON Body, or the Events of a stream
GatewayFactswhat the gateway knows itself: call id, session hash, route, upstream, attempts, queue wait, time to first token, declared cost, start and end
WireSessionwhat is kept per session between calls, so each call is attributed to the right agent
wire::lift_callturns one finished call into steps
wire::session_hash(source, value)the 12-hex-digit session id the gateway derives from a session header
Appender::spawn(path, capacity)opens the store and starts a writer thread behind a queue of capacity batches
AppenderHandle::appendqueues one call's steps. It never blocks: when the queue is full it returns false and counts a drop
AppenderHandle::statscounts of batches queued, dropped, written and failed

The writer extends each session's views as steps arrive, so agenticspec serve on the same store shows gateway sessions live. The writer thread ends when every handle is dropped and the queue is drained. Join it with the returned handle.

Join gateway facts to transcripts​

When the same session is also recorded on disk, wire::join(&mut disk_steps, &wire_steps) copies the gateway's facts onto the transcript's model turns with the same message id. It returns how many turns it joined. Message ids match for Anthropic traffic.

Privacy​

The wire lift keeps lengths and SHA-256 digests of content, never the text. It does not scan gateway traffic for secrets and personal data yet, so gateway sessions report no exposures. See Privacy.