Abdul F. Tirtayasa

Case study

Threads AI Content Operations Agent

A human-in-the-loop AI agent that plans, generates, reviews, illustrates, schedules, and publishes persona-aligned social content through Telegram and the official Threads Graph API.

Project context
Personal Project
Year
2026
Categories
AI Agent, Content Automation, Backend Development
Source code
View source code
Technology stack
Python, FastAPI, SQLAlchemy, APScheduler, Gemini, OpenAI-compatible APIs, OpenRouter, Telegram Bot API, Threads Graph API, SQLite, PostgreSQL, Pillow

System design

A public-safe view of the components, integrations, and data flow described in this case study.

Open diagram full size
System design diagram showing the architecture and workflow for Threads AI Content Operations Agent

Scroll horizontally to inspect the full diagram, or open it full size.

Problem

Managing a consistent social media presence involves more than generating text. Ideation, brand voice, safety review, visual production, approval, scheduling, and publishing are separate operational steps that can become repetitive and difficult to coordinate. The project addresses this by combining those steps into a controlled content pipeline while retaining human approval before publication.

Role

Abdul designed and built the project end to end, including: - Content-generation and persona prompt systems. - AI-assisted ideation, drafting, safety evaluation, and style evaluation. - Telegram-based operational controls and approval workflows. - Image and carousel generation pipelines. - Scheduled background jobs and persistent workflow state. - Threads text, image, carousel, and reply-chain publishing. - Failure handling, media regeneration, audit logging, and token refresh automation.

Architecture

The application uses FastAPI as its API and webhook layer, with SQLAlchemy providing persistent storage for ideas, drafts, generated media, workflow logs, and runtime configuration. The content pipeline consists of: 1. AI-assisted ideation with duplicate and backlog checks. 2. Persona-aligned draft generation using configurable writing strategies. 3. Independent safety and writing-style evaluations. 4. Human review through Telegram inline controls. 5. Optional text-only, single-image, or multi-slide carousel production. 6. A second approval stage for generated media. 7. FIFO publishing through the official Threads Graph API. 8. Scheduled execution through APScheduler. Generated assets are stored as static files. Approved carousels can also be converted into LinkedIn-ready PDF documents.

Implementation

The agent supports both scheduled operation and manual Telegram commands. Content strategies and schedules are stored in the database, allowing behavior to be changed without redeploying the application. Notable implementation details include: - Separate prompts for writing, safety, style, single-image planning, and carousel planning. - Duplicate-idea prevention using normalized topics and angles. - Backlog controls that avoid generating unnecessary content. - Persistent status transitions across ideas, drafts, media, and publishing. - Draft, individual slide, and complete media regeneration. - Automatic fallback to text-only publishing when media is rejected or fails. - Paragraph- and word-aware splitting for posts exceeding Threads limits. - Reply-chain publishing for longer content. - Retry and processing delays for Threads media containers. - Automatic watermarking and PDF generation with Pillow. - Configurable scheduled ideation, drafting, publishing, and access-token refresh jobs. - Audit records for generation, approval, regeneration, publishing, and failures.

Results

The project produced a working content operations pipeline that connects generative AI with human review and official publishing APIs. It demonstrates how an AI agent can move beyond standalone text generation by managing persistent workflow state, configurable content strategies, multimodal assets, operational approvals, scheduling, and publishing reliability.