Social Media Automation

How to Build a Social Media AI Agent (With the Exact Prompt to Copy)

NasBy NasPublished 10 min read
Social media AI agent ranking top Instagram posts and logging new content ideas to a Google Sheet
On this page

Most social media advice tells you to "post consistently" and "know your audience.", but what it doesn't tell you is how to find the patterns inside your own account that actually predict what performs, and how to use those patterns to systematically generate content ideas that are more likely to work.

That's what this agent does. It scrapes your own Instagram posts, ranks them by performance, extracts the hooks and topics from your top performers, generates 10 new content ideas modeled on those winners, and logs everything to a Google Sheet, without you touching a single spreadsheet. And yes, of course you can also run the same Agent to look at your competitors' or inspiring creators' accounts.

TL;DR

  • The agent scrapes your last 40 Instagram posts using Apify
  • Ranks them by views, then engagement rate, and identifies your top ~10 performers
  • Extracts the hooks and topics that keep appearing in your best content
  • Generates 10 new ideas, each with a ready-to-use hook and reasoning
  • Writes everything to a Google Sheet, deduplicating against existing rows
  • Works with Claude (Pro or API) using Apify and Google Sheets integrations

What a Social Media AI Agent Actually Does

A social media AI agent is different from asking ChatGPT to "write me 5 Instagram captions." The difference is data it uses, because instead of generating generic content based on what it was trained on, this agent starts from your specific account: your actual posts, your actual performance numbers, your actual audience's reactions.

The result is content ideas that are modeled on what has demonstrably worked for you, not what works for some average creator in your niche. Your top performers become the training set for your next batch of content, meaning the likelihood of better engagement is higher.

It also builds institutional knowledge. Every time the agent runs, your Google Sheet grows: your winning patterns get documented, your top hooks get archived, and new ideas get logged alongside the reasoning behind them. Over time, you end up with a living content strategy document that gets smarter every week.

What You Need to Set It Up

Claude Pro or API access

The agent uses Claude with tool use enabled. Claude Pro works if you connect the Apify and Google Sheets MCP integrations. API access works if you're building a more automated setup.

An Apify account

Apify runs the Instagram scraper. They have a free tier ($5/month of compute credit) which covers many runs. The Instagram scraper actor is pre-built; you don't need to configure anything beyond the input fields the prompt specifies.

A Google Sheet

Create a new spreadsheet and add a tab called "Content Analysis." The agent will create three blocks inside it: Top Performers, Winning Patterns, and New Ideas. Copy the Sheet ID from the URL (the long string between /d/ and /edit).

Your Instagram handle

Your public Instagram username. The account needs to be public for the scraper to access it. If your account is private, you'll need to use Apify's authenticated scraping options.

How the Agent Works: Step by Step

Step 1: Scrape your posts

The agent calls the Apify Instagram scraper with your handle and pulls your last 40 posts. For each post it retrieves the caption, post URL, publish date, view count, like count, and comment count. Reels and videos take priority in the analysis since they typically carry more distributable reach than static images.

Step 2: Rank and analyze

Posts are ranked by views first (reach), then by engagement rate, calculated as (likes + comments) / views. This two-tier ranking separates posts that were broadly distributed from those that generated genuine audience interaction. The top ~10 performers become the analysis set.

For each top performer, the agent extracts the hook: the first line or first ~10 words of the caption. It can't see the video itself, but the hook is usually the most influential variable anyway as it's what determines whether someone stops scrolling. Patterns across hooks are identified: questions, numbers, "how to" frames, bold claims, contrarian angles.

Step 3: Generate 10 new ideas

Using the winning patterns as a template, the agent generates 10 new content ideas. Each idea comes with a ready-to-use hook (written in the style of your top performers), the topic and angle, and a one-line explanation of which winning pattern it echoes and why it should work. These aren't generic suggestions; they're modeled on what your specific audience has responded to.

Step 4: Log to Google Sheets

The agent reads your existing Sheet first (Batch Get) to avoid duplicating posts already logged. It then writes three structured blocks: Top Performers (one row per post with all performance data), Winning Patterns (the recurring hooks and topics), and New Ideas (the 10 new ideas with hooks and reasoning). The Sheet becomes your running content strategy document.

The Prompt

Paste this directly into your AI Agent orchestration interface, whether it's Talk to Me Data or Claude Project. Before running, replace [YOUR_HANDLE] with your Instagram username and [YOUR_SHEET_ID] with the ID from your Google Sheet URL. Make sure your Apify and Google Sheets integrations are connected in Claude's settings.

Agent Prompt
You analyze the user's own Instagram content, surface what works, and propose new ideas modeled on the top performers. Run once per request.

