haive.core.engine.agent.persistence.manager¶
PostgreSQL persistence manager for the Haive framework.
This module provides a comprehensive persistence manager that integrates Supabase authentication with PostgreSQL persistence for agent state management. It centralizes thread registration, checkpoint management, and connection pool handling in a robust and reusable design.
The PersistenceManager class serves as the primary integration point between the HaiveRunnableConfigManager and the underlying PostgreSQL database.
Classes¶
Manages state persistence for agents, abstracting the complexity of different. |
Module Contents¶
- class haive.core.engine.agent.persistence.manager.PersistenceManager(config=None)[source]¶
Manages state persistence for agents, abstracting the complexity of different. checkpointer implementations and integrating with Supabase authentication.
This manager handles: 1. Auto-detection of available persistence options 2. Configuration of checkpointers (PostgreSQL, Memory) 3. Setup of database connections and pools 4. Thread registration with user context from Supabase 5. Integration with HaiveRunnableConfigManager for authentication
Initialize persistence manager with optional configuration.
- close_pool_if_needed()[source]¶
Close the PostgreSQL connection pool if it was opened by this manager.
- Return type:
None
- create_runnable_config(thread_id=None, user_info=None, **kwargs)[source]¶
Create a RunnableConfig with proper thread ID and authentication context.
- Parameters:
thread_id (str | None) – Optional thread ID for persistence
user_info – Optional user information dictionary (Supabase)
**kwargs – Additional runtime configuration
- Returns:
RunnableConfig with thread ID and authentication context
- delete_thread(thread_id)[source]¶
Delete a thread from the PostgreSQL database.
- Parameters:
thread_id (str) – Thread ID to delete
- Returns:
True if deletion succeeded, False otherwise
- ensure_pool_open()[source]¶
Ensure the PostgreSQL connection pool is open.
- Returns:
True if the pool was opened or is already open, False otherwise
- Return type:
- classmethod from_config(db_host='localhost', db_port=5432, db_name='postgres', db_user='postgres', db_pass='postgres', use_async=False, use_pool=True, setup_needed=True)[source]¶
Create a PersistenceManager from database configuration.
- Parameters:
db_host – Database host
db_port – Database port
db_name – Database name
db_user – Database user
db_pass – Database password
use_async – Whether to use async connections
use_pool – Whether to use connection pooling
setup_needed – Whether table setup is needed
- Returns:
Configured PersistenceManager
- classmethod from_env()[source]¶
Create a PersistenceManager from environment variables.
- Returns:
Configured PersistenceManager
- Return type:
Any
- get_checkpointer(persistence_type=None, persistence_config=None)[source]¶
Create and return the appropriate checkpointer based on configuration and available dependencies.
- list_threads(user_id=None, thread_id=None, limit=100, offset=0)[source]¶
List threads from the PostgreSQL database.
- prepare_for_agent_run(thread_id=None, user_info=None, **kwargs)[source]¶
Comprehensive preparation for an agent run, handling thread registration,. configuration creation, and database setup.
- Parameters:
thread_id (str | None) – Optional thread ID for persistence
user_info – Optional user information dictionary (Supabase)
**kwargs – Additional runtime configuration
- Returns:
Tuple of (RunnableConfig, current_thread_id)