AI Agent Documentation
AI Agent Documentation
Section titled “AI Agent Documentation”This directory contains documentation specifically designed for AI agents and developers building AI-powered shopping assistants.
Contents
Section titled “Contents”- MCP_TOOLS.md - Complete reference for all 29 MCP tools available
- GRAPH_SCHEMA.md - Neo4j graph schema and relationships
- DEMO_USERS.md - Pre-configured demo user profiles for testing
- EXAMPLE_QUERIES.md - Common use cases and tool combinations
Quick Reference
Section titled “Quick Reference”Core Capabilities
Section titled “Core Capabilities”The Consumer Graph MCP provides 29 tools across these categories:
-
Product Discovery (8 tools)
- Search products, discover new items, find alternatives
- Product details, similarities, and brand discovery
-
Offer Management (4 tools)
- Active offers, retailer offers, offer search
- Product-to-offer matching and optimization
-
User Context (9 tools)
- Purchase history, patterns, and timeline
- Brand/category/retailer preferences
- Location and household context
-
Recommendations (4 tools)
- Collaborative filtering
- Similar products
- Community insights
- New product discovery
-
Analytics (4 tools)
- Spending patterns
- Category expansion prediction
- Repurchase prediction
- Local trending
Getting Started
Section titled “Getting Started”1. Test MCP Endpoint
Section titled “1. Test MCP Endpoint”curl http://localhost:8081/mcp \ -H "Content-Type: application/json" \ -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'Expected output: List of 29 available tools
2. Test with Demo User
Section titled “2. Test with Demo User”curl http://localhost:8081/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "get_user_purchase_history", "arguments": {"user_id": "DEMO_USER_HEALTH", "limit": 5} }, "id": 2 }'3. Integrate with Your Agent
Section titled “3. Integrate with Your Agent”The MCP tools are designed to be called via OpenAI’s native MCP support:
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create( model="gpt-4o", messages=[{ "role": "user", "content": "What products does DEMO_USER_HEALTH usually buy?" }], tools=[{ "type": "function", "function": { "name": "get_user_purchase_history", "description": "Get user's purchase history", "parameters": { "type": "object", "properties": { "user_id": {"type": "string"}, "limit": {"type": "number"} }, "required": ["user_id"] } } }])Key Concepts
Section titled “Key Concepts”Graph-Based Shopping Intelligence
Section titled “Graph-Based Shopping Intelligence”The system uses a Neo4j knowledge graph to model:
- Users and their shopping behaviors
- Products with attributes, categories, and similarities
- Offers with eligibility rules and point values
- Retailers and venue types
- Communities of similar shoppers
- Categories for product organization
- Households for shared shopping context
Relationship Types
Section titled “Relationship Types”PURCHASED- User bought productHAS_OFFER- Offer applies to product/brand/categoryELIGIBLE_FOR- User can redeem offerSIMILAR_TO- Products with similarity scoresMEMBER_OF- User in household or communitySHOPS_AT- User prefers retailerIN_CATEGORY- Product belongs to category
Optimization Patterns
Section titled “Optimization Patterns”The graph uses intermediary nodes (Community, Category) to reduce edge complexity:
- Before: 2,182 edges (direct user-to-product)
- After: 662 edges (user-to-community-to-product)
- Result: 70% reduction, faster queries, better scalability
Common Patterns
Section titled “Common Patterns”Pattern 1: Personalized Recommendations
Section titled “Pattern 1: Personalized Recommendations”1. get_user_purchase_history (understand past behavior)2. get_community_insights (what similar users like)3. discover_new_products (filtered by preferences)Pattern 2: Offer-Driven Shopping
Section titled “Pattern 2: Offer-Driven Shopping”1. get_active_offers (eligible offers for user)2. match_products_to_offers (find products with offers)3. optimize_offer_activation (maximize points)Pattern 3: Context-Aware Search
Section titled “Pattern 3: Context-Aware Search”1. get_user_location_context (understand location)2. search_products (find relevant items)3. get_local_trending (see what's popular nearby)Demo Users
Section titled “Demo Users”Six pre-configured users with distinct profiles:
DEMO_USER_HEALTH- Health-conscious, organic preferencesDEMO_USER_FAMILY- Budget-conscious family, bulk buyerDEMO_USER_SINGLE- Convenience-oriented, small portionsDEMO_USER_FOODIE- Specialty items, adventurousDEMO_USER_TRADITIONAL- Mainstream brands, weekly routineDEMO_USER_ECO- Sustainable, ethical brands
See DEMO_USERS.md for detailed profiles.
Data Volumes
Section titled “Data Volumes”The demo dataset includes:
- Users: 6 demo users + 120+ similar users
- Products: 135+ products across 10 categories
- Offers: 120+ offers with various point values
- Retailers: 8 retailers (grocery, drugstore, warehouse, specialty)
- Communities: 45 shopping communities
- Categories: 47 product categories
Best Practices
Section titled “Best Practices”For AI Agents
Section titled “For AI Agents”- Always use user_id - Most tools require user context for personalization
- Leverage similarities - Use
find_similar_productsfor explainable recommendations - Check community - Use
get_community_insightsfor social proof - Combine tools - Multi-tool workflows provide richer context
- Handle empty results - Not all users have data in all categories
For Developers
Section titled “For Developers”- Start with demo users - Use DEMO_USER_* for testing before production
- Test edge cases - Try users with no purchase history, no offers, etc.
- Monitor performance - Tools include query performance metadata
- Validate inputs - Required parameters will return errors if missing
- Use limits wisely - Default limits balance completeness and performance
Troubleshooting
Section titled “Troubleshooting”No tools available
Section titled “No tools available”Check that:
- Neo4j is running (port 7687)
- Data is loaded (run
./scripts/setup-neo4j.sh) - MCP HTTP server is running (port 8081)
Empty results
Section titled “Empty results”Check that:
- User ID exists in database
- User has purchase history
- Offers have correct date ranges (active offers)
Slow queries
Section titled “Slow queries”Check that:
- Community/Category nodes are created (optimization)
- Indexes exist on frequently queried properties
- Limit parameters are set appropriately
Support
Section titled “Support”For issues or questions:
- Check existing documentation in this directory
- Review example queries in EXAMPLE_QUERIES.md
- Inspect graph directly via Neo4j Browser (http://localhost:7474)