Graph Analytics Agent Guide¶
Blend Graph Data Science algorithms into the regular GraphRAG chat workflow by enabling the Graph Analytics Agent. Content below distills the legacy GRAPH_ANALYTICS_GUIDE.md.
Overview¶
The agent extends text-to-Cypher with analytics such as community detection, influence ranking, and bridge analysis. Routing happens automatically based on user intent; when no analytics tool fits, the request falls back to standard Cypher generation.
Enable the Agent¶
- Install the Neo4j GDS Agent (
pip install gds-agent) or run it as a remote MCP server. - Populate
.envwith the same credentials the GDS Agent expects:NEO4J_URI,NEO4J_USER,NEO4J_PASSWORD, optionalNEO4J_DATABASE. - Set
ENABLE_ANALYTICS_AGENT=trueand restart the backend. - Verify connectivity by running
python ai/mcp_client.py --interactiveand listing tools.
Available Tools¶
| Tool | Purpose | Example Prompts |
|---|---|---|
article_rank |
Ranks nodes by influence using ArticleRank | “Which influencers are most important?”, “Show me the top creators by ArticleRank score.” |
leiden |
Detects communities/clusters via the Leiden algorithm | “Find communities of people who follow similar influencers.” |
bridges |
Surfaces critical edges whose removal disconnects the graph | “Which connections are essential for linking neighborhoods?” |
count_nodes |
Provides dataset size statistics | “How many people, influencers, and areas are there?” |
Each capability lives in ai/agent/graph_analytics_agent.py. Inputs such as nodeLabels, relTypes, nodeIdentifierProperty, or algorithm-specific knobs (e.g., minCommunitySize) are inferred from natural language, but you can override them explicitly:
await analytics_agent.run(
"Find person communities",
tool_name="leiden",
inputs={"nodeLabels": ["Person"], "relTypes": ["FOLLOWS"], "minCommunitySize": 10},
)
Routing Logic¶
- Chat API receives a user question.
- Intent classifier (LLM-based with keyword fallback) checks for analytics cues (communities, influence, bridges, graph size).
- If matched, the backend calls the MCP client, executes the tool, and summarizes the results.
- Frontend progress cards tell the user which route ran (analytics vs. text-to-Cypher).
Regular Cypher queries still handle counts, aggregations, or lookups that do not require heavy analytics.
Integration Points¶
- Backend –
backend/app/api/chat.pywires routing throughservices/graphrag.py, which instantiates the agent once and reuses it per request. - Frontend – no UX changes required; messages flow through the same UI, but analytics-specific metadata is displayed to set expectations.
Troubleshooting¶
- Tool not found: ensure the GDS Agent exposes it (
python ai/mcp_client.py --interactive --list-tools). - Credentials rejected: confirm TLS-enabled URIs for Aura (
neo4j+s://...). - Slow responses: monitor Langfuse traces when algorithms traverse large graphs; consider raising timeouts or narrowing parameters.
- Fallback triggered: set
DEBUG_PROMPT=trueand inspect routing prompts/logs to understand why the LLM avoided analytics.
Future Tools¶
The agent reads MCP metadata to discover new tools automatically. To add one:
- Define a
ToolConfigin_build_default_configs(). - Implement a custom summary builder.
- Regenerate docs to capture the new capability.
Potential additions include shortest_path, betweenness_centrality, pagerank, and connected_components.