YouTube Strategist
A private, owner-only YouTube Metadata Copilot for AI Simplified Lab.
One conversational interface to scan channel performance, find videos worth optimizing, formulate evidence-based metadata proposals, and publish either exact owner-approved proposals or eligible high-confidence proposals that pass the autonomous gatekeeper.
Architecture Overview
This repository uses one owner-authenticated Streamlit application as the control centre. GitHub Actions supplies reliable scheduled execution because Streamlit Community Cloud is not an always-on worker. Supabase stores encrypted OAuth grants, run snapshots, proposals, and an audit trail. No second dashboard is required.
Part 1: Streamlit Copilot and Autonomous YouTube Strategist
What It Does
- One owner-only Streamlit workspace: Google sign-in, YouTube OAuth, conversational metadata optimization, strategist settings, proposal approvals, performance evaluation, and run history stay in the existing app.
- Three monitoring and optimization cadences:
- Daily monitoring (
30 2 * * * UTC / 08:00 AM IST): rapid detection of emerging packaging underperformance, recent upload health, steady maintenance.
- Weekly optimization (
30 3 * * 0 UTC / Sun 09:00 AM IST): cross-video pattern recognition, weekly upload optimization sweep, cohort comparisons, systematic topic gaps.
- Monthly strategic review (
30 4 5 * * UTC / Day 5 10:00 AM IST): strategic macro review, subscriber conversion compounding, back-catalogue packaging refreshes, evergreen vs decay analysis.
- Full catalogue pagination beyond 500 uploads: upload playlist discovery scans the entire catalogue with resumable pagination without artificial ceilings.
- Evidence-first diagnosis: evaluates views, watch time, average percentage viewed, subscriber conversion per 1,000 views, traffic sources, impressions, and impression CTR from the YouTube Reporting API. Missing metrics remain unavailable; uploads under 180 seconds stay unclassified and are excluded from peer-underperformance ranking and automatic metadata candidates until orientation can be confirmed.
- Gemini-first channel reasoning with explicit failover: daily, weekly and monthly Strategist runs try Gemini 3.6 Flash → Gemini 3.5 Flash-Lite → Gemini Flash-Lite Latest → Gemini 3 Flash Preview, in that exact order. Only after the Gemini chain is exhausted does the Strategist try Groq GPT-OSS 120B, then GPT-OSS 20B. Other app tasks and the batch metadata worker keep their separate Gemini-only defaults. Every accepted response must finish streaming and pass JSON/source-ID sanitization before any strategy decision is processed.
- Three Automation Modes:
- Paused: Scanning and briefings run; no proposals are published automatically.
- Shadow mode: Runs full analysis and proposal generation; logs
shadow_published records with before/proposed diffs without writing to YouTube.
- Autonomous mode: High-confidence updates ($\ge$ threshold, default 0.85) are automatically published and verified after passing cooldown and safety gates.
- Global Emergency Pause: Immediate toggle halts all autonomous writes across all cadences.
- Learning & Performance Feedback Loop: Evaluates published metadata changes at 7-day, 14-day, and 28-day observation windows against matched pre-change baselines, classifying outcomes into
improved, no_change, or declined. Empirical results feed back into Gemini prompts for future runs.
- Safe 1-Click Rollback: Allows restoring original pre-optimization metadata (
before_metadata) directly from the audit log with read-back verification.
Scheduled execution
| Job | UTC schedule | India time | Purpose |
|---|
| Daily metadata snapshots | 02:15 | 07:45 | Maintain seven-day change ledger for owner uploads |
| Daily channel strategist | 04:45 | 10:15 | Emerging underperformance scan, mature 28d comparison |
| Weekly channel strategist | 03:30 (Sun) | 09:00 (Sun) | Cross-video pattern recognition, weekly upload optimization sweep |
| Monthly channel strategist | 04:30 (Day 5) | 10:00 (Day 5) | Strategic macro review, subscriber conversion compounding, catalogue refresh |
| Batch metadata worker | Every 5 min | Every 5 min | Process manually submitted batch instructions and save proposals |
The daily, weekly and monthly Strategist workflows can also be started manually with GitHub Actions workflow_dispatch. Their required GitHub Actions repository secrets are SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, YOUTUBE_STRATEGIST_STATE_SECRET, and GEMINI_API_KEY. Add GROQ_API_KEY to enable the final Groq fallback stage; without it, the four-model Gemini chain still runs and deterministic analytics are retained if Gemini fails. DISCORD_WEBHOOK_URL enables Discord alerts.