core.history.ordered
Ordered prompt-response history management with named references.
This module provides the OrderedPromptHistory class for managing AI interactions with named prompt references, enabling declarative context assembly in the FFAI wrapper.
Ordered prompt-response history management with named references.
This module provides the OrderedPromptHistory class for managing AI interactions with named prompt references, enabling declarative context assembly in the FFAI wrapper.
- class Interaction(sequence_number, model, timestamp, prompt_name, prompt, response, history=None)[source]
Bases:
objectRepresents a single prompt-response interaction.
- Parameters:
- class OrderedPromptHistory[source]
Bases:
objectManages ordered prompt-response history with named references.
This class provides: - Named prompt storage for declarative context assembly - Sequential ordering of interactions - Query capabilities by prompt name, model, etc. - History chain tracking for dependency resolution
- prompt_dict
OrderedDict mapping prompt names to interaction lists.
- prompt_dict: OrderedDict[str, list[Interaction]]
- get_effective_prompt_name(prompt_name)[source]
Get the effective prompt name from various input types.
- add_interaction(model, prompt, response, prompt_name=None, history=None)[source]
Add a new interaction to the history, storing cleaned versions of prompt and response.
- Parameters:
model (str) – The model used for the interaction
prompt (str) – The prompt text
response (str) – The response text
prompt_name (str | None) – Optional name/key for the prompt. If None, uses prompt text as key
history (list[str] | None) – Optional list of prompt names that form the history chain for this interaction
- Returns:
The created Interaction object
- Return type:
- get_interactions_by_prompt_name(prompt_name)[source]
Get all interactions for a specific prompt name.
- Parameters:
prompt_name (str)
- Return type:
- get_latest_interaction_by_prompt_name(prompt_name)[source]
Get the most recent interaction for a specific prompt name.
- Parameters:
prompt_name (str)
- Return type:
Interaction | None
- get_interactions_by_model_and_prompt_name(model, prompt_name)[source]
Get all interactions for a specific model and prompt name combination.
- Parameters:
- Return type:
- merge_histories(other)[source]
Merge another OrderedPromptHistory into this one.
- Parameters:
other (OrderedPromptHistory) – Another OrderedPromptHistory instance to merge
- Return type:
None
- get_interaction_by_prompt(prompt)[source]
Get an interaction by its exact prompt text.
Useful when prompt was used as the prompt_name.
- Parameters:
prompt (str)
- Return type:
Interaction | None
Classes
- class Interaction(sequence_number, model, timestamp, prompt_name, prompt, response, history=None)[source]
Bases:
objectRepresents a single prompt-response interaction.
- Parameters:
- class OrderedPromptHistory[source]
Bases:
objectManages ordered prompt-response history with named references.
This class provides: - Named prompt storage for declarative context assembly - Sequential ordering of interactions - Query capabilities by prompt name, model, etc. - History chain tracking for dependency resolution
- prompt_dict
OrderedDict mapping prompt names to interaction lists.
- prompt_dict: OrderedDict[str, list[Interaction]]
- get_effective_prompt_name(prompt_name)[source]
Get the effective prompt name from various input types.
- add_interaction(model, prompt, response, prompt_name=None, history=None)[source]
Add a new interaction to the history, storing cleaned versions of prompt and response.
- Parameters:
model (str) – The model used for the interaction
prompt (str) – The prompt text
response (str) – The response text
prompt_name (str | None) – Optional name/key for the prompt. If None, uses prompt text as key
history (list[str] | None) – Optional list of prompt names that form the history chain for this interaction
- Returns:
The created Interaction object
- Return type:
- get_interactions_by_prompt_name(prompt_name)[source]
Get all interactions for a specific prompt name.
- Parameters:
prompt_name (str)
- Return type:
- get_latest_interaction_by_prompt_name(prompt_name)[source]
Get the most recent interaction for a specific prompt name.
- Parameters:
prompt_name (str)
- Return type:
Interaction | None
- get_interactions_by_model_and_prompt_name(model, prompt_name)[source]
Get all interactions for a specific model and prompt name combination.
- Parameters:
- Return type:
- merge_histories(other)[source]
Merge another OrderedPromptHistory into this one.
- Parameters:
other (OrderedPromptHistory) – Another OrderedPromptHistory instance to merge
- Return type:
None
- get_interaction_by_prompt(prompt)[source]
Get an interaction by its exact prompt text.
Useful when prompt was used as the prompt_name.
- Parameters:
prompt (str)
- Return type:
Interaction | None