Skip to main content

Crate klieo_runlog

Crate klieo_runlog 

Source
Expand description

klieo-runlog — Tier 2 observability for klieo agents.

This crate ships:

  • A RunLog aggregate type (the spec §8.2 view: run_id, agent, started_at, finished_at, status, steps, tokens, cost_estimate).
  • A pluggable RunLogStore trait. Default in-memory; SQLite behind sqlite feature.
  • Deterministic compaction (drop-by-rule). LLM-summarise compaction behind compaction-llm feature.
  • A deterministic-only replay engine that re-runs recorded LLM + tool calls.

§Design: projection over EpisodicMemory, not a new trait

RunLog is not a separate sink. It is a projection computed by walking a Vec<klieo_core::Episode> returned from any EpisodicMemory::replay(run_id). The crate adds zero traits to klieo-core. Plan #11 froze that surface.

Typical wiring:

  EpisodicMemory --(replay)--> Vec<Episode> --(project)--> RunLog --(put)--> RunLogStore

§Replay caveats

replay is deterministic-only. It asserts that user-supplied test-double LlmClient + ToolInvoker produce byte-identical outputs to the recorded ones. Side effects that do not flow through these traits (timestamps, randomness, network calls outside the recorded LLM/tool calls) cannot be replayed.

Re-exports§

pub use crate::capture::Capture;
pub use crate::capture_sink::RunLogCaptureSink;
pub use crate::capture_store::gc_captures;
pub use crate::capture_store::load_capture;
pub use crate::capture_store::persist_capture;
pub use crate::capture_store::CAPTURE_BUCKET;
pub use crate::compaction::LlmCompaction;
pub use crate::compaction::CompactionPolicy;
pub use crate::compaction::DeterministicCompaction;
pub use crate::divergence::replay_with_divergence;
pub use crate::divergence::DivergenceReport;
pub use crate::divergence::ReplayMode;
pub use crate::divergence::ReproVerdict;
pub use crate::divergence::StepDivergence;
pub use crate::error::RunLogError;
pub use crate::fingerprint::request_fingerprint;
pub use crate::pricing::PriceTable;
pub use crate::pricing::Rates;
pub use crate::pricing::RatesError;
pub use crate::projector::project;
pub use crate::projector::project_with_llm_io;
pub use crate::projector::project_with_price_table;
pub use crate::replay::replay;
pub use crate::replay_llm::ReplayLlmClient;
pub use crate::store::InMemoryRunLogStore;
pub use crate::store::RunLogQuery;
pub use crate::store::RunLogStore;
pub use crate::store_sqlite::SqliteRunLogStore;
pub use crate::types::Cost;
pub use crate::types::LlmIo;
pub use crate::types::RunLog;
pub use crate::types::RunStatus;
pub use crate::types::Step;
pub use crate::types::StepKind;
pub use crate::types::Usage;

Modules§

capture
The Capture envelope (ADR-046): a single serializable artifact bundling everything needed to replay a run without a live store — the RunLog, the parallel LlmIo sidecar carrying prompt/completion text, and Option-typed provider-version / seed / memory metadata filled in when available.
capture_sink
Live CaptureSink that accumulates replayable LLM I/O (ADR-048).
capture_store
KvStore-backed persistence for the Capture artifact (ADR-046). The bucket holds one JSON blob per run, keyed by run id — the durable, cross-process channel for embedded and distributed callers. Offline operator export/import of the same serde blob goes through the klieo-replay CLI’s file path; both share Capture’s serialization.
compaction
CompactionPolicy trait + deterministic and (optional) LLM-summarise impls.
divergence
Soft-compare reproducibility reporting (ADR-046): replay a recorded run and collect per-step textual divergences instead of failing on the first mismatch, so non-deterministic runs yield an auditable report.
error
RunLogError — the only error surface for this crate.
fingerprint
Stable request fingerprint for replay-keying (ADR-048).
pricing
Pricing tables and per-(provider, model) USD rate lookup.
projector
Episode stream → RunLog aggregate projection.
replay
Deterministic-only replay engine.
replay_llm
Order-keyed structured LLM double for agent-loop re-drive (ADR-048).
store
RunLogStore trait and in-memory default implementation.
store_sqlite
SQLite-backed RunLogStore. Single-table schema with steps stored as JSON.
test_utils
Test helpers for downstream consumers that want to drive klieo’s deterministic replay engine without hand-wiring a FakeLlmClient.
types
Aggregate types for the RunLog projection.