PROJECT CASE STUDY

An AI Agent That Runs LinkedIn — On Its Own

LinkedIn AI Agent researches AI & business news, writes original posts in a personal voice, publishes them automatically four times a day, tracks performance, and learns from engagement data to keep getting better — all running for free on GitHub Actions.

Built for Abdul Rauf Agha (AI Agent | AI Automation | Data Engineering | Business Intelligence) to maintain a consistent, high-quality LinkedIn presence without manual effort.

What Is This System?
A fully automated content pipeline that thinks, writes, publishes, measures, and improves itself.
📰

Research

Aggregates the latest AI & business news from Google News, HackerNews, Reddit, VentureBeat, and TechCrunch — filtered to stay strictly on-topic.

✍️

Write

Uses Gemini 2.0 Flash (with a GLM-4 fallback) to write a completely original LinkedIn post in a consistent first-person persona.

🚀

Publish

Posts directly to LinkedIn via the official API v2 — text-only or with a relevant real image, four times a day.

📊

Learn

Tracks likes & comments on every post, then feeds those insights back into future posts to double down on what works.

🛠️

Self-Heal

If anything breaks, an AI sub-agent (DeepSeek V3) reads the error logs, fixes the source code, and pushes the patch automatically.

💸

Zero Cost

Runs entirely on free tiers — GitHub Actions, Gemini free tier, Reddit API, Pexels, and Google Custom Search free quota.

Purpose
Why this exists

📈 Daily Presence

Maintain a daily LinkedIn presence (4 posts/day) without spending time writing content.

🧠 Brand Authority

Build personal brand authority around AI Agents, AI Automation, Data Engineering, and Business Intelligence for business owners, CTOs, and operations leaders.

🔁 Always Fresh

Avoid repetitive content by tracking recent posts and steering away from duplicate news angles.

📊 Self-Improving

Continuously improve post quality and topic selection using real engagement data instead of guesswork.

How It Works — The Pipeline
Every time the agent runs, it automatically goes through these steps from start to finish.
1

Validate Configuration

Checks that LinkedIn tokens and at least one AI provider key are present before doing any work.

2

Fetch the Latest News

Gathers the latest AI and business news from several trusted sources, filters out anything off-topic, removes duplicates, and keeps a backup copy in case a source is temporarily down.

3

Review What Worked Before

Looks back at how previous posts performed (likes and comments) and figures out which topics, post styles, and hashtags got the best response.

4

Write the Post

Combines the news, the lessons from past posts, and the writing style guide, then asks the AI to write a fresh, original post — checking it for quality and trying again if needed until it's ready to publish.

5

Find a Matching Image (Optional)

For some posts, searches for a relevant, real photo to go along with the text — and only uses a fitting one if it can find it.

6

Publish to LinkedIn

Logs in securely, attaches the image if there is one, and publishes the finished post directly to the LinkedIn profile — automatically retrying if LinkedIn is briefly busy.

7

Save the Post Details

Adds a record of the new post — its text, hashtags, and source — to its post history log, so it can be reviewed and learned from later.

8

Save the Updated History

Saves the updated post history so the records carry over and aren't lost between runs.

9

Auto-Fix Agent

Runs no matter what happens above. If something went wrong, a separate AI agent reads the error, figures out the fix, and corrects the code automatically — no developer needed.

Posting Schedule
The agent runs automatically on this schedule every day (times shown in Pakistan Standard Time).
Time (PKT)UTCJobDescription
10:00 AM05:00scrape-and-postGenerate + publish post (image-eligible)
02:00 PM09:00scrape-and-postGenerate + publish post (text-only)
05:00 PM12:00scrape-and-postGenerate + publish post (image-eligible)
09:00 PM16:00scrape-and-postGenerate + publish post (text-only)
11:00 PM18:00update-engagementFetch likes/comments for all posts
Features
What it delivers — for the business and under the hood
Non-Technical / Business Features

🤖 Fully autonomous LinkedIn presence — no manual writing or scheduling

🎯 On-brand, consistent first-person voice across every post

♻️ Always fresh — avoids repeating news stories (2 days) or post angles (7 days)

🚫 Topic guardrails — automatically avoids off-brand ML/Deep Learning content

📈 Self-improving content strategy based on real engagement data

🖼️ Relevant visuals automatically attached to select posts

🗂️ Full performance history of every post ever published

🔧 Self-healing automation — fixes its own bugs in production

💰 Zero ongoing operating cost (free-tier APIs only)

Technical Features

🔗 Multi-Source News Aggregation

