FFAI
Declarative context handling API wrapper for AI clients.
This module provides the FFAI class which wraps AI client implementations and adds declarative context management, history tracking, and DataFrame export capabilities.
Declarative context handling API wrapper for AI clients.
This module provides the FFAI class which wraps AI client implementations and adds declarative context management, history tracking, and DataFrame export capabilities.
- class FFAI(client, persist_dir=None, persist_name=None, auto_persist=False, shared_prompt_attr_history=None, history_lock=None, rag=None, memory_enabled=None, memory_embeddings=None, memory_persist=None, memory=None)[source]
Bases:
objectDeclarative context handling wrapper for AI clients.
This class wraps an AI client implementation and exposes three namespaced managers:
workflow— execution orchestration (generate, DAG, workflows)history— interaction queries, DataFrame export, persistencerag— retrieval-augmented generation (query, index, search)
- client
The underlying AI client instance.
- workflow
WorkflowEnginefor execution orchestration.
- history
HistoryManagerfor history queries and export.history.memoryexposes theMemoryinstance when memory is enabled (elseNone).history.search()performs semantic recall.
- rag
RAGinstance, orNoneif not configured.
- persist_dir
Directory for history persistence files.
- persist_name
Filename stem for persisted files.
- auto_persist
Whether histories auto-persist after each call.
- Parameters:
client (FFAIClientBase) – AI client to wrap.
persist_dir (str | None) – Directory for history persistence files.
persist_name (str | None) – Filename stem for persisted files.
auto_persist (bool) – Whether to auto-persist histories after each call.
shared_prompt_attr_history (list[dict[str, Any]] | None) – Optional shared prompt-attr list.
history_lock (threading.Lock | None) – Optional thread lock for history access.
rag (RAG | None) – Optional pre-constructed
RAGinstance.memory_enabled (bool | None) – Override
config.memory.enabled.Nonefalls through to config (defaultFalse).memory_embeddings (str | None) – Override
config.memory.embedding_model.Nonefalls through to config; triggers the resolution ladder if config is alsoNone.memory_persist (bool | None) – Override
config.memory.persist.Nonefalls through to config (defaultFalse).memory (Memory | None)
- property rag: RAG | None
RAG instance for retrieval-augmented generation.
Setting this property automatically wires the current client as the RAG’s default
generate_fnviaClientAdapter.
- set_client(client)[source]
Switch to a different AI client.
- Parameters:
client (FFAIClientBase)
- Return type:
None
- get_system_instructions()[source]
Return the system instructions configured on the client, or
None.- Return type:
str | None
- get_client_conversation_history()[source]
Get the raw conversation history from the underlying client.
- set_client_conversation_history(history)[source]
Set the raw conversation history in the underlying client.
- extract_json_field(data, path)[source]
Extract a value from JSON using dot notation path.
Supports: - Simple fields: “field_name” - Nested objects: “object.field” - Array indices: “array.0” - Combined: “object.array.0.field”
- interpolate_prompt(prompt, history, strict=False)[source]
Replace {{prompt_name.response}} patterns with actual content.
- Parameters:
- Returns:
Tuple of (resolved_prompt, set_of_interpolated_prompt_names)
- Return type:
Classes
- class FFAI(client, persist_dir=None, persist_name=None, auto_persist=False, shared_prompt_attr_history=None, history_lock=None, rag=None, memory_enabled=None, memory_embeddings=None, memory_persist=None, memory=None)[source]
Bases:
objectDeclarative context handling wrapper for AI clients.
This class wraps an AI client implementation and exposes three namespaced managers:
workflow— execution orchestration (generate, DAG, workflows)history— interaction queries, DataFrame export, persistencerag— retrieval-augmented generation (query, index, search)
- client
The underlying AI client instance.
- workflow
WorkflowEnginefor execution orchestration.
- history
HistoryManagerfor history queries and export.history.memoryexposes theMemoryinstance when memory is enabled (elseNone).history.search()performs semantic recall.
- rag
RAGinstance, orNoneif not configured.
- persist_dir
Directory for history persistence files.
- persist_name
Filename stem for persisted files.
- auto_persist
Whether histories auto-persist after each call.
- Parameters:
client (FFAIClientBase) – AI client to wrap.
persist_dir (str | None) – Directory for history persistence files.
persist_name (str | None) – Filename stem for persisted files.
auto_persist (bool) – Whether to auto-persist histories after each call.
shared_prompt_attr_history (list[dict[str, Any]] | None) – Optional shared prompt-attr list.
history_lock (threading.Lock | None) – Optional thread lock for history access.
rag (RAG | None) – Optional pre-constructed
RAGinstance.memory_enabled (bool | None) – Override
config.memory.enabled.Nonefalls through to config (defaultFalse).memory_embeddings (str | None) – Override
config.memory.embedding_model.Nonefalls through to config; triggers the resolution ladder if config is alsoNone.memory_persist (bool | None) – Override
config.memory.persist.Nonefalls through to config (defaultFalse).memory (Memory | None)
- property rag: RAG | None
RAG instance for retrieval-augmented generation.
Setting this property automatically wires the current client as the RAG’s default
generate_fnviaClientAdapter.
- set_client(client)[source]
Switch to a different AI client.
- Parameters:
client (FFAIClientBase)
- Return type:
None
- get_system_instructions()[source]
Return the system instructions configured on the client, or
None.- Return type:
str | None
- get_client_conversation_history()[source]
Get the raw conversation history from the underlying client.
- set_client_conversation_history(history)[source]
Set the raw conversation history in the underlying client.