Interaction logging to Postgres #19
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Lineage
Standalone — operational observability for improving Nemo over time. Blocked by #21 (Postgres DB + NetworkPolicy infra).
Repo
forgejo_admin/westside-ai-assistantUser Story
As Lucas (platform operator)
I want every Nemo interaction logged to a database
So that I can analyze what Marcus asks, how Nemo responds, track token costs, and identify when tools are ready to graduate from read-only to read-write
Context
Every GroupMe message that Nemo processes gets logged: who asked, what they asked, what tools were called, what was returned, how many tokens were used. This is the training data for improving the system. Uses the existing CNPG Postgres cluster (pal-e-postgres). Database
nemoand usernemoprovisioned by #21. NetworkPolicy for postgres access provisioned by #21.File Targets
Files the agent should create:
app/logging_db.py— async database connection (asyncpg),log_interaction()functionmigrations/001_interaction_log.sql— CREATE TABLE interaction_log (id, timestamp, group_id, sender_name, message, bot_response, tools_called JSONB, tool_results JSONB, model, input_tokens, output_tokens, duration_ms)Files the agent should modify:
app/ai.py— after processing each message, calllog_interaction()with all fields. Token counts from Anthropic responseusage.input_tokensandusage.output_tokens. For multi-turn tool_use loops, sum tokens across all API calls in the interaction.app/config.py— adddatabase_url: str = ""settingrequirements.txt— addasyncpgFiles the agent should NOT touch:
app/basketball.py,app/groupme.py,app/confirmation.pyAcceptance Criteria
migrations/directory created with001_interaction_log.sqlDATABASE_URLconfigurable via env var, empty string disables logging gracefullyTest Expectations
pytest tests/ -vConstraints
usage.input_tokens,usage.output_tokens)Checklist
Related
project-westside-ai-assistant— parent projectScope Review: NEEDS_REFINEMENT (re-review)
Review note:
review-684-2026-03-28-v2Re-review of board item #684. Previous review (
review-684-2026-03-28) returned NEEDS_REFINEMENT with 4 recommendations. None have been addressed.Outstanding issues:
[SCOPE]No infra prerequisite ticket exists for DB creation, NetworkPolicy, or k8s secret. This blocks #19 — the app code cannot connect to Postgres without this work. File on pal-e-services or pal-e-platform.[BODY]migrations/directory does not exist — ticket should note it must be created.[BODY]Token counting needs clarification — tool_use loop makes multiple Anthropic API calls, total tokens should be summed.[BODY]Add explicit "Blocked by: infra ticket" dependency reference in Constraints.