Skip to content

tdfs4ds.impact_agent.ledger

tdfs4ds.impact_agent.ledger

The evidence ledger of an impact study: every tool call, who answered, how long it took.

Each entry: {"tool", "args", "digest", "duration", "source", "model", "ok", "skipped", "error"} (model is the model name on a model entry, skipped is True with the reason in error when a step was not run: no question, bad arguments, already done, budget spent) where source is code (a deterministic tool), consumer (the consumer agent was asked) or model (the impact agent's own model: planner or narrative). digest is a short hash of the result, so two studies can be compared without storing the results twice. Pure.

SOURCES module-attribute

SOURCES = ('code', 'consumer', 'model')

Ledger

An ordered list of entries. record adds one; entries is the JSON-able list.

entries instance-attribute

entries: List[Dict[str, Any]] = []

__init__

__init__()

record

record(tool: str, args: Optional[dict], result: Any, duration: float, source: str = 'code', error: Optional[str] = None, model: Optional[str] = None, skipped: bool = False) -> dict

count

count(*, tool: Optional[str] = None, source: Optional[str] = None) -> int

as_list

as_list() -> List[dict]

timed

with timed() as t: ... then t.seconds.

__enter__

__enter__()

__exit__

__exit__(*exc)

digest

digest(value: Any) -> str

A short, stable hash of a JSON-able value (repr for anything else).

_safe_args

_safe_args(args: Optional[dict]) -> dict