Before you begin
Before you can ingest and manage menus using the Food Ordering AI Agent API, first:
Enable the Food Ordering AI Agent API:
gcloud services enable foodorderingaiagent.googleapis.com --project=PROJECTEnsure you have the necessary IAM permissions. Grant the following Identity and Access Management (IAM) role to the user or service account that interacts with the API:
- Food Ordering Agent Admin (
roles/foodorderingaiagent.admin): This role provides full access to create, read, update, and delete all Food Ordering AI Agent resources, including Brands, Stores, and Menus.
You can grant IAM roles using the Google Cloud console, the
gcloudcommand-line tool, or the IAM API. For more information, see Grant an IAM role.To grant the role using Google Cloud console:
- In the Google Cloud console, go to the IAM page.
- Click Add.
- Enter the principal (user or service account email).
- Select the Food Ordering AI Agent Admin role.
- Click Save.
Without the appropriate permissions, API calls to create or modify Brands, Stores, or Menus are denied. The
Food Ordering Agent Viewerrole is insufficient for the tasks described in this guide, as it only grants read-only access.- Food Ordering Agent Admin (
Overview
The Food Ordering AI Agent Menu API is designed to be flexible and accommodate various menu structures, from short lists of standalone items to complex menus with nested modifiers and combination meals. The API is built around a few key concepts:
- Menu: The top-level container for all orderable entities.
- Item: Represents an orderable top-level product from the menu, such as a meal, entree, or any product which can be ordered standalone.
Items can referenceModifierGroups. - ModifierGroup: A collection of
Modifieroptions that can be applied to anItemor anotherModifier(allowing nesting). Examples include "Choose Your Side", "Add Toppings", or "Select Drink Flavor." - Modifier: An individual option within a
ModifierGroup, such as "Fries", "Extra Cheese", or "Cola." Modifiers can adjust the price and can also have their own nestedModifierGroups. - MenuCategory: Used to organize
Items into sections for display and display understanding (e.g., "Appetizers", "Burgers", "Drinks").
Key concepts and structure
This section details the core components of the Food Ordering AI Agent Menu API schema and how they are structured. Understanding these concepts is crucial for correctly modeling your menu data.
Items
Each distinct item on your menu should be defined as an Item. Key fields include:
id: A unique identifier within the menu.display_name: The customer-facing name.base_price: The base price of the item.modifier_groups: References toModifierGroups that can apply to this item.category_ids: References toMenuCategoryIDs this item belongs to.availability: Specifies when the item is available (e.g., by status or daypart). Defaults toSTATUS_AVAILABLEif not specified.
Modifiers and ModifierGroups
Modifiers allow for customization of items.
ModifierGroups define a set of choices, including constraints like minimum or maximum selections. Must contain at least oneModifier.Modifiers represent the actual options. They can have aprice_adjustmentand can recursively reference otherModifierGroups for nested customizations (e.g., a "Meal Combo"Itemmight have a "Choose Your Drink"ModifierGroup, and the "Soda"Modifierwithin that group could have a "Choose Flavor"ModifierGroup).
Example 1: Toppings
A "Bacon Cheeseburger" Item might reference a "Toppings" ModifierGroup. This ModifierGroup would contain Modifiers like "Extra Cheese", "No Onions", etc.
Example 2: Combination meals (Combos)
Some menus have complex structures consisting of multiple nested choices, such as combination meals, or "combos". Combos can be modeled as an Item with several ModifierGroups representing the components of the combo. For example, a "Burger Combo" Item, consisting of a fixed entree bundled with multiple options for side and drink could be modeled with:
- A
ModifierGroupfor the side (e.g., "Side choices").- Each side option is modeled as a
Modifier(e.g., "Fries", "Salad").- Each drink option may reference nested
ModifierGroups (e.g., "Ice options", "Drink size") which in turn referencesModifiers (e.g. "No Ice", "Large drink", respectively).
- Each drink option may reference nested
- Each side option is modeled as a
- A
ModifierGroupfor the drink (e.g., "Drinks").- Each drink option is modeled as a
Modifier.- Each drink option may reference nested
ModifierGroups (e.g., "Ice options", "Drink size") which in turn referencesModifiers (e.g. "No Ice", "Large drink").
- Each drink option may reference nested
- Each drink option is modeled as a
- A
ModifierGroupfor toppings on the entree. (e.g., "Extra Cheese", "Bacon").
Availability
The Availability message on Items and Modifiers lets you specify:
status:STATUS_AVAILABLE,STATUS_OUT_OF_STOCK, etc.daypart_availability: Links to specific daypart IDs if the item is only available during certain times (e.g., "Breakfast Menu").
Integration attributes
Item, Modifier, and ModifierGroup messages contain an integration_attributes field. This field (ItemIntegrationAttributes, ModifierIntegrationAttributes, etc.) holds a google.protobuf.Struct called custom_integration_attributes. You can use this to store arbitrary key-value data, such as:
- IDs from your Point of Sale (POS) system.
- SKUs or other internal codes.
- Any other metadata needed for downstream order processing or POS integration.
This data is passed through opaquely by the AI agent.
Labels
You can use the labels field on the Menu resource to attach metadata to menus to help with integration and debugging.
Labels are a convenience feature and have no effect on the AI agent's behavior.
Creating a Menu
Menus are ingested using the CreateMenu RPC call within the MenuService.
Steps
- Transform Your Data: Convert your existing menu data (from your POS, API, or other source) into the structure defined by the
google.cloud.foodorderingaiagent.v1beta.Menumessage. This involves mapping your items, modifiers, categories, and prices to the corresponding API message types. - Construct the
CreateMenuRequest:- Set the
parentfield (e.g.,projects/PROJECT/locations/LOCATION). - Populate the
menufield with your transformedMenuobject. - Optionally provide a
menu_id.
- Set the
- Call the API: Send the
CreateMenuRequestto theMenuService.CreateMenuendpoint. The API will first sanitize the menu, then validate it, and return the finalMenuobject. - Handle Menu Updates: Upon each update to the menu source data (e.g. when a new product is introduced, or when a product becomes unavailable), a new
Menushould be created reflecting the updated source data, following handling menu updates.
Guidance for data transformation
The specific logic for transforming your menu data will depend on the format and structure of your source system (e.g., POS API, database schema). Here's a general approach:
- Export Data: Obtain a complete export of your menu data, including all items, modifiers, prices, and relationships.
- Map Entities:
- Identify the corresponding entities in the Food Ordering AI Agent API schema for each element in your source data. For example, your POS "menu items" will likely map to
Itemobjects. "Order options" or "add-ons" will map toModifiers andModifierGroups. - Establish relationships using IDs. For example, link
Items to their applicableModifierGroups using themodifier_groupsreference field.
- Identify the corresponding entities in the Food Ordering AI Agent API schema for each element in your source data. For example, your POS "menu items" will likely map to
- Handle Nested Structures: If your menu has nested modifiers (e.g., choosing a drink flavor for a combo meal's soda), model this by having
Modifiers reference otherModifierGroups. - Populate Attributes: Fill in fields like
display_name,base_price,price_adjustment, andavailabilitybased on your source data. - Include POS IDs: Crucially, store your internal POS or system IDs for each item, modifier, and group within the
custom_integration_attributesfield. This lets you translate theOrderproduced by the agent back to your application's representation of a final order or in-progress cart. - Scripting: You will likely need to write a script (e.g., in Python, Node.js, Go) to fetch data from your source, perform the transformation, and call the
CreateMenumethod. This script will use the Google Cloud client libraries for authentication and API interaction.
Conceptual Transformation Workflow:
This workflow outlines the process of transforming menu data from a source system into the Food Ordering AI Agent API format:
- Extract and Map Categories:
- Identify categories or sections in your source data (e.g., "Appetizers", "Entrees").
- Transform each into a
MenuCategoryobject with a uniqueidanddisplay_name.
- Extract and Map Items:
- Identify sellable items in your source data.
- Transform each into an
Itemobject, populatingid,display_name,base_price, andavailability. - Map each
Itemto its categories using thecategory_idsfield. - Store source system identifiers (like PLU or SKU) in
item.integration_attributes.custom_integration_attributes.
- Extract and Map Modifiers:
- Identify item customizations, options, or add-ons in your source data.
- Group related options (e.g., "Side Options", "Drink Choices", "Extra Toppings") into
ModifierGroupobjects. Define minimum and maximum selection rules on eachModifierGroup. - Transform each individual option (e.g., "Fries", "Cola", "Extra Cheese") into
Modifierobjects within the appropriateModifierGroup. Populateprice_adjustmentif applicable. - Store source system identifiers in
modifier_group.integration_attributes.custom_integration_attributesandmodifier.integration_attributes.custom_integration_attributes.
- Establish Relationships:
- For each
Item, populate itsmodifier_groupsfield with references to theids ofModifierGroups that apply to it. - If a
Modifierallows for further customization (e.g., choosing a flavor for a "Soda" modifier), populate itsmodifier_groupsfield to create nested modifiers.
- For each
- Assemble and Ingest:
- Combine all
MenuCategory,Item,ModifierGroup, andModifierobjects into the lists within a singleMenumessage. - Call the
CreateMenuRPC with the fully assembledMenumessage as input.
- Combine all
Handling menu updates
Menu is immutable. Once a menu is created using the CreateMenu RPC call, it cannot be modified. To propagate menu updates into a menu—such as changing item prices, modifying options, or adjusting availability—you must create a new menu resource by calling CreateMenu again. Each version of your menu should be ingested as a new Menu resource with a unique menu_id.
The process for ingesting a new version of a menu is identical to ingesting the menu for the first time, and it undergoes the same sanitization and validation steps. While handling orders, the agent's behavior will always reflect the most recently created Menu associated with the Store referenced in the session's configuration.
Automatic menu sanitization
The CreateMenu API automatically performs several sanitization steps to correct common issues and ensure menu content is represented consistently throughout the API. Validations are applied after these sanitizations to simplify menu integration for clients:
- Default availability:
Items andModifiers without an explicitAvailability.Statusare set toSTATUS_AVAILABLE. - Drop unreferenced entities:
Modifiers andModifierGroups that are not transitively referenced by anyItemare removed from the menu, as they can't be ordered. - Drop empty modifier groups:
ModifierGroups that contain nomodifier_idsare dropped, and any references to them are removed.
Menu validation
After sanitization, the API validates the menu against a strict set of rules to ensure it's well-formed and can be reliably used by the AI agent. If validation fails, the CreateMenu call will return an error detailing the issues. Key validations include:
- Required fields: Ensures all required fields like
id,display_name, andavailability.statusare present. - Unique IDs: All
Items,Modifiers, andModifierGroups must have unique IDs within the menu. - Unique display names:
- All
Items must have uniquedisplay_names. - Within any given
ModifierGroup, all containedModifiers must have uniquedisplay_names.
- All
- Reference integrity:
- All
modifier_group_idsreferenced byItems orModifiers must exist in the menu. - All
modifier_idsreferenced byModifierGroups must exist in the menu. - Default modifiers specified in
ModifierGroupReferencemust exist in the referencedModifierGroup. - If a
Modifierusesitem_idto reference anItem, thatItemmust exist.
- All
- Modifier group constraints:
ModifierGroups cannot be empty.- Minimum or maximum selection counts within
ModifierGroups are checked for logical consistency. ItemorModifierlevelmodifier_constraintsare validated against the selection count constraints of referencedModifierGroups to ensure they are satisfiable.
- Nesting depth: The depth of nested modifiers is limited (e.g.,
Item->ModifierGroup->Modifier->ModifierGroup->Modifier...) to a maximum of 5 levels. - Daypart validation: If dayparts are used in
Availability, they must be defined in the associatedStoreresource. - Modifier item references:
Modifiers referencing anItemusingitem_idcannot have fields likedisplay_nameoravailabilityset, as these are inherited from the referencedItem.
A failure on any of these validation rules will prevent the menu from being created or updated. The error message will provide details on which entities are causing the violation.
API reference
For complete details on all messages and fields, see the Food Ordering AI Agent API RPC Reference.
Best practices
- Unique IDs: Ensure all
idfields within theMenuscope (forItem,Modifier,ModifierGroup,MenuCategory) are unique. - Clear Names: Use clear, customer-friendly
display_names. Provide distinctdisplay_names for semantically different products to steer the agent to disambiguate appropriately. - Model Combos Effectively: Model combination meals as an
ItemwithModifierGroups representing sides, drinks, and other choices, as described in combination meals. This ensures the agent can correctly guide customers through combo selections. - Use Integration Attributes: Store any necessary POS or internal system identifiers in the
custom_integration_attributesto facilitate seamless order integration. - Manage Availability: Keep the
Availabilitystatus up-to-date. - Test Thoroughly: After ingestion, test the agent's understanding of the menu with various order combinations.