Skip to content

Tools Organization Structure

This document describes the organization of the 20 graph query tools for AI agent access.

  1. Shared Parameters: Common filter structures are defined once in internal/models/tools/common.go
  2. Category-based Files: Tools are organized into 8 category files
  3. Consistent Naming: All requests end with Request, responses with Response
  4. Composable Filters: Tools embed common filter structs for consistency
  5. Embedded Defaults: Each request has a SetDefaults() method
internal/models/tools/
├── common.go # Shared parameter structures
├── user_context.go # User Context Tools (5 tools)
├── products.go # Product Discovery Tools (3 tools)
├── temporal.go # Temporal Tools (2 tools)
├── offers.go # Offer Tools (3 tools)
├── brands.go # Brand Tools (3 tools)
├── retailers.go # Retailer Tools (2 tools)
├── collaborative.go # Collaborative Tools (2 tools)
└── composition.go # Composition Tool (1 tool)

Defined in internal/models/tools/common.go:

StructureFieldsUsed By
UserFilteruser_idALL 20 tools (required)
TimeFilterlookback_days, as_of12 tools
CategoryFiltercategory, categories13 tools
BrandFilterbrand, brands9 tools
ProductFilterEmbeds Category + Brand + name_pattern3 tools
RetailerFilterretailer_id3 tools
PaginationParamslimit, offset18 tools
SimilarityParamsmin_similarity, max_similar3 tools
OfferFiltermin_points, search_term1 tool
RepurchaseParamsmin_intervals, prediction_window, min_days1 tool
CollaborativeParamssame_zip_only, min_shared_products1 tool

File: user_context.go

Understand user behavior and preferences.

ToolRequest TypeResponse TypeKey Features
get_user_purchase_historyPurchaseHistoryRequestPurchaseHistoryResponseRecent purchases with details
get_user_categoriesUserCategoriesRequestUserCategoriesResponseCategory-level aggregations
get_user_brandsUserBrandsRequestUserBrandsResponseBrand preferences and loyalty
get_purchase_patternsPurchasePatternsRequestPurchasePatternsResponseRepurchase patterns
get_category_brand_affinityCategoryBrandAffinityRequestCategoryBrandAffinityResponseBrand preference within category

Embedded Filters: UserFilter, TimeFilter, PaginationParams

File: products.go

Find and explore products.

ToolRequest TypeResponse TypeKey Features
search_productsSearchProductsRequestSearchProductsResponseSearch with category/brand/name filters
find_similar_productsSimilarProductsRequestSimilarProductsResponseSimilarity-based recommendations
find_alternatives_in_categoryAlternativesRequestAlternativesResponseUntried products in category

Embedded Filters: UserFilter, ProductFilter, SimilarityParams, PaginationParams

File: temporal.go

Time-based queries and predictions.

ToolRequest TypeResponse TypeKey Features
predict_repurchasesRepurchasePredictionRequestRepurchasePredictionResponseWhen user needs products again
get_purchase_timelinePurchaseTimelineRequestPurchaseTimelineResponseHistorical purchase timeline

Embedded Filters: UserFilter, TimeFilter, RepurchaseParams, CategoryFilter, BrandFilter, PaginationParams

File: offers.go

Rewards and promotion discovery.

ToolRequest TypeResponse TypeKey Features
get_active_offersActiveOffersRequestActiveOffersResponseUser’s eligible offers
match_products_to_offersMatchProductsToOffersRequestMatchProductsToOffersResponseCheck which products have offers
search_offersSearchOffersRequestSearchOffersResponseAdvanced offer search

Embedded Filters: UserFilter, CategoryFilter, BrandFilter, RetailerFilter, OfferFilter, PaginationParams

File: brands.go

Brand exploration and comparison.

ToolRequest TypeResponse TypeKey Features
get_brand_productsBrandProductsRequestBrandProductsResponseAll products from a brand
compare_brandsCompareBrandsRequestCompareBrandsResponseSide-by-side brand comparison
discover_brands_in_categoryDiscoverBrandsRequestDiscoverBrandsResponseAll brands in category

Embedded Filters: UserFilter, CategoryFilter, BrandFilter, PaginationParams

File: retailers.go

Store preferences and retailer-specific offers.

ToolRequest TypeResponse TypeKey Features
get_user_retailersUserRetailersRequestUserRetailersResponseWhere user shops
get_retailer_offersRetailerOffersRequestRetailerOffersResponseOffers at specific retailer

Embedded Filters: UserFilter, TimeFilter, RetailerFilter, CategoryFilter, PaginationParams

File: collaborative.go

Social recommendations and local trends.

ToolRequest TypeResponse TypeKey Features
get_collaborative_recommendationsCollaborativeRecommendationsRequestCollaborativeRecommendationsResponse”People like me” recommendations
get_local_trending_productsLocalTrendingRequestLocalTrendingResponsePopular in user’s zip code

Embedded Filters: UserFilter, CategoryFilter, CollaborativeParams, TimeFilter, PaginationParams

File: composition.go

Deep context aggregation.

ToolRequest TypeResponse TypeKey Features
get_product_contextProductContextRequestProductContextResponseComprehensive product context

Embedded Filters: UserFilter, SimilarityParams

  • Pattern: {ToolName}Request
  • Example: PurchaseHistoryRequest, SearchProductsRequest
  • All embed UserFilter (user_id is always required)
  • All have SetDefaults() method
  • Pattern: {ToolName}Response
  • Example: PurchaseHistoryResponse, SearchProductsResponse
  • All include: UserID, data field(s), Count, GeneratedAt
  • Pattern: Descriptive noun (e.g., PurchaseHistoryItem, BrandStats, TrendingProduct)
  • Represent individual items in response arrays
ParameterDefaultMaxApplied By
lookback_daysVaries by toolN/A12 tools
limitVaries by toolVaries18 tools
min_similarity0.61.03 tools
max_similar5502 tools
min_intervals2N/A2 tools
prediction_window14 daysN/A1 tool
min_shared_products2N/A1 tool
same_zip_onlyfalseN/A1 tool
import "internal/models/tools"
// Create a request with embedded filters
req := &tools.PurchaseHistoryRequest{
UserFilter: tools.UserFilter{
UserID: "USER123",
},
TimeFilter: tools.TimeFilter{
LookbackDays: 90, // Override default 180
},
PaginationParams: tools.PaginationParams{
Limit: 20, // Override default 50
},
}
// Apply defaults
req.SetDefaults()
// Make request
response, err := repo.GetPurchaseHistory(ctx, req)
  1. DRY (Don’t Repeat Yourself): Common parameters defined once
  2. Type Safety: Strong typing with Go structs
  3. Discoverability: Related tools grouped together
  4. Maintainability: Easy to update shared parameters
  5. Consistency: All tools follow same patterns
  6. Documentation: Clear structure makes code self-documenting
  7. Testability: Consistent interfaces easy to mock
  8. Extensibility: Easy to add new tools or parameters
  1. Implement Repository Methods: Create methods in internal/graph/repository/ for each tool
  2. Create Service Layer: Add business logic and caching in service layer
  3. Add HTTP Handlers: Expose tools as REST endpoints
  4. Agent Integration: Register tools with LLM function calling
  5. Add Tests: Unit tests for each tool
  6. Add Caching: Tool-specific caching strategies

The old recommendation.go models can be gradually migrated:

Old ModelNew Location
RecommendationRequestKeep in recommendation.go (existing endpoint)
RepurchaseRequestKeep in recommendation.go (existing endpoint)
PurchaseHistoryRequesttools/user_context.go (moved)

This allows gradual migration without breaking existing endpoints.