{"id":51061829,"url":"https://github.com/kardelruveyda/foundry-commerce-demo","last_synced_at":"2026-06-23T03:01:09.971Z","repository":{"id":355482892,"uuid":"1228254460","full_name":"KardelRuveyda/foundry-commerce-demo","owner":"KardelRuveyda","description":"Multi-agent e-commerce operations center built with Microsoft Agent Framework v1.0 + Foundry on .NET 10. Fraud detection, inventory, fulfillment, and customer comms — all in C#.","archived":false,"fork":false,"pushed_at":"2026-05-03T20:04:50.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-03T22:09:41.366Z","etag":null,"topics":["azure-ai","csharp","demo","dotnet","microsoft-agent-framework","microsoft-foundry","net10"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KardelRuveyda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-03T19:49:00.000Z","updated_at":"2026-05-03T20:04:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/KardelRuveyda/foundry-commerce-demo","commit_stats":null,"previous_names":["kardelruveyda/foundry-commerce-demo"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/KardelRuveyda/foundry-commerce-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KardelRuveyda%2Ffoundry-commerce-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KardelRuveyda%2Ffoundry-commerce-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KardelRuveyda%2Ffoundry-commerce-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KardelRuveyda%2Ffoundry-commerce-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KardelRuveyda","download_url":"https://codeload.github.com/KardelRuveyda/foundry-commerce-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KardelRuveyda%2Ffoundry-commerce-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34673437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-ai","csharp","demo","dotnet","microsoft-agent-framework","microsoft-foundry","net10"],"created_at":"2026-06-23T03:01:08.295Z","updated_at":"2026-06-23T03:01:09.961Z","avatar_url":"https://github.com/KardelRuveyda.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🛒 FoundryCommerceDemo\n\n\u003e **Enterprise E-Commerce Operations Center — Multi-Agent Demo**\n\u003e Built with Microsoft Agent Framework v1.0 + Microsoft Foundry.\n\u003e A simple end-to-end pipeline:\n\u003e fraud check → inventory → fulfillment → customer email.\n\n[![.NET](https://img.shields.io/badge/.NET-10.0-512BD4?logo=dotnet)](https://dotnet.microsoft.com/)\n[![Agent Framework](https://img.shields.io/badge/Agent%20Framework-v1.3-0078D4)](https://github.com/microsoft/agent-framework)\n[![Foundry](https://img.shields.io/badge/Microsoft-Foundry-2560E0)](https://foundry.azure.com)\n\n---\n\n## 📖 Table of Contents\n\n1. [What is this?](#-what-is-this)\n2. [Architecture](#-architecture)\n3. [Hosting model — this is a LOCAL agent demo](#-hosting-model--this-is-a-local-agent-demo)\n4. [Other hosting options](#-other-hosting-options)\n5. [What you need](#-what-you-need)\n6. [Quick start](#-quick-start)\n7. [Azure setup (`az login` step by step)](#-azure-setup-az-login-step-by-step)\n8. [Environment variables](#-environment-variables)\n9. [How to run](#-how-to-run)\n10. [Project structure](#-project-structure)\n11. [Demo orders](#-demo-orders)\n12. [Local mode (Ollama)](#-local-mode-ollama)\n13. [Troubleshooting](#-troubleshooting)\n14. [License](#-license)\n\n---\n\n## 🎯 What is this?\n\nThis demo shows an online shop. When a new order comes in, **four AI agents**\nwork together like a team:\n\n| Agent | What it does |\n|-------|--------------|\n| 🛡️ **FraudDetectionAgent** | Looks for risky orders. Checks the country, the device, and how many orders the customer made today. |\n| 📦 **InventoryAgent** | Checks if the products are in stock. Looks at all warehouses. Can reserve items. |\n| 🚚 **FulfillmentAgent** | Picks the best warehouse. Calculates shipping cost. Can split the order if needed. |\n| 💬 **CustomerAgent** | Writes a nice email to the customer. Never shares secret data (like fraud scores). |\n\n### Why is this cool?\n\n- ✅ **Real C# code** does the math. The AI does **not** invent numbers.\n- ✅ **Multiple warehouses** with real stock data.\n- ✅ **Split shipments** when one warehouse is not enough.\n- ✅ **Agent-as-a-tool**: one agent can use another agent like a function.\n- ✅ **Local mode**: payment data stays on your computer (good for PCI-DSS).\n\n---\n\n## 🏠 Hosting model — this is a **LOCAL agent demo**\n\n\u003e **Important:** In this repo the agents run **on your computer**, not in the cloud.\n\u003e Microsoft Foundry is used **only as the LLM gateway** (model + auth + project scope).\n\u003e All agent logic, tools, and state live inside your local `dotnet run` process.\n\n### 📐 Architecture diagrams\n\n| Scenario | SVG (preview) | draw.io (editable) |\n|----------|---------------|--------------------|\n| 🏠 **Local agents** (this repo) | _inline below_ | — |\n| ☁️ **Option 1 — Container Apps** | [option2-container-apps.svg](docs/architecture/option2-container-apps.svg) | [.drawio](docs/architecture/option2-container-apps.drawio) |\n| 🏗️ **Option 2 — Foundry Agent Service (Azure resources)** ⭐ | [option3-foundry-agent-service-azure.svg](docs/architecture/option3-foundry-agent-service-azure.svg) | [.drawio](docs/architecture/option3-foundry-agent-service-azure.drawio) |\n| 📖 Option 2 — Foundry Agent Service (run lifecycle, story-style) | [option3-foundry-agent-service-detailed.svg](docs/architecture/option3-foundry-agent-service-detailed.svg) | [.drawio](docs/architecture/option3-foundry-agent-service-detailed.drawio) |\n| 🤖 Option 2 — Foundry Agent Service (compact overview) | [option3-foundry-agent-service.svg](docs/architecture/option3-foundry-agent-service.svg) | [.drawio](docs/architecture/option3-foundry-agent-service.drawio) |\n| ⏱️ **Option 4 — Azure Durable Functions** (long-running workflows) | [option4-durable-functions-azure.svg](docs/architecture/option4-durable-functions-azure.svg) | [.drawio](docs/architecture/option4-durable-functions-azure.drawio) |\n\n### What runs where?\n\n```\n┌─────────────────────────────────────────────────┐\n│ YOUR MACHINE  (dotnet run)                      │\n│                                                 │\n│  ┌──────────────────────────────────────────┐   │\n│  │ Pipeline orchestrator (Program.cs)       │   │\n│  │  ├─ FraudDetectionAgent                  │   │\n│  │  ├─ InventoryAgent                       │   │\n│  │  ├─ FulfillmentAgent                     │   │\n│  │  └─ CustomerAgent                        │   │\n│  │                                          │   │\n│  │ Tools = your C# code (FraudTools.cs etc.)│   │\n│  │ State = in-memory (OrderDatabase)        │   │\n│  └──────────────────┬───────────────────────┘   │\n└─────────────────────┼───────────────────────────┘\n                      │ HTTPS\n                      ▼\n          ┌────────────────────────┐\n          │ Microsoft Foundry      │\n          │  • gpt-4o-mini model   │  ← only LLM calls go here\n          │  • DefaultAzureCredential\n          └────────────────────────┘\n```\n\n### What Foundry does (in this demo)\n\n| # | Feature | Used? | Notes |\n|---|---------|:-----:|-------|\n| 🧠 Model hosting | ✅ | `gpt-4o-mini` |\n| 🔐 Authentication | ✅ | `DefaultAzureCredential` + `az login` (no API keys) |\n| 📦 Project scope | ✅ | One project for billing, quota, monitoring |\n| 🤖 Foundry Agent Service (cloud-hosted agents) | ❌ | Agents are local |\n| 💬 Threads / conversation history | ❌ | Not persisted |\n| 📚 Vector stores / file search | ❌ | Not used |\n| 🔒 Content safety filters | ❌ | Not configured |\n| 📊 Tracing / evaluation | ❌ | Add OpenTelemetry to enable |\n\n### Why this design?\n\n- 🚀 **Fast** to demo — no deployment needed.\n- 💰 **Cheap** — you only pay for LLM tokens.\n- 🧪 **Easy to debug** — set breakpoints in Visual Studio.\n- 🎤 **Great for talks** — everything visible on stage.\n\n### Limitations of running locally\n\n- ❌ No state persistence — process restart wipes everything.\n- ❌ Single user only.\n- ❌ No autoscale.\n- ❌ Not production-ready as-is.\n\n👉 If you need any of those, see the next section.\n\n---\n\n## ☁️ Other hosting options\n\nFoundry can host much more than just the model. Here are **three ways** to move\nthe agents to the cloud, from least to most cloud-native.\n\n### Comparison at a glance\n\n| Option | Code change | State persistence | Multi-user | Scale-to-zero | Best for |\n|--------|:-----------:|:-----------------:|:----------:|:-------------:|----------|\n| 🏠 **Local** (this repo) | — | ❌ | ❌ | — | Demos, dev loop |\n| ☁️ **Container Apps** | Small | ❌ (add Cosmos DB) | ✅ | ✅ | Most teams |\n| 🤖 **Foundry Agent Service** | Medium | ✅ Auto | ✅ | ✅ | Cloud-first agents |\n| ⏱️ **Durable Functions** | Medium | ✅ Auto | ✅ | ✅ | Long-running workflows |\n\n---\n\n### Option 1 — Azure Container Apps (recommended next step)\n\nWrap the same .NET 10 code in an ASP.NET Core API and deploy to a serverless\ncontainer runtime. Your agent code does **not** change — only `Program.cs`\nbecomes a web app.\n\n📐 **Architecture diagram:**\n[`docs/architecture/option2-container-apps.svg`](docs/architecture/option2-container-apps.svg)\n· editable [`.drawio`](docs/architecture/option2-container-apps.drawio)\n\n**Topology:**\n\n```\nClient → Front Door / APIM → Container Apps (foundry-commerce-api)\n                                   ├─ pulls image from ACR\n                                   ├─ uses Managed Identity → Foundry (LLM)\n                                   ├─ logs to App Insights\n                                   └─ stores data in Cosmos DB / Service Bus\n```\n\n**Sketch of the code:**\n\n```csharp\nvar builder = WebApplication.CreateBuilder(args);\n\nbuilder.Services.AddSingleton(sp =\u003e\n    new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential()));\n\nvar app = builder.Build();\n\napp.MapPost(\"/api/orders/{orderId}/process\", async (string orderId, AIProjectClient client) =\u003e\n{\n    var fraudAgent = client.AsAIAgent(\n        model: \"gpt-4o-mini\",\n        instructions: \"...\",\n        tools: [...]);\n\n    var result = await fraudAgent.RunAsync($\"Process order {orderId}\");\n    return Results.Ok(result);\n});\n\napp.Run();\n```\n\n**Deploy:**\n\n```powershell\naz containerapp up `\n  --name foundry-commerce-api `\n  --resource-group rg-demo `\n  --location swedencentral `\n  --source .\n```\n\nor with Azure Developer CLI:\n\n```powershell\nazd up\n```\n\n**Pros**\n- ✅ Minimal code changes.\n- ✅ Scale-to-zero (you pay $0 when idle).\n- ✅ Managed Identity → no secrets in code.\n- ✅ HTTPS endpoint, custom domains, revisions, blue/green deploys.\n\n**Cons**\n- ❌ You still manage state yourself (add Cosmos DB or SQL).\n- ❌ Threads/conversations are not built-in.\n\n---\n\n### Option 2 — Microsoft Foundry **Agent Service** (cloud-hosted agents)\n\nLet Foundry host the agent itself. Tool definitions, instructions, and\nconversation threads all live in the cloud. Your code calls the agent and\nresponds to tool-call requests.\n\n🏗️ **Azure architecture (production-ready resource topology):**\n[`docs/architecture/option3-foundry-agent-service-azure.svg`](docs/architecture/option3-foundry-agent-service-azure.svg)\n· editable [`.drawio`](docs/architecture/option3-foundry-agent-service-azure.drawio)\n\nThis is the **“what do I deploy?”** view. It shows real Azure resources, resource\ngroups, networking, identity, and data services laid out the way they would look\nin production.\n\n**Resource groups in the diagram:**\n\n| RG | Color | Contents |\n|----|-------|----------|\n| `rg-foundrycommerce-app` | 🟩 Green | Container Apps (api + worker), ACR, UAMI, Key Vault, App Configuration, Service Bus |\n| `rg-foundrycommerce-foundry` | 🟧 Orange | Foundry Hub + Project, PersistentAgents, Threads/Runs, model deployments, vector store, content safety |\n| `rg-foundrycommerce-data` | 🟪 Purple | Cosmos DB (NoSQL), Azure SQL, Storage Account, Azure Managed Redis |\n\n**Cross-cutting concerns (shown on the side):**\n\n- 🆔 **Microsoft Entra ID** → issues tokens to a User-Assigned Managed Identity. **No API keys anywhere.**\n- 🔐 **VNet** (`vnet-foundry-prod`) with private endpoints for Key Vault, ACR, Cosmos DB, Storage, Foundry.\n- 🛡️ **Edge** — Front Door + WAF + API Management + DDoS Protection.\n- 📊 **Observability** — Application Insights, Log Analytics, Azure Monitor, Foundry built-in tracing, Defender for Cloud.\n\n**Run lifecycle (numbered arrows on the diagram):**\n\n| # | Color | What happens |\n|---|-------|--------------|\n| ① | 🟧 Orange | Container App calls `Runs.CreateRunAsync` on Foundry Agent Service |\n| ② | 🟪 Purple | Foundry replies with `requires_action` → “call tool X” |\n| ③ | 🟩 Green | Container App runs the C# tool and posts back via `SubmitToolOutputsAsync` |\n\nFor a step-by-step **run lifecycle** explanation (story-style), see\n[`option3-foundry-agent-service-detailed.svg`](docs/architecture/option3-foundry-agent-service-detailed.svg).\nFor a single-page **compact overview**, see\n[`option3-foundry-agent-service.svg`](docs/architecture/option3-foundry-agent-service.svg).\n\n**Topology:**\n\n```\nClient → Container Apps (thin API)\n              │   ① start run\n              ▼\n       ┌─────────────────────────────────────────┐\n       │ Microsoft Foundry — Agent Service       │\n       │  • PersistentAgents (definitions)       │\n       │  • Threads + Runs (auto-saved state)    │\n       │  • Vector store (optional, RAG)         │\n       │  • Model deployment (gpt-4o-mini)       │\n       │  • Built-in safety + tracing            │\n       └──────────────┬──────────────────────────┘\n                      │ ② \"call tool X\"\n                      ▼\n       Container Apps tool handler → runs C# in your code\n                      │ ③ returns tool result\n                      ▼\n       Foundry continues the run → ④ final reply\n```\n\n**Run lifecycle (4 steps):**\n\n| # | Who | What happens |\n|---|-----|--------------|\n| ① | Your API | `Runs.CreateRunAsync(thread, agent)` |\n| ② | Foundry | Sends a `requires_action` event with tool name + args |\n| ③ | Your API | Runs the C# tool, posts result back via `SubmitToolOutputsAsync` |\n| ④ | Foundry | Continues reasoning, returns the final assistant message |\n\n\u003e 💡 Foundry stores **conversation data** (threads, runs, tool calls).\n\u003e Your backend stores **business data** (orders, warehouses) in Cosmos DB / SQL.\n\n**Sketch:**\n\n```csharp\nusing Azure.AI.Agents.Persistent;\n\nvar agentsClient = new PersistentAgentsClient(endpoint, credential);\n\n// 1. Create the agent in Foundry (once)\nvar agent = await agentsClient.Administration.CreateAgentAsync(\n    model: \"gpt-4o-mini\",\n    name: \"FraudDetectionAgent\",\n    instructions: \"You analyze fraud risk...\",\n    tools: [\n        new FunctionToolDefinition(\n            name: \"AnalyzeGeoConsistency\",\n            description: \"Checks geographic consistency\",\n            parameters: BinaryData.FromString(\"\"\"\n                { \"type\": \"object\", \"properties\": {\n                    \"orderId\": { \"type\": \"string\" }\n                }}\n                \"\"\"))\n    ]);\n\n// 2. Create a conversation thread\nvar thread = await agentsClient.Threads.CreateThreadAsync();\n\n// 3. Send a message and run\nawait agentsClient.Messages.CreateMessageAsync(\n    thread.Id, MessageRole.User, \"Check ORD-50002\");\nvar run = await agentsClient.Runs.CreateRunAsync(thread.Id, agent.Id);\n```\n\n**What Foundry stores for you**\n- ✅ Agent definition (tools, instructions, model)\n- ✅ Thread history (every conversation)\n- ✅ Run state (resumable if your code crashes)\n- ✅ Tool call audit trail\n\n**Pros**\n- ✅ Automatic state, threads, history.\n- ✅ Built-in safety, evaluation, tracing in Foundry portal.\n- ✅ You only host the **tool execution** (a webhook or function).\n\n**Cons**\n- ❌ More refactoring — moves agent definition out of C#.\n- ❌ Slightly higher cost (storage + agent runtime).\n\n---\n\n### Option 3 — Azure Durable Functions (long-running workflows)\n\nUse this if your pipeline can take **hours or days** (e.g. waits for a manager\napproval, retries failed shipments, cross-day reconciliation).\n\n**Sketch:**\n\n```csharp\n[Function(nameof(OrderPipeline))]\npublic async Task\u003cstring\u003e OrderPipeline(\n    [OrchestrationTrigger] TaskOrchestrationContext context)\n{\n    var orderId = context.GetInput\u003cstring\u003e();\n\n    // Step 1: fraud check\n    var verdict = await context.CallActivityAsync\u003cstring\u003e(\n        nameof(RunFraudAgent), orderId);\n\n    if (verdict == \"BLOCKED\")\n        return await context.CallActivityAsync\u003cstring\u003e(\n            nameof(SendBlockEmail), orderId);\n\n    // Step 2: wait up to 24h for human approval\n    var approved = await context.WaitForExternalEvent\u003cbool\u003e(\n        \"ManagerApproval\", TimeSpan.FromHours(24));\n\n    // Step 3: fulfillment\n    return await context.CallActivityAsync\u003cstring\u003e(\n        nameof(RunFulfillmentAgent), orderId);\n}\n```\n\n**Pros**\n- ✅ State and progress are checkpointed automatically.\n- ✅ Survives restarts, scale-out, and long waits.\n- ✅ Perfect for human-in-the-loop steps.\n\n**Cons**\n- ❌ More moving parts (Functions runtime, storage account).\n- ❌ Steeper learning curve than Container Apps.\n\n---\n\n### Which option should you pick?\n\n```\n             ┌────────────────────────────┐\n             │ Do agents need to keep      │\n             │ state across requests?      │\n             └──────┬─────────────┬───────┘\n                 No │             │ Yes\n                    ▼             ▼\n           ┌─────────────┐   ┌──────────────────────┐\n           │ Container   │   │ Pipeline can take    │\n           │ Apps        │   │ hours / human waits? │\n           │ (Option 1)  │   └────┬─────────┬───────┘\n           └─────────────┘     No │         │ Yes\n                                  ▼         ▼\n                       ┌────────────────┐  ┌────────────────┐\n                       │ Foundry Agent  │  │ Durable        │\n                       │ Service        │  │ Functions      │\n                       │ (Option 2)     │  │ (Option 3)     │\n                       └────────────────┘  └────────────────┘\n```\n\n**Rule of thumb for this demo:** start with Container Apps. It is the smallest\njump from the local code in this repo and covers ~80% of real-world needs.\n\n---\n\n## 🏗️ Architecture\n\n```\n┌──────────────────────────────────────────────────────────────────┐\n│                          NEW ORDER                                │\n└──────────────────────────────┬───────────────────────────────────┘\n                               ▼\n                   ┌───────────────────────┐\n                   │ FraudDetectionAgent   │\n                   │  • Geo check          │\n                   │  • Velocity check     │\n                   │  • Final verdict      │\n                   └─────────┬─────────────┘\n                             │\n              ┌──────────────┴──────────────┐\n              ▼ BLOCKED                     ▼ APPROVED\n   ┌───────────────────┐         ┌────────────────────────┐\n   │  CustomerAgent    │         │  FulfillmentAgent      │\n   │  writes a polite  │         │   uses ↓ as a tool     │\n   │  \"we need more    │         │  ┌──────────────────┐  │\n   │  info\" email.     │         │  │ InventoryAgent   │  │\n   │  No secret data.  │         │  │  • CheckStock    │  │\n   └───────────────────┘         │  │  • Optimize      │  │\n                                 │  │  • Reserve       │  │\n                                 │  └──────────────────┘  │\n                                 └──────────┬─────────────┘\n                                            ▼\n                                  ┌───────────────────────┐\n                                  │  CustomerAgent        │\n                                  │  writes a thank-you   │\n                                  │  email with the ETA.  │\n                                  └───────────────────────┘\n```\n\n---\n\n## 🧰 What you need\n\n| Tool | Version | Note |\n|------|---------|------|\n| .NET SDK | **10.0** (8.0+ also works) | Check with `dotnet --version` |\n| Azure CLI | latest | Check with `az --version` |\n| Visual Studio 2022/2026 or VS Code | — | C# Dev Kit is helpful |\n| Microsoft Foundry project | — | One model must be deployed (e.g. `gpt-4o-mini`) |\n| (Optional) Ollama | latest | For local mode: `llama3.1`, `mistral`, or `qwen2.5` |\n\n\u003e ⚠️ Some models (like `llama3`) **cannot call functions**.\n\u003e Please use `llama3.1` or newer.\n\n---\n\n## 🚀 Quick start\n\n```powershell\n# 1. Clone the repo\ngit clone \u003crepo-url\u003e\ncd FoundryCommerceDemo\n\n# 2. Sign in to Azure\naz login\n\n# 3. Set the Foundry endpoint\n$env:FOUNDRY_PROJECT_ENDPOINT = \"https://\u003cyour-resource\u003e.services.ai.azure.com/api/projects/\u003cyour-project\u003e\"\n$env:FOUNDRY_MODEL_NAME       = \"gpt-4o-mini\"\n\n# 4. Build and run\ndotnet restore\ndotnet build\ndotnet run\n```\n\n---\n\n## 🔐 Azure setup (`az login` step by step)\n\n### 1. Install Azure CLI\n\n```powershell\n# Windows (winget)\nwinget install -e --id Microsoft.AzureCLI\n\n# macOS (brew)\nbrew update \u0026\u0026 brew install azure-cli\n\n# Linux\ncurl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash\n```\n\nCheck that it works:\n\n```powershell\naz --version\n```\n\n### 2. Sign in to Azure\n\n```powershell\naz login\n```\n\nA browser window opens. Sign in with your Microsoft account.\nThen go back to the terminal.\n\nIf you have more than one subscription, list all of them:\n\n```powershell\naz account list --output table\n```\n\nPick the subscription you want to use:\n\n```powershell\naz account set --subscription \"\u003csubscription-id-or-name\u003e\"\n```\n\nCheck the active subscription:\n\n```powershell\naz account show\n```\n\n### 3. Create a Microsoft Foundry project (if you don't have one)\n\n\u003e Foundry Portal: \u003chttps://foundry.azure.com\u003e\n\n1. Click **+ New project** → choose a name, region, and subscription.\n2. Open **Models** and deploy a model:\n   - 🟢 Fast and cheap: `gpt-4o-mini` or `gpt-4.1-mini`\n   - 🔵 More powerful: `gpt-4o`\n3. On the project page, copy the **Project endpoint**. It looks like this:\n\n   ```\n   https://\u003cresource-name\u003e.services.ai.azure.com/api/projects/\u003cproject-name\u003e\n   ```\n\n### 4. Give yourself the right role\n\nYour user (or managed identity) needs the **Azure AI User** role on the project:\n\n```powershell\n$user      = az ad signed-in-user show --query id -o tsv\n$projectId = \"/subscriptions/\u003csub-id\u003e/resourceGroups/\u003crg\u003e/providers/Microsoft.CognitiveServices/accounts/\u003cresource\u003e\"\n\naz role assignment create `\n  --assignee $user `\n  --role \"Azure AI User\" `\n  --scope $projectId\n```\n\n### 5. Test the connection\n\n```powershell\n$token = az account get-access-token --resource https://ai.azure.com --query accessToken -o tsv\ncurl -H \"Authorization: Bearer $token\" $env:FOUNDRY_PROJECT_ENDPOINT\n```\n\nIf you see `200 OK`, you are ready! ✅\n\n---\n\n## 🔧 Environment variables\n\n| Variable | What it is | Example |\n|----------|------------|---------|\n| `FOUNDRY_PROJECT_ENDPOINT` | The URL of your Foundry project | `https://admin-5418-resource.services.ai.azure.com/api/projects/admin-5418` |\n| `FOUNDRY_MODEL_NAME` | The name of your deployed model | `gpt-4o-mini` |\n\n### PowerShell (only this session)\n\n```powershell\n$env:FOUNDRY_PROJECT_ENDPOINT = \"https://\u003cyour-resource\u003e.services.ai.azure.com/api/projects/\u003cyour-project\u003e\"\n$env:FOUNDRY_MODEL_NAME       = \"gpt-4o-mini\"\n```\n\n### PowerShell (save for later)\n\n```powershell\n[Environment]::SetEnvironmentVariable(\"FOUNDRY_PROJECT_ENDPOINT\", \"https://...\", \"User\")\n[Environment]::SetEnvironmentVariable(\"FOUNDRY_MODEL_NAME\", \"gpt-4o-mini\", \"User\")\n```\n\n### Bash / Zsh\n\n```bash\nexport FOUNDRY_PROJECT_ENDPOINT=\"https://\u003cyour-resource\u003e.services.ai.azure.com/api/projects/\u003cyour-project\u003e\"\nexport FOUNDRY_MODEL_NAME=\"gpt-4o-mini\"\n```\n\n\u003e 💡 **Tip:** In Visual Studio you can also add these in `launchSettings.json`\n\u003e under `environmentVariables`.\n\n---\n\n## ▶️ How to run\n\n```powershell\ndotnet run\n```\n\nThe pipeline runs each demo order one by one:\n\n```\n+===================================================================+\n|   FOUNDRY — Enterprise E-Commerce Operations Center               |\n+===================================================================+\n\n  STEP 1: Fraud Detection .....................................\n  STEP 2: Fulfillment Optimization ............................\n  STEP 3: Customer Communication ..............................\n```\n\n---\n\n## 📁 Project structure\n\n```\nFoundryCommerceDemo/\n├── Program.cs                        # Entry point + pipeline\n├── FoundryCommerceDemo.csproj        # Project file (.NET 10)\n├── Models/\n│   └── Order.cs                      # Order, LineItem, WarehouseStock\n├── Data/\n│   ├── OrderDatabase.cs              # Demo orders + customer history\n│   └── WarehouseDatabase.cs          # Stock and shipping rates\n├── Tools/\n│   ├── FraudTools.cs                 # Geo + velocity + verdict\n│   ├── scoring/\n│   │   └── InventoryTools.cs         # Stock matrix, optimize, reserve\n│   └── split-shipment/\n│       └── CustomerTools.cs          # Customer email helpers\n└── Agents/\n    └── AgentDefinitions.cs           # Agent instructions\n```\n\n---\n\n## 🧪 Demo orders\n\n| Order | Customer | Total | What happens |\n|-------|----------|-------|--------------|\n| `ORD-50001` | Zeynep Arslan (Platinum) | $18,249 | ✅ APPROVED → split shipment (IST + FRA) |\n| `ORD-50002` | John Smith (Standard) | $11,599 | 🚫 BLOCKED — country mismatch + too many orders + GPUs |\n| `ORD-50003` | Maria Gonzalez (Gold) | $8,219 | ⚠️ APPROVED → smart stock plan |\n\n### The \"wow\" moment — `ORD-50002`\n\n- 💳 Card from: 🇺🇸 USA\n- 🌐 IP from: 🇷🇴 Romania\n- 📦 Ship to: 🇳🇬 Nigeria\n- 🛒 **7 orders** in the last 24 hours + new device\n- 🎮 4x RTX 5090 GPUs + a throwaway email\n- → **Risk: CRITICAL → BLOCKED**\n- The `CustomerAgent` writes a polite \"we need more info\" email.\n  It does **not** mention the fraud reasons. ✨\n\n---\n\n## 🏠 Local mode (Ollama)\n\nDo you want payment data to stay on your computer? (Good for PCI-DSS.)\n\n```powershell\n# 1. Install Ollama\nwinget install -e --id Ollama.Ollama\n# or download from: https://ollama.com/download\n\n# 2. Start the service\nollama serve\n\n# 3. Pull a model that supports function calling\nollama pull llama3.1\n```\n\nIn `Program.cs`, uncomment the local mode block and run again.\nThe same `Tools` and `Agents` code works — only the \"brain\" changes.\n\n---\n\n## 🩺 Troubleshooting\n\n| Error | Reason | Fix |\n|-------|--------|-----|\n| `AuthenticationFailedException` | Token is expired | Run `az login` again |\n| `404 — Model not found` | Model is not deployed | Foundry Portal → Models → deploy a model |\n| `429 — Rate limited` | Too many requests | Wait 60 seconds or ask for more quota |\n| `Insufficient permissions` | Missing role | Add the `Azure AI User` role |\n| `Connection refused (Ollama)` | Ollama is not running | Run `ollama serve` in another terminal |\n| `Wrong endpoint format` | Bad URL | Use `https://\u003cresource\u003e.services.ai.azure.com/api/projects/\u003cproject\u003e` |\n\n### Quick check commands\n\n```powershell\naz account show                       # Check Azure login\ndotnet list package                   # See package versions\ndotnet clean; dotnet build            # Clean and rebuild\ncurl http://localhost:11434/api/tags  # Check Ollama\n```\n\n---\n\n## 📚 Resources\n\n- [Microsoft Foundry Portal](https://foundry.azure.com)\n- [Agent Framework on GitHub](https://github.com/microsoft/agent-framework)\n- [Agent Framework Samples](https://github.com/microsoft/Agent-Framework-Samples)\n- [Learn Docs — Overview](https://learn.microsoft.com/agent-framework/overview/)\n- [Learn Docs — Workflows](https://learn.microsoft.com/agent-framework/workflows/)\n\n---\n\n## 📄 License\n\nThis demo is made for the **DOTNET Conference** talk. It is for learning only.\n\n- All company names, customer names, and order data are **fictional**.\n- The fraud detection logic is **simplified** for the demo.\n  Please do **not** use it in production.\n\n---\n\n\u003csub\u003eBuilt with Microsoft Agent Framework v1.0 — a unified SDK for enterprise AI agents.\nPresented at DOTNET Conference · 7 May 2026 · Sheraton Grand Istanbul Hotel.\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkardelruveyda%2Ffoundry-commerce-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkardelruveyda%2Ffoundry-commerce-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkardelruveyda%2Ffoundry-commerce-demo/lists"}