Relevance scoring, include/exclude keyword filters, deduplication, and a 24h JSON cache fallback across 5 news sources.

🧩 AI Provider Fallback Chain

Gemini 2.0 Flash → GLM-4 Flash → deterministic rule-based template, guaranteeing a post is always produced.

📐 Prompt Engineering via Skill File

Persona, tone, post formats, hashtag pool, and a quality checklist live in one Markdown file injected as the system prompt.

🧮 Engagement-Driven Prompting

Weighted score (likes + comments × 3) drives top/bottom topic detection, best format, top hashtags, and best sources.

🛡️ Content Safety Checks

Rejects outputs with excluded keywords or near-duplicate openings vs. recent posts, with automatic regeneration.

🔌 Official LinkedIn API v2

OAuth2 token refresh on 401, full 3-step image upload flow, retry/backoff on 429 rate limits.

🖼️ Curated Image Sourcing

Allow-list of trusted domains and a block-list of AI-art generator sites, with size/format validation.

📊 Engagement Metrics Collection

3-tier LinkedIn API fallback (socialActions → shares → ugcPosts) to maximize data availability.

🗃️ CSV-Based Persistence

Tracks date, time, post preview, hashtags, post ID, generation method, news source/title, status, likes, and comments.

🤝 Self-Healing CI/CD

Parses failed Actions logs, sends Python tracebacks to DeepSeek V3 for a corrected file, and auto-commits the fix.

☁️ Cloud/Local Detection

Same codebase runs identically on a developer machine and in GitHub Actions, with cloud-only auto-commit of post history.

🪟 Cross-Platform Safe

UTF-8 console reconfiguration ensures clean output on Windows as well as Linux runners.

Tech Stack & Tools
Languages, AI providers, APIs, libraries, and infrastructure
Languages & Runtime
Python 3.11
AI / LLM Providers
Google Gemini 2.0 Flash — primary content generation Zhipu AI GLM-4 Flash — fallback content generation DeepSeek V3 — automated error fixing HuggingFace FLUX.1-schnell — optional AI image generation
External APIs & Data Sources
LinkedIn API v2 Google News RSS HackerNews Firebase API Reddit API (PRAW) VentureBeat RSS TechCrunch AI RSS Pexels API Google Custom Search API
Python Libraries
python-dotenv requests pandas feedparser praw google-generativeai zhipuai Pillow python-docx python-dateutil urllib3
Automation & Infrastructure
GitHub Actions (cron scheduling) GitHub Secrets Git (programmatic commits) GitHub CLI (gh)
Project Structure
A look inside the repository
LinkedIn-AI-Agent/ ├── .claude/skills/ │ └── writing-linkedin-posts.md # Persona, tone, post formats, hashtags, quality checklist ├── .github/workflows/ │ └── linkedin-automation.yml # Cron schedules + 3 jobs (post, auto-fix, engagement) ├── data/ │ ├── post_history.csv # Every published post + engagement metrics │ └── news_cache.json # 24h cache of fetched news (fallback) ├── scripts/ │ └── generate_token.py # One-time LinkedIn OAuth token generator ├── src/ │ ├── config.py # Configuration, API keys, persona, keyword lists │ ├── main.py # Pipeline orchestrator (entry point) │ ├── news_fetcher.py # Multi-source news aggregation + filtering │ ├── engagement_analyzer.py # "What works" intelligence from post history │ ├── post_generator.py # AI post generation (Gemini → GLM → rule-based) │ ├── image_finder.py # Image search/generation (Pexels/HF/Google) │ ├── linkedin_publisher.py # LinkedIn API v2 publishing + OAuth │ ├── post_tracker.py # Reads/writes post_history.csv │ ├── engagement_tracker.py # Fetches likes/comments for past posts │ └── error_fixer.py # AI-driven auto-fix sub-agent (DeepSeek V3) ├── tests/ │ └── test_agent.py # Test suite / report generation ├── .env.template # Required environment variables template └── requirements.txt
The Persona Behind the Posts
PERSONA PROFILE

Abdul Rauf Agha — AI Agent | AI Automation | Data Engineering | Business Intelligence

Helps businesses grow by leveraging AI agents and data automation. Audience: business owners, CTOs, operations managers, and decision-makers. Tone: authoritative, approachable, practical, forward-thinking, first-person.

Covers: AI Agents, AI Automation, Business Intelligence, Claude/Anthropic, Gemini/Google AI, OpenAI/ChatGPT, Chinese AI (DeepSeek/Qwen), vibe coding, agentic development.

Never covers: Machine Learning theory, Predictive Analytics, Neural Networks, Deep Learning.