core.history.recorder
Single point for writing interactions to all history stores.
Single point for writing interactions to all history stores.
- class HistoryRecorder(context, permanent_history, ordered_history, memory=None, memory_persist=False, memory_persist_path=None)[source]
Bases:
objectRecords interactions to all 5 history stores in a single operation.
Owns the raw
historyandclean_historylists and coordinates writes toPermanentHistory,OrderedPromptHistory, andResponseContext. Optionally embeds each recorded Q+A pair into aMemoryinstance on a fire-and-forget background thread.Callers invoke
record()instead of manually writing to 5 separate stores.- Parameters:
context (ResponseContext) – The ResponseContext for prompt_attr_history recording.
permanent_history (PermanentHistory) – The PermanentHistory for chronological turns.
ordered_history (OrderedPromptHistory) – The OrderedPromptHistory for named interactions.
memory (Memory | None) – Optional Memory instance. When provided, each successful
record()call submits an embedding task to a dedicated single-worker thread pool. Failed embeds are logged atWARNINGand dropped; they never propagate to the caller.memory_persist (bool) – If
True, persist the memory store to Parquet after each successful embed. Requiresmemory_persist_pathto be set.memory_persist_path (str | None) – Fully-qualified file path for the Parquet persistence file. Ignored when
memory_persistisFalseormemoryisNone. Typically computed byFFAI.__init__()asf"{config.memory.persist_dir}/{config.memory.collection_name}.parquet".
- record(prompt, response, model, prompt_name=None, history=None, status='success', resolved_prompt=None, usage=None, metadata=None)[source]
Record an interaction to all 5 history stores.
When a
Memoryinstance is configured andstatus == "success", the Q+A pair is embedded on a fire-and-forget background thread. Metadata is derived fromprompt_namewhen not explicitly passed.- Parameters:
prompt (str) – The resolved prompt text.
response (Any) – The cleaned response.
model (str) – Model identifier used.
prompt_name (str | None) – Logical name for the prompt.
history (list[str] | None) – List of prompt names this call depends on.
status (str) – Execution status (“success”, “skipped”, “failed”). Only
"success"triggers embedding.resolved_prompt (str | None) – The fully interpolated prompt sent to the model.
usage (Any) – Token usage from the API call.
metadata (dict[str, Any] | None) – Optional caller metadata. When
None, derived fromprompt_nameas{"prompt_name": prompt_name}(or{}ifprompt_nameis alsoNone).
- Return type:
None
Classes
- class HistoryRecorder(context, permanent_history, ordered_history, memory=None, memory_persist=False, memory_persist_path=None)[source]
Bases:
objectRecords interactions to all 5 history stores in a single operation.
Owns the raw
historyandclean_historylists and coordinates writes toPermanentHistory,OrderedPromptHistory, andResponseContext. Optionally embeds each recorded Q+A pair into aMemoryinstance on a fire-and-forget background thread.Callers invoke
record()instead of manually writing to 5 separate stores.- Parameters:
context (ResponseContext) – The ResponseContext for prompt_attr_history recording.
permanent_history (PermanentHistory) – The PermanentHistory for chronological turns.
ordered_history (OrderedPromptHistory) – The OrderedPromptHistory for named interactions.
memory (Memory | None) – Optional Memory instance. When provided, each successful
record()call submits an embedding task to a dedicated single-worker thread pool. Failed embeds are logged atWARNINGand dropped; they never propagate to the caller.memory_persist (bool) – If
True, persist the memory store to Parquet after each successful embed. Requiresmemory_persist_pathto be set.memory_persist_path (str | None) – Fully-qualified file path for the Parquet persistence file. Ignored when
memory_persistisFalseormemoryisNone. Typically computed byFFAI.__init__()asf"{config.memory.persist_dir}/{config.memory.collection_name}.parquet".
- record(prompt, response, model, prompt_name=None, history=None, status='success', resolved_prompt=None, usage=None, metadata=None)[source]
Record an interaction to all 5 history stores.
When a
Memoryinstance is configured andstatus == "success", the Q+A pair is embedded on a fire-and-forget background thread. Metadata is derived fromprompt_namewhen not explicitly passed.- Parameters:
prompt (str) – The resolved prompt text.
response (Any) – The cleaned response.
model (str) – Model identifier used.
prompt_name (str | None) – Logical name for the prompt.
history (list[str] | None) – List of prompt names this call depends on.
status (str) – Execution status (“success”, “skipped”, “failed”). Only
"success"triggers embedding.resolved_prompt (str | None) – The fully interpolated prompt sent to the model.
usage (Any) – Token usage from the API call.
metadata (dict[str, Any] | None) – Optional caller metadata. When
None, derived fromprompt_nameas{"prompt_name": prompt_name}(or{}ifprompt_nameis alsoNone).
- Return type:
None