Overview
The Instagram agent extracts profile information and posts from Instagram using Browser Use Cloud SDK skills (primary) with browser-use Agent fallback for Google-first scraping.Implementation
backend/agents/instagram_agent.py
Architecture Decision
backend/agents/instagram_agent.py
- Marketplace skill handles Instagram’s anti-bot measures
- Deterministic results (~$0.01/run, 20-30s)
- No account bans or IP blocks
- Structured output parsing
- Risk of account bans
- Requires managing Instagram sessions
- More complex setup and maintenance
Two-Tier Approach
async def _run_task(self, request: ResearchRequest) -> AgentResult:
# Try Cloud SDK skill first (faster, more reliable)
if self._cloud.configured:
cloud_result = await self._try_cloud_skill(request)
if (
cloud_result
and cloud_result.status == AgentStatus.SUCCESS
and cloud_result.profiles
):
return cloud_result
# Fallback to Google-scraping via browser-use Agent
return await self._try_browser_use(request)
async def _try_cloud_skill(self, request: ResearchRequest) -> AgentResult | None:
"""Try the Instagram Profile Posts marketplace skill."""
query = self._build_search_query(request)
task = (
f"Search for Instagram profile of {query} and extract profile info "
f"including username, bio, followers, following, and post count."
)
try:
result = await self._cloud.run_skill(
"instagram_posts",
task,
timeout=60.0,
)
if not result or not result.get("success"):
logger.info("instagram cloud skill returned no result, falling back")
return None
output = result.get("output", "")
parsed = _parse_instagram_output(output, request.person_name)
return AgentResult(
agent_name=self.agent_name,
status=AgentStatus.SUCCESS,
profiles=[parsed["profile"]],
snippets=parsed["snippets"],
urls_found=[parsed["profile"].url] if parsed["profile"].url else [],
)
except Exception as exc:
logger.warning("instagram cloud skill error: {}", str(exc))
return None
async def _try_browser_use(self, request: ResearchRequest) -> AgentResult:
"""Fallback: Google-first scraping via browser-use Agent."""
if not self.configured:
return AgentResult(
agent_name=self.agent_name,
status=AgentStatus.FAILED,
error="Browser Use not configured (BROWSER_USE_API_KEY or OPENAI_API_KEY missing)",
)
query = self._build_search_query(request)
logger.info("instagram agent (fallback) searching: {}", query)
try:
task = (
"Go to https://www.google.com/search"
f"?q={query.replace(' ', '+')}+site:instagram.com "
f"and use the extract tool to get this JSON from the Google results:\n"
f'{{"username": "", "display_name": "", "bio": "", '
f'"followers": 0, "following": 0, "post_count": 0, '
f'"profile_url": ""}}\n'
f"Extract from Google snippets. Do NOT click into Instagram. Do NOT scroll. "
f"After extracting, immediately call done with the JSON result."
)
agent = self._create_browser_agent(task, max_steps=3)
result = await agent.run()
final_result = result.final_result() if result else None
if final_result:
parsed = _parse_instagram_output(str(final_result), request.person_name)
return AgentResult(
agent_name=self.agent_name,
status=AgentStatus.SUCCESS,
profiles=[parsed["profile"]],
snippets=parsed["snippets"],
urls_found=[parsed["profile"].url] if parsed["profile"].url else [],
)
return AgentResult(
agent_name=self.agent_name,
status=AgentStatus.SUCCESS,
snippets=["No Instagram profile found"],
)
except Exception as exc:
logger.error("instagram agent error: {}", str(exc))
return AgentResult(
agent_name=self.agent_name,
status=AgentStatus.FAILED,
error=f"Instagram agent error: {exc}",
)
Output Parsing
JSON Extraction
backend/agents/instagram_agent.py
Profile Parsing
backend/agents/instagram_agent.py
Extracted Data
The Instagram agent extracts:- Profile Info: Username, display name, bio
- Metrics: Followers, following, post count
- Verification: Blue checkmark status
- Privacy: Whether account is private
- Recent Posts: Latest post captions and media
- Profile URL: Direct link to Instagram profile
Usage Example
Performance
Cloud SDK Path
- Duration: 20-30s typical
- Cost: $0.01 per run
- Success Rate: ~80%
- Data Quality: High (direct Instagram extraction)
Browser-Use Fallback
- Duration: 5-10s (Google snippets only)
- Cost: Browser Use API usage
- Success Rate: ~50%
- Data Quality: Medium (summary from Google knowledge panel)
Handling Private Accounts
Troubleshooting
Cloud Skill Failing
Empty Results
Timeout Issues
Post Count Parsing
Private vs Public Profiles
Advanced Usage
Extracting Recent Posts
Checking Verification Status
Follower Growth Analysis
Next Steps
Twitter Agent
Twitter/X profile scraping with twscrape
Google Agent
Google search-based intelligence gathering
Browser Use Integration
Deep dive into Cloud SDK skills
Agent Overview
Full agent system architecture