Skip to content

Add generic agent activity tracking and Alembic migrations - #6

Merged
kevinhermawan merged 1 commit into
mainfrom
feat/agent-activity-tracking
Jun 18, 2026
Merged

Add generic agent activity tracking and Alembic migrations#6
kevinhermawan merged 1 commit into
mainfrom
feat/agent-activity-tracking

Conversation

@kevinhermawan

Copy link
Copy Markdown
Collaborator

Summary

Adds generic agent activity tracking so every agent run and tool call in the newsroom pipeline is recorded in a queryable agent_activity table, tied to its newsletter. Tracking is wired in automatically via a shared make_agent factory, so no per-agent code is needed now or in the future.

Related issues

Closes #5

Changes

  • New agent_activity table: kind, name, model, status, duration, token counts (input/output/total), error, metadata JSONB
  • Newsletter lifecycle split into create_newsletter (pending placeholder up front) and finalize_newsletter (fills content + flips status), so newsletter_id exists before agents run
  • ActivityTracker and ToolTracker middleware auto-injected into every agent via make_agent; token counts read from AgentResponse.usage_details; tool args and result length recorded in metadata
  • agents/runtime/ subpackage consolidates agent runtime helpers: chat_client.py, guardrails.py, make_agent.py, tracking.py
  • agents/sections.py moved from utils/; utils/ package removed
  • Alembic migrations added (alembic/) with a hand-written initial migration covering all three tables; docker-entrypoint.sh runs alembic upgrade head on startup

How to test

  1. conda run -n agentic-mediapulse pytest — 107 tests pass
  2. conda run -n agentic-mediapulse ruff check . && ruff format --check . — clean
  3. With a real DATABASE_URL: python src/app.py test --email=you@example.com, then query select name, kind, status, duration_ms, total_tokens from agent_activity order by created_at;

Records every agent run and tool call (status, duration, token usage, model,
error) tied to its newsletter in a new agent_activity table. Introduces a
newsletter lifecycle (create placeholder up front, finalize after generation)
so newsletter_id exists before agents run. Moves agent runtime helpers
(chat_client, guardrails, make_agent, tracking) into agents/runtime/ and wires
ActivityTracker + ToolTracker into every agent via a shared make_agent factory.
Adds Alembic migrations that run automatically in Docker on startup.
@kevinhermawan
kevinhermawan merged commit 72f0875 into main Jun 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add generic agent activity tracking per newsletter

1 participant