Skip to main content

agrag.agents.ledger.Ledger

Ledger() -> None

Assigns and tracks stable citation keys for one agent run.

A key (E1, R1, C1 for entities, relations, and chunks) is assigned the first time this run encounters that item, by SearchResult.identity_key, and never reassigned within the run. The agent is shown rendered evidence carrying these keys, never raw SearchResults. A chunk result that has a parent shows the parent text under the first child's key. Later children of that parent show their own text and name the first key.

Functions:

  • cite – Return this result's citation key, assigning one if new.
  • render – Return the markdown-with-key text the agent sees.
  • resolve – Return the SearchResult behind a citation key.

Attributes:

  • keys (list[str]) – Return all citation keys assigned so far.

cite​

cite(result:SearchResult) -> str

Return this result's citation key, assigning one if new.

Parameters:

  • result (SearchResult) – The SearchResult to assign a key to.

Returns:

  • str – The citation key (e.g. E1, C3).

keys​

keys: list[str]

Return all citation keys assigned so far.

render​

render(result:SearchResult) -> str

Return the markdown-with-key text the agent sees.

Parameters:

Returns:

  • str – Markdown text with the citation key and item summary.

resolve​

resolve(key:str) -> SearchResult | None

Return the SearchResult behind a citation key.

Parameters:

  • key (str) – The citation key to look up.

Returns:

  • SearchResult | None – The SearchResult, or None if the key is unknown.