Building an AI-Powered Grocery Ordering Assistant with Semantic Kernel


As artificial intelligence continues to evolve, one concept is shaping how applications interact with people: context-aware AI orchestration. Instead of handling each user request in isolation, modern AI systems can maintain context, understand intent, and execute workflows step by step.

In this blog, I’ll walk you through a Grocery Shopping Assistant I built using Microsoft Semantic Kernel — a lightweight SDK that makes it easy to create AI-driven applications that understand natural language and connect to your own business logic.

The full project is available on GitHub: https://github.com/venuthomas/AIGroceryShopOnline

Why Semantic Kernel?

Semantic Kernel (SK) isn’t just about calling an AI model; it’s about bridging AI with real-world workflows. With SK, you can:

  • Define plugins (C#, Python, Java available) for specific tasks like product lookup, order placement, or customer validation
  • Guide the AI with context prompts so it knows which plugin to call and when
  • Keep conversations stateful, so the AI remembers what was said earlier

That’s exactly what you need when building a system like grocery ordering, where customers move through a sequence of steps.

How the Assistant Works

The assistant is powered by a structured ordering flow. Instead of free-form AI responses, the conversation is guided by explicit rules:

  1. Customer requests products
    • “What fruits are available?” → ProductPlugin.GetProductsByCategory
    • “Order 2kg apple” → OrderPlugin.ProductVerifyBeforeOrder
  2. Customer details validation
    • Name, phone, and address are collected once via CustomerPlugin.UpdateCustomerDetails.
    • Already provided? The assistant skips re-asking, thanks to context tracking.
  3. Order verification & availability check
    • Always run OrderPlugin.ProductVerifyBeforeOrder first.
    • Assistant shows summary: products, price, stock availability.
  4. Final confirmation
    • Customer says: “Yes”, “Proceed”, “Order it”.
    • The assistant checks context and directly calls OrderPlugin.MakeMultipleProductReservation.
  5. Order placement
    • Reservation created.
    • Order ID and delivery details returned.
  6. Completion & follow-up
    • Customer profile stays active for future orders.
    • Assistant asks: “Do you need anything else?”

Because of the structured context, the assistant never misuses functions. For example:

  • It will not call CheckMultipleProductsAvailability inside an order flow.
  • It will not re-validate customer details unnecessarily.

The system understands the request, verifies availability, and guides the user through the order — all while following a context-driven workflow.

A Custom Extension: vTSafeKernelInvoker

One challenge with Semantic Kernel is controlling how plugin outputs are passed back to the AI. For example, if your plugin queries a database and returns thousands of rows, you don’t want all that raw data sent to the model.

To solve this, I developed InvokePromptFunctionUsingCustomizedKernelAsync, available as a NuGet package (vTSafeKernelInvoker). https://www.nuget.org/packages/vTSafeKernelInvoker

This method extends Semantic Kernel so that:

  • Plugins execute safely based on AI-generated plans
  • Large outputs (like database chunks) aren’t echoed back to the AI
  • The model only sees the essential context, keeping responses accurate and efficient

This makes the assistant production-ready and optimized for real-world data loads.

more about that package : https://wisecodes.venuthomas.in/2025/08/09/vtsafekernelinvoker-efficient-semantic-kernel-plugin-execution-without-extra-ai-token-costs-especially-for-large-output-data/

Tech Stack

  • Frontend: Blazor Server + SignalR (real-time chat UI)
  • Backend: C# with Semantic Kernel
  • Database: SQL Server (structured orders) + Redis (conversation caching)
  • Deployment: Dockerized (docker-compose build –no-cache and <em><strong>docker-compose up -d</strong></em>)
  • Language Flexibility: Semantic Kernel works in C#, Python, and Java, so the same design can be implemented across different stacks.

Why It Matters

This project shows how Semantic Kernel + structured context can transform AI from being “just a chatbot” into a reliable digital assistant:

  • Customers interact naturally (“order 3kg banana”)
  • AI handles workflows step by step
  • Developers keep full control over logic, safety, and scalability

It’s not just about AI talking — it’s about AI doing the right thing, in the right order.

Resources

Note: After cloning the project, update the appsettings.json file with your Azure OpenAI details: DeploymentName, Endpoint, and ApiKey.

If you have any more questions or need further clarification, feel free to ask!

Buy me a pizza

Please follow and like us:
0

One response to “Building an AI-Powered Grocery Ordering Assistant with Semantic Kernel”

Leave a Reply

Your email address will not be published. Required fields are marked *