Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::SqliteStorageBackend Class Reference

SQLite-based storage backend. More...

#include <entropic/storage/backend.h>

Public Member Functions

 SqliteStorageBackend (const std::filesystem::path &db_path)
 Construct with database file path.
 
bool initialize ()
 Initialize storage (open database, run migrations).
 
void close ()
 Close storage and database connection.
 
std::string create_conversation (const std::string &title="New Conversation", const std::optional< std::string > &project_path=std::nullopt, const std::optional< std::string > &model_id=std::nullopt)
 Create a new conversation.
 
bool save_messages (const std::string &conversation_id, const std::string &messages_json)
 Save messages to a conversation.
 
bool load_conversation (const std::string &conversation_id, std::string &result_json)
 Load a conversation with messages.
 
bool list_conversations (int limit, int offset, std::string &result_json)
 List conversations with pagination.
 
bool delete_conversation (const std::string &conversation_id)
 Delete a conversation and all associated records.
 
bool update_title (const std::string &conversation_id, const std::string &title)
 Update a conversation's title.
 
bool search_conversations (const std::string &query, int limit, std::string &result_json)
 Full-text search across conversations.
 
bool create_delegation (const std::string &parent_conversation_id, const std::string &delegating_tier, const std::string &target_tier, const std::string &task, int max_turns, std::string &delegation_id, std::string &child_conversation_id)
 Create a delegation record with a child conversation.
 
bool complete_delegation (const std::string &delegation_id, const std::string &status, const std::optional< std::string > &result_summary=std::nullopt)
 Mark a delegation as completed or failed.
 
bool get_delegations (const std::string &conversation_id, std::string &result_json)
 Get delegations for a parent conversation.
 
