Complete local hybrid search and improve agent reliability

This commit is contained in:
Hamza Ayed
2026-10-02 23:38:02 +03:00
parent 3563a104a3
commit 140f6eb287
62 changed files with 7546 additions and 314 deletions
+44
View File
@@ -103,6 +103,17 @@ def initialize_database() -> None:
);
CREATE INDEX IF NOT EXISTS idx_answer_feedback_user
ON answer_feedback(user_id, updated_at DESC);
CREATE TABLE IF NOT EXISTS agent_audit_events (
id TEXT PRIMARY KEY,
tool TEXT NOT NULL,
method TEXT NOT NULL,
status_code INTEGER NOT NULL,
duration_ms INTEGER NOT NULL,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_agent_audit_created
ON agent_audit_events(created_at DESC);
"""
)
message_columns = {
@@ -319,4 +330,37 @@ def save_answer_feedback(
)
def record_agent_audit_event(
event_id: str,
tool: str,
method: str,
status_code: int,
duration_ms: int,
) -> None:
"""Record agent route metadata only; never persist prompts or file contents."""
with _connect() as connection:
connection.execute(
"""
INSERT INTO agent_audit_events(id, tool, method, status_code, duration_ms)
VALUES (?, ?, ?, ?, ?)
""",
(event_id, tool, method, status_code, duration_ms),
)
def list_agent_audit_events(limit: int = 50) -> list[dict[str, Any]]:
bounded_limit = max(1, min(limit, 200))
with _connect() as connection:
rows = connection.execute(
"""
SELECT id, tool, method, status_code, duration_ms, created_at
FROM agent_audit_events
ORDER BY created_at DESC, rowid DESC
LIMIT ?
""",
(bounded_limit,),
).fetchall()
return [dict(row) for row in rows]
initialize_database()