Skip to content

Commit 57b4f5e

Browse files
Refactor database initialization in SQLiteSessionMemory
- Introduced a new method `_init_db_for_connection` to handle database schema initialization for a specific connection. - Updated the `_init_db` method to call the new method, improving clarity and separation of concerns. - Added a comment to indicate the initialization of the database schema for the connection.
1 parent 4af2192 commit 57b4f5e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/agents/memory/session_memory.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ def _get_connection(self) -> sqlite3.Connection:
9696
check_same_thread=False,
9797
)
9898
self._local.connection.execute("PRAGMA journal_mode=WAL")
99+
# Initialize the database schema for this connection
100+
self._init_db_for_connection(self._local.connection)
99101
return self._local.connection
100102

101-
def _init_db(self) -> None:
102-
"""Initialize the database schema."""
103-
conn = self._get_connection()
103+
def _init_db_for_connection(self, conn: sqlite3.Connection) -> None:
104+
"""Initialize the database schema for a specific connection."""
104105
conn.execute(
105106
f"""
106107
CREATE TABLE IF NOT EXISTS {self.sessions_table} (
@@ -132,6 +133,11 @@ def _init_db(self) -> None:
132133

133134
conn.commit()
134135

136+
def _init_db(self) -> None:
137+
"""Initialize the database schema."""
138+
conn = self._get_connection()
139+
# The schema initialization is now handled in _init_db_for_connection
140+
135141
async def get_messages(self, session_id: str) -> list[TResponseInputItem]:
136142
"""Retrieve the conversation history for a given session.
137143

0 commit comments

Comments
 (0)