bool get_delegation_by_id (const std::string &delegation_id, std::string &result_json)
 Look up a single delegation record by id (gh#32, v2.1.6).
 
bool search_delegations (const std::string &query, int max_results, std::string &result_json)
 Search delegations across all conversations (gh#32, v2.1.6).
 
bool save_snapshot (const std::string &conversation_id, const std::string &messages_json)
 Save a pre-compaction snapshot of full conversation history.
 
bool get_stats (std::string &result_json)
 Get storage statistics.
 

Detailed Description

SQLite-based storage backend.

Provides conversation persistence, message storage, delegation record management, full-text search, and compaction snapshots. Thread-safe via SqliteDatabase's internal mutex.

Lifecycle:
SqliteStorageBackend storage("/path/to/entropic.db");
storage.initialize();
auto id = storage.create_conversation("Title");
storage.save_messages(id, messages_json);
storage.close();
SQLite-based storage backend.
Definition backend.h:43
Version
1.8.8

Definition at line 43 of file backend.h.

Constructor & Destructor Documentation

◆ SqliteStorageBackend()

entropic::SqliteStorageBackend::SqliteStorageBackend ( const std::filesystem::path &  db_path)
explicit

Construct with database file path.

Parameters
db_pathPath to SQLite database file.
Version
1.8.8
Parameters
db_pathPath to SQLite file.

Definition at line 97 of file backend.cpp.

Member Function Documentation

◆ close()

void entropic::SqliteStorageBackend::close ( )

Close storage and database connection.

Close storage.

Version
1.8.8

Definition at line 116 of file backend.cpp.

◆ complete_delegation()

bool entropic::SqliteStorageBackend::complete_delegation ( const std::string &  delegation_id,
const std::string &  status,
const std::optional< std::string > &  result_summary = std::nullopt 
)

Mark a delegation as completed or failed.

Parameters
delegation_idDelegation ID.
status"completed" or "failed".
result_summarySummary text (optional).
Returns
true on success.
Version
1.8.8
Parameters
delegation_idDelegation ID.
status"completed" or "failed".
result_summaryOptional summary text.
Returns
true on success.

Definition at line 602 of file backend.cpp.

◆ create_conversation()

std::string entropic::SqliteStorageBackend::create_conversation ( const std::string &  title = "New Conversation",
const std::optional< std::string > &  project_path = std::nullopt,
const std::optional< std::string > &  model_id = std::nullopt 
)

Create a new conversation.

Parameters
titleConversation title.
project_pathProject path (optional).
model_idModel identifier (optional).
Returns
Conversation ID (UUID string).
Version
1.8.8
Parameters
titleConversation title.
project_pathOptional project path.
model_idOptional model identifier.
Returns
Conversation ID.

Definition at line 131 of file backend.cpp.

◆ create_delegation()

bool entropic::SqliteStorageBackend::create_delegation ( const std::string &  parent_conversation_id,
const std::string &  delegating_tier,
const std::string &  target_tier,
const std::string &  task,
int  max_turns,
std::string &  delegation_id,
std::string &  child_conversation_id 
)

Create a delegation record with a child conversation.

Create a delegation with a child conversation.

Parameters
parent_conversation_idParent conversation ID.
delegating_tierTier initiating delegation.
target_tierTarget tier for child loop.
taskTask description.
max_turnsMax turns for child (0 = unlimited).
[out]delegation_idCreated delegation ID.
[out]child_conversation_idCreated child conversation ID.
Returns
true on success.
Version
1.8.8
Parameters
parent_conversation_idParent conversation.
delegating_tierSource tier.
target_tierTarget tier.
taskTask description.
max_turnsTurn limit (0 = unlimited).
[out]delegation_idCreated delegation ID.
[out]child_conversation_idCreated child conversation ID.
Returns
true on success.

Definition at line 540 of file backend.cpp.

◆ delete_conversation()

bool entropic::SqliteStorageBackend::delete_conversation ( const std::string &  conversation_id)

Delete a conversation and all associated records.

Delete a conversation and all cascading records.

Parameters
conversation_idConversation ID.
Returns
true on success.
Version
1.8.8
Parameters
conversation_idConversation ID.
Returns
true on success.

Definition at line 385 of file backend.cpp.

◆ get_delegation_by_id()

bool entropic::SqliteStorageBackend::get_delegation_by_id ( const std::string &  delegation_id,
std::string &  result_json 
)

Look up a single delegation record by id (gh#32, v2.1.6).

Used by entropic.followup and entropic.resume_delegation to resolve a delegation's target_tier and child_conversation_id without scanning all parents.

Parameters
delegation_idDelegation id.
[out]result_jsonSingle-object JSON with the delegation row.
Returns
true on success and a row was found; false on absence/error.
Version
2.1.6
Parameters
delegation_idDelegation id.
[out]result_jsonObject JSON of the delegation row.
Returns
true if found and parsed.

Definition at line 708 of file backend.cpp.

◆ get_delegations()

bool entropic::SqliteStorageBackend::get_delegations ( const std::string &  conversation_id,
std::string &  result_json 
)

Get delegations for a parent conversation.

Parameters
conversation_idParent conversation ID.
[out]result_jsonJSON array of delegation records.
Returns
true on success.
Version
1.8.8
Parameters
conversation_idParent conversation ID.
[out]result_jsonJSON array of delegation records.
Returns
true on success.

Definition at line 681 of file backend.cpp.

◆ get_stats()

bool entropic::SqliteStorageBackend::get_stats ( std::string &  result_json)

Get storage statistics.

Parameters
[out]result_jsonJSON with total_conversations, total_messages, total_tokens.
Returns
true on success.
Version
1.8.8
Parameters
[out]result_jsonJSON with counts.
Returns
true on success.

Definition at line 807 of file backend.cpp.

◆ initialize()

bool entropic::SqliteStorageBackend::initialize ( )

Initialize storage (open database, run migrations).

Initialize storage.

Returns
true on success.
Version
1.8.8
Returns
true on success.

Definition at line 107 of file backend.cpp.

◆ list_conversations()

bool entropic::SqliteStorageBackend::list_conversations ( int  limit,
int  offset,
std::string &  result_json 
)

List conversations with pagination.

Parameters
limitMaximum results.
offsetPagination offset.
[out]result_jsonJSON array of conversation summaries.
Returns
true on success.
Version
1.8.8
Parameters
limitMax results.
offsetPagination offset.
[out]result_jsonJSON array of summaries.
Returns
true on success.

Definition at line 349 of file backend.cpp.

◆ load_conversation()

bool entropic::SqliteStorageBackend::load_conversation ( const std::string &  conversation_id,
std::string &  result_json 
)

Load a conversation with messages.

Load a conversation with its messages.

Parameters
conversation_idConversation ID.
[out]result_jsonJSON with "conversation" and "messages".
Returns
true if found.
Version
1.8.8
Parameters
conversation_idConversation ID.
[out]result_jsonJSON result.
Returns
true if found.

Definition at line 309 of file backend.cpp.

◆ save_messages()

bool entropic::SqliteStorageBackend::save_messages ( const std::string &  conversation_id,
const std::string &  messages_json 
)

Save messages to a conversation.

Parameters
conversation_idConversation ID.
messages_jsonJSON array of message objects.
Returns
true on success.
Version
1.8.8
Parameters
conversation_idConversation ID.
messages_jsonJSON array of message objects.
Returns
true on success.

Definition at line 225 of file backend.cpp.

◆ save_snapshot()

bool entropic::SqliteStorageBackend::save_snapshot ( const std::string &  conversation_id,
const std::string &  messages_json 
)

Save a pre-compaction snapshot of full conversation history.

Save a pre-compaction snapshot.

Parameters
conversation_idConversation ID.
messages_jsonJSON array of all messages before compaction.
Returns
true on success.
Version
1.8.8
Parameters
conversation_idConversation ID.
messages_jsonJSON array of all messages.
Returns
true on success.

Definition at line 774 of file backend.cpp.

◆ search_conversations()

bool entropic::SqliteStorageBackend::search_conversations ( const std::string &  query,
int  limit,
std::string &  result_json 
)

Full-text search across conversations.

Full-text search across conversations via FTS5.

Parameters
queryFTS5 query string.
limitMaximum results.
[out]result_jsonJSON array of search results with snippets.
Returns
true on success.
Version
1.8.8
Parameters
queryFTS5 query string.
limitMax results.
[out]result_jsonJSON array of search results.
Returns
true on success.

Definition at line 426 of file backend.cpp.

◆ search_delegations()

bool entropic::SqliteStorageBackend::search_delegations ( const std::string &  query,
int  max_results,
std::string &  result_json 
)

Search delegations across all conversations (gh#32, v2.1.6).

Substring-match delegations across all conversations.

Substring match against result_summary (case-insensitive). Returns the top-N most recently completed delegations whose summary contains query.

Parameters
queryKeyword/phrase to match.
max_resultsMaximum records to return.
[out]result_jsonJSON array of matching delegation rows.
Returns
true on success.
Version
2.1.6

Bound to top-N most recently completed records. Uses sqlite's LIKE for portability — FTS5 is wired for messages, not delegation summaries.

Parameters
querySubstring to match (LIKE query%).
max_resultsCap on returned rows.
[out]result_jsonJSON array of delegation rows.
Returns
true on success.

Definition at line 744 of file backend.cpp.

◆ update_title()

bool entropic::SqliteStorageBackend::update_title ( const std::string &  conversation_id,
const std::string &  title 
)

Update a conversation's title.

Parameters
conversation_idConversation ID.
titleNew title.
Returns
true on success.
Version
1.8.8
Parameters
conversation_idConversation ID.
titleNew title.
Returns
true on success.

Definition at line 404 of file backend.cpp.


The documentation for this class was generated from the following files: