An Agentic AI-based SEO Ranking System that accurately determines Google Places (Local) and Google Organic Search rankings for multiple keywords using SerpAPI and LangGraph.
The system dynamically adapts to Google's ranking behavior by selecting the correct Google surface (Maps, Local Finder, or Search), making it more reliable than traditional static scripts.
- ✅ Google Places (Local) ranking detection
- ✅ Google Organic Search ranking (Top 50 results)
- ✅ Hybrid Places logic (Google Maps → Local Finder fallback)
- ✅ Agentic architecture using LangGraph
- ✅ Excel-based input and output
- ✅ Deterministic, production-ready workflow
Google ranking behavior varies based on keyword intent:
- Brand keywords behave differently from category keywords
- Google Maps does not return results for all searches
- Local Finder and Maps are separate systems
This project solves the problem using an agentic execution model, where each agent has a single responsibility and execution is controlled through LangGraph.
Traditional Script (Non-Agentic)
1. Call Google Maps API
2. Parse response
3. Return result
4. Done
❌ Problem: Fails when Google Maps returns no results for certain keyword types
Agentic Approach (This Project)
1. Places Rank Agent decides strategy
2. Tries Google Maps
3. Agent evaluates result
4. If needed, agent switches to Local Finder
5. Agent matches and validates business
6. Returns confident result
✅ Solution: Agent adapts strategy based on results
Agents don't follow a rigid script. They make decisions based on:
- Whether Google Maps returned results
- Whether a business match was found
- Which ranking surface to query next
Example:
# Agentic Logic
if maps_results_empty:
agent_decides_to_try_local_finder()
else:
agent_processes_maps_results()This is not hardcoded branching—the agent evaluates state and chooses the next action.
Each agent has one clear job:
| Agent | Responsibility | Independence |
|---|---|---|
| Places Rank Agent | Determine Google Places rank using adaptive strategy | Can operate standalone |
| Search Rank Agent | Determine Google Search rank from organic results | Can operate standalone |
Agents don't interfere with each other. They work in parallel, and their results are merged in shared state.
LangGraph acts as the orchestration layer:
- Maintains shared state (current keyword, website, rankings)
- Routes execution flow between agents
- Ensures agents don't overwrite each other's results
- Allows conditional execution (e.g., retry logic)
State Flow:
Initial State: {keyword: "pizza", website: "example.com"}
↓
Places Agent adds: {google_rank: 3}
↓
Search Agent adds: {google_rank_1: 7}
↓
Final State: {keyword: "pizza", website: "example.com", google_rank: 3, google_rank_1: 7}
The system doesn't fail—it adapts:
Scenario 1: Brand keyword (e.g., "Starbucks near me")
- Google Maps returns results ✅
- Agent uses Maps data directly
Scenario 2: Generic keyword (e.g., "coffee shop")
- Google Maps returns empty []
- Agent automatically switches to Local Finder
- Finds results and ranks business
Scenario 3: Business not in top results
- Agent searches through all results
- Returns
NAif not found (honest failure)
This dynamic adaptation is core to agentic behavior.
Agents interact with external tools (SerpAPI) and make intelligent API calls:
- Google Maps API (
engine=google_maps) - Local Finder API (
engine=google,tbm=lcl) - Google Search API (
engine=google)
The agent chooses which tool to use based on context, not a fixed sequence.
Unlike traditional AI agents that might hallucinate, this system is:
- Deterministic: Same input → Same output
- Flexible: Adapts strategy based on API responses
- Reliable: Always returns a result (rank or
NA)
This balance makes it production-ready while maintaining agentic intelligence.
You could write this with if-else, but here's why the agentic approach is superior:
| Aspect | If-Else Script | Agentic System |
|---|---|---|
| Scalability | Hard to add new ranking sources | Easy to add new agents |
| Maintainability | Spaghetti code as logic grows | Modular, each agent is independent |
| State Management | Manual variable tracking | LangGraph handles state |
| Debugging | Hard to trace execution path | Clear agent → action → result flow |
| Testing | Test entire script | Test agents individually |
| Future AI Integration | Would require full rewrite | Can add LLM-based reasoning agents |
This foundation enables powerful future features:
-
Intent Detection Agent
- Uses LLM to classify keyword intent
- Routes to specialized ranking agents
-
Confidence Scoring Agent
- Evaluates ranking reliability
- Flags uncertain results for review
-
Explanation Agent
- Generates human-readable ranking insights
- "Your business ranks #3 because competitors have more reviews"
-
Recommendation Agent
- Suggests SEO improvements
- "Add business hours to improve Places ranking"
-
Multi-Agent Collaboration
- Agents negotiate which one should handle edge cases
- Voting system for ambiguous matches
This project is agentic because:
- ✅ Agents make autonomous decisions
- ✅ Each agent has clear responsibility
- ✅ State is managed centrally (LangGraph)
- ✅ System adapts to external conditions
- ✅ Architecture supports future AI enhancements
It's not just "AI-powered"—it's agent-based, which means the system thinks, adapts, and evolves rather than blindly executing steps.
- Places Rank Agent
- Determines Google Places ranking
- Uses hybrid logic (Maps → Local Finder)
- Search Rank Agent
- Determines Google Search ranking (organic links only)
- LangGraph manages execution order and shared state
- Each keyword is processed as an independent agentic flow
graph TD
A[Excel Input<br/>Keywords + Websites] --> B[LangGraph Orchestrator]
B --> C{For Each Keyword}
C --> D[Places Rank Agent]
C --> E[Search Rank Agent]
D --> F{Google Maps Query}
F -->|Results Found| G[Match Business]
F -->|No Results| H[Fallback: Local Finder]
H --> G
G -->|Match Found| I[Return Rank]
G -->|No Match| J[Return NA]
E --> K[Google Search Query<br/>Top 50 Results]
K --> L[Filter Organic Links]
L --> M[Match Domain]
M -->|Match Found| N[Return Position]
M -->|No Match| O[Return NA]
I --> P[Shared State]
J --> P
N --> P
O --> P
P --> Q{More Keywords?}
Q -->|Yes| C
Q -->|No| R[Excel Output<br/>Rankings Generated]
style B fill:#e1f5ff
style D fill:#fff4e1
style E fill:#fff4e1
style P fill:#e8f5e9
style R fill:#f3e5f5
- Query Google Maps (
engine=google_maps) - If no results are returned:
- Fallback to Google Local Finder (
engine=google,tbm=lcl)
- Fallback to Google Local Finder (
- Match business using:
- Business name
- Website domain
- Return rank or
NAif not found
This mirrors real Google Places behavior and avoids false negatives.
- Queries Google Search using SerpAPI
- Fetches up to top 50 organic results
- Ignores ads and sponsored listings
- Matches target website domain
- Returns exact ranking position or
NA
This logic remains independent of Google Places ranking.
| Column | Description |
|---|---|
| sn | Serial number |
| Keyword | Search keyword |
| Website | Website URL to check ranking |
| Column | Description |
|---|---|
| google rank | Google Places rank |
| google rank-1 | Google Search rank |
- Python
- LangGraph (Agent orchestration)
- SerpAPI (Google data source)
- Pandas (Excel processing)
- dotenv (Environment variable management)
pip install pandas serpapi python-dotenv langgraphCreate a .env file:
SERPAPI_API_KEY=your_serpapi_key_herepython agentic_ranking.pyEnsure the input Excel file is named:
Ranking_Website.xlsx
The output file will be generated as:
Agentic_Ranking_Website_Results.xlsx
- Google ranking is intent-based, not static
- A single API strategy does not work for all keywords
- Agentic orchestration improves reliability and scalability
- Hybrid logic is essential for accurate Places ranking
- Dependent on SerpAPI rate limits
- Rankings may vary by location and time
- Google algorithm changes may affect results
- Intent Detection Agent
- Ranking explanation & reason generation
- Confidence scoring for ranks
- LLM-based SEO recommendations
- API or dashboard-based interface
The Agentic SEO Rank Analyzer demonstrates how agent-based systems can handle real-world SEO complexity by dynamically adapting to platform behavior while remaining modular, scalable, and production-ready.
- 📧 Email: harshitwaldia112@gmail.com
- 🐦 Twitter: @HarshitWaldia
- 💼 LinkedIn: Harshit Waldia
- ⚙️ GitHub: @HarshitWaldia
If you find this project helpful, please consider giving it a star! ⭐
Harshit Waldia
Ahaṁ Brahmāsmi | अहं ब्रह्मास्मि
The true self is not the body but an eternal, infinite part of the universe