STEP 1 - SCRAPE
Use the Apify action "Run Actor Sync & Get Dataset Items":
- actor: apify/instagram-scraper
- input: { "directUrls": ["https://www.instagram.com/[YOUR_HANDLE]/"], "resultsType": "posts", "resultsLimit": 40 }
(Confirm the field names against the actor's Input tab.)

STEP 2 - ANALYZE (focus on reels/videos)
- Rank posts by performance: views first, then engagement rate ((likes + comments) / views).
- Identify the TOP ~10 performers.
- Best hooks: extract the first line / first ~10 words of each top post's caption - this is the textual hook (you cannot see the video). Note recurring patterns: questions, numbers, bold claims, "how to", contrarian takes, etc.
- Best topics/formats: the themes and formats that appear most among the top performers.

STEP 3 - GENERATE IDEAS
Propose 10 new content ideas modeled on the winners. For each: a ready-to-use hook written in the style of your top performers + the topic/angle + one line on why it should work (which winning pattern it echoes).

STEP 4 - WRITE TO SHEET (spreadsheet [YOUR_SHEET_ID], tab "Content Analysis")
- Block A "Top Performers": one row per top post — Date, URL, Topic, Hook, Views, Likes, Comments, Engagement Rate.
- Block B "Winning Patterns": the recurring hook styles + topics.
- Block C "New Ideas": the 10 ideas — Hook, Topic/Angle, Why it works.
Read existing rows first (Batch Get) and don't duplicate posts already logged.

Finish with a short chat summary: the top 3 hooks and your 3 strongest new ideas.

How to Connect the Integrations

Apify

  1. Create a free account at apify.com
  2. Go to Settings → Integrations and copy your API token
  3. In Claude, go to Settings → Integrations → Apify and paste the token
  4. The agent will then be able to call the Instagram scraper actor directly

Google Sheets

  1. In Claude, go to Settings → Integrations → Google Drive / Sheets and authorize your Google account
  2. Create a new Google Sheet and add a tab named exactly "Content Analysis"
  3. Copy the Sheet ID from the URL: it's the string between /d/ and /edit
  4. Replace [YOUR_SHEET_ID] in the prompt with that value

What You Get Out of It

OutputWhereWhat it contains
Top PerformersSheet, Block ADate, URL, Hook, Views, Likes, Comments, Engagement Rate
Winning PatternsSheet, Block BRecurring hook styles, topic categories, format types
New Content IdeasSheet, Block C10 hooks, topics, and reasoning for each idea
Chat SummaryClaude replyTop 3 hooks + 3 strongest new ideas at a glance

Tips for Customising the Prompt

Change the platform

Apify has scrapers for TikTok, LinkedIn, YouTube, and most other platforms. Swap the actor ID in Step 1 and adjust field names in Steps 2 and 4 to match what each scraper returns.

Increase the post sample

Change "resultsLimit": 40 to 80 or 100 for a larger sample. More data means more reliable pattern detection, though it increases processing time slightly.

Add competitor analysis

Add a second scrape call in Step 1 with a competitor's handle. In Step 2, instruct the agent to compare their top performers against yours and identify gaps: topics they're winning on that you haven't covered.

Generate more ideas

Change "Propose 10 new content ideas" in Step 3 to 20 or 30. You'll get a larger bank to pull from when planning your content calendar.

Automate it on a schedule

Using the Claude API, you can wrap this in a cron job that runs every Sunday night so your Sheet updates automatically. The deduplication logic in Step 4 ensures you never log the same post twice. If you'd rather skip the infrastructure entirely, Talk to Me Data handles the scheduling, hosting, and monitoring for you.

Summary

A social media AI agent shifts content strategy from guesswork to data. Instead of generating ideas based on vague intuition about what your audience likes, you start from performance evidence (your actual top posts) and work outward from there.

The agent handles the tedious parts: pulling data, ranking posts, identifying hook patterns, generating ideas, and logging everything to a Sheet. You get a structured, up-to-date content strategy document every time you run it, and a batch of ready-to-use hooks that are grounded in what's actually worked on your account.

The prompt above is ready to use. Replace the two placeholders, make sure your integrations are connected, and run it. The first time you see your own patterns laid out in a Sheet, it's genuinely surprising how clear the signal is.

Frequently Asked Questions

Does this work for accounts with a small following?

Yes. The agent analyzes relative performance within your own account, so it will be comparing your posts against each other, not against industry benchmarks. Even with a few hundred followers, it surfaces meaningful patterns from your last 40 posts.

Can I use this for TikTok or LinkedIn instead of Instagram?

The prompt as written uses Apify's Instagram scraper. Apify has scrapers for TikTok, LinkedIn, and most other major platforms, so you can swap the actor ID and input fields in Step 1, and adjust the field names in Steps 2 and 4 to match the data structure each scraper returns.

Can Talk to Me Data build this Agent for me?

Absolutely. We can build it for you so you don't have to worry about Claude API credits, API Keys, Apify and Google Sheets integrations etc. Just book a Demo and we will get you onboarded onto the platform.

Is the Apify Instagram scraper free?

Apify offers a free tier with $5 of monthly compute credit. Scraping 40 posts typically uses a fraction of that. For regular use (running the agent weekly), a paid plan is more practical.

What if Claude can't see the video content?

The agent explicitly works around this as it analyzes captions, hooks (first ~10 words), engagement metrics, and topics rather than the visual content. In practice, caption hooks are often the primary driver of performance anyway, so this limitation rarely matters.

How often should I run this agent?

Once a week is a reasonable cadence for most accounts. The agent reads existing rows from the Sheet before writing, so it won't duplicate posts already logged. Running it weekly keeps your pattern analysis fresh as new posts accumulate.
Done for youThe Social Media AI Agent: built and hosted for you

Keep reading

All Social Media Automation guides