Skip to main content

history

Read turn logs and durable memory without starting an agent or changing the files.

source

History

def History(
    cfg:NoneType=None, # config folder; None uses the folder containing `config_path()`
    history_name:str='agent', # history file prefix
):

Read turn logs and memory without changing them.

sessions lists each conversation in a log, newest first. The example writes a log of two conversations into a temporary config folder and reads it back with History.

import tempfile
cfg = Path(tempfile.mkdtemp())
rows = [{'at': 1, 'session': 'a', 'prompt': 'Fix the parser. Then test it.', 'model': 'gpt-mini'},
        {'at': 2, 'session': 'a', 'prompt': 'Run the tests.', 'model': 'gpt-mini'},
        {'at': 3, 'session': 'b', 'prompt': 'Explain the index', 'model': 'gpt-mini'}]
(cfg/'agent-history.jsonl').write_text(''.join(json.dumps(r) + '\n' for r in rows))
before = sorted(p.name for p in cfg.iterdir())
History(cfg).sessions()

Reading creates no file in the config folder, not even the session index.

assert sorted(p.name for p in cfg.iterdir()) == before
before