{
  "name": "E-commerce AI Agent with Real-Time Stock Check",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {},
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Customer message"
        }
      }
    },
    {
      "id": 2,
      "module": "ai-local-agent:RunLocalAIAgent",
      "version": 0,
      "parameters": {
        "makeConnectionId": 1
      },
      "mapper": {
        "defaultModel": "gpt-4.1-mini",
        "systemPrompt": "You are a shop assistant. You can answer only by calling the catalog tools. search_shop_catalog and get_shop_product read a feed snapshot.\n\nWhen the customer asks about a product, a price, or availability:\n1. In the same reply, say \"Зараз перевірю наявність.\"\n2. Call a tool before you name any price, stock state, or product. If they give an exact article, call get_shop_product. Otherwise call search_shop_catalog and put their words in q.\n3. Leave sku as an empty string, and leave min_price and max_price null, unless they named an article or a price range. Set in_stock_only only when they want confirmed in-stock items. Keep limit at 5.\n\nThe tool returns JSON. Read items for the customer. Take price, stock, and url from items. Never invent them. stock \"unknown\" means the feed said nothing — do not promise that item is available. stock \"out_of_stock\" means it is not available. If catalog.stale is true, say the price must be confirmed. If count is 0 or the product tool returns 404, say nothing matched. Do not paste raw JSON into the chat.",
        "message": "{{ifempty(1.message; 1.q)}}",
        "files": [],
        "threadId": "{{ifempty(1.threadId; \"\")}}",
        "modelConfig": {
          "recursionLimit": 6,
          "iterationsFromHistoryCount": 10
        },
        "timeout": "",
        "outputType": "text"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Shop agent"
        },
        "restore": {
          "parameters": {
            "makeConnectionId": {
              "label": "OpenAI",
              "data": {
                "scoped": "true",
                "connection": "openai-gpt-3"
              }
            }
          },
          "expect": {
            "defaultModel": {
              "mode": "chose",
              "label": "gpt-4.1-mini"
            },
            "files": {
              "mode": "chose"
            },
            "outputType": {
              "label": "Text"
            }
          }
        }
      },
      "tools": [
        {
          "name": "search_shop_catalog",
          "description": "Search the shop catalog by the customer's words, an article, or a price range. Call this before any answer about price, availability, or which product to buy. Pass q in the customer's words. Leave sku empty and min_price and max_price null when not asked. Returns items (exact price, stock, url) and catalog.stale.",
          "flow": [
            {
              "id": 3,
              "module": "http:ActionSendData",
              "version": 3,
              "parameters": {
                "handleErrors": true,
                "useNewZLibDeCompress": true
              },
              "mapper": {
                "url": "http://127.0.0.1:8080/v1/catalog/mock_5/search",
                "serializeUrl": false,
                "method": "post",
                "headers": [
                  {
                    "name": "Content-Type",
                    "value": "application/json"
                  },
                  {
                    "name": "Accept",
                    "value": "application/json"
                  },
                  {
                    "name": "Authorization",
                    "value": "Bearer PASTE_SHOP_KEY"
                  }
                ],
                "qs": [],
                "bodyType": "raw",
                "contentType": "application/json",
                "data": "{{2.data}}",
                "parseResponse": true,
                "authUser": "",
                "authPass": "",
                "timeout": "30",
                "shareCookies": false,
                "ca": "",
                "rejectUnauthorized": true,
                "followRedirect": true,
                "useQuerystring": false,
                "gzip": true,
                "useMtls": false,
                "followAllRedirects": false
              },
              "metadata": {
                "designer": {
                  "x": 300,
                  "y": 280,
                  "name": "search_shop_catalog"
                },
                "restore": {
                  "expect": {
                    "method": {
                      "mode": "chose",
                      "label": "POST"
                    },
                    "bodyType": {
                      "label": "Raw"
                    },
                    "contentType": {
                      "label": "JSON (application/json)"
                    },
                    "data": {
                      "extra": {
                        "aiHelp": "Raw JSON only, no markdown.",
                        "aiInstruction": "Body of POST /v1/catalog/mock_5/search. One JSON object, no code fence. Keys: q (string, the customer's words), sku (string, empty when they did not name an article), min_price (number or null), max_price (number or null), limit (number, default 5, max 5), in_stock_only (boolean, default false). Example: {\"q\":\"дриль\",\"sku\":\"\",\"min_price\":null,\"max_price\":null,\"limit\":5,\"in_stock_only\":false}"
                      }
                    }
                  }
                }
              }
            }
          ]
        },
        {
          "name": "get_shop_product",
          "description": "Fetch one product by its exact article number (SKU). Use this when the customer names an article. Returns the same JSON as search: items and catalog.stale. A 404 means that article is not in the catalog.",
          "flow": [
            {
              "id": 4,
              "module": "http:ActionSendData",
              "version": 3,
              "parameters": {
                "handleErrors": true,
                "useNewZLibDeCompress": true
              },
              "mapper": {
                "url": "{{2.url}}",
                "serializeUrl": false,
                "method": "get",
                "headers": [
                  {
                    "name": "Accept",
                    "value": "application/json"
                  },
                  {
                    "name": "Authorization",
                    "value": "Bearer PASTE_SHOP_KEY"
                  }
                ],
                "qs": [],
                "bodyType": "",
                "parseResponse": true,
                "authUser": "",
                "authPass": "",
                "timeout": "30",
                "shareCookies": false,
                "ca": "",
                "rejectUnauthorized": true,
                "followRedirect": true,
                "useQuerystring": false,
                "gzip": true,
                "useMtls": false,
                "followAllRedirects": false
              },
              "metadata": {
                "designer": {
                  "x": 600,
                  "y": 280,
                  "name": "get_shop_product"
                },
                "restore": {
                  "expect": {
                    "method": {
                      "mode": "chose",
                      "label": "GET"
                    },
                    "url": {
                      "extra": {
                        "aiHelp": "Full product URL ending with the article.",
                        "aiInstruction": "Set url to http://127.0.0.1:8080/v1/catalog/mock_5/products/ plus the exact article, with the article URL-encoded. Example: http://127.0.0.1:8080/v1/catalog/mock_5/products/MOCK-00004"
                      }
                    }
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "id": 5,
      "module": "gateway:WebhookRespond",
      "version": 1,
      "parameters": {},
      "mapper": {
        "status": "200",
        "body": "{{2.response}}",
        "headers": [
          {
            "name": "Content-Type",
            "value": "text/plain; charset=utf-8"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Reply"
        }
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    }
  }
}
