# memory/database.py | |
import sqlite3 | |
import os | |
DB_PATH = os.path.join("/tmp", "memory.db") | |
def init_db(): | |
conn = sqlite3.connect(DB_PATH) | |
cursor = conn.cursor() | |
cursor.execute(""" | |
CREATE TABLE IF NOT EXISTS agent_logs ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
agent TEXT, | |
action TEXT, | |
result TEXT, | |
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP | |
) | |
""") | |
conn.commit() | |
conn.close() | |
def log_action(agent: str, action: str, result: str): | |
conn = sqlite3.connect(DB_PATH) | |
cursor = conn.cursor() | |
cursor.execute( | |
"INSERT INTO agent_logs (agent, action, result) VALUES (?, ?, ?)", | |
(agent, action, result) | |
) | |
conn.commit() | |
conn.close() | |