An open API service indexing awesome lists of open source software.

https://github.com/kardelruveyda/foundry-commerce-demo

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#.
https://github.com/kardelruveyda/foundry-commerce-demo

azure-ai csharp demo dotnet microsoft-agent-framework microsoft-foundry net10

Last synced: about 1 month ago
JSON representation

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#.

Awesome Lists containing this project

README

          

# ๐Ÿ›’ FoundryCommerceDemo

> **Enterprise E-Commerce Operations Center โ€” Multi-Agent Demo**
> Built with Microsoft Agent Framework v1.0 + Microsoft Foundry.
> A simple end-to-end pipeline:
> fraud check โ†’ inventory โ†’ fulfillment โ†’ customer email.

[![.NET](https://img.shields.io/badge/.NET-10.0-512BD4?logo=dotnet)](https://dotnet.microsoft.com/)
[![Agent Framework](https://img.shields.io/badge/Agent%20Framework-v1.3-0078D4)](https://github.com/microsoft/agent-framework)
[![Foundry](https://img.shields.io/badge/Microsoft-Foundry-2560E0)](https://foundry.azure.com)

---

## ๐Ÿ“– Table of Contents

1. [What is this?](#-what-is-this)
2. [Architecture](#-architecture)
3. [Hosting model โ€” this is a LOCAL agent demo](#-hosting-model--this-is-a-local-agent-demo)
4. [Other hosting options](#-other-hosting-options)
5. [What you need](#-what-you-need)
6. [Quick start](#-quick-start)
7. [Azure setup (`az login` step by step)](#-azure-setup-az-login-step-by-step)
8. [Environment variables](#-environment-variables)
9. [How to run](#-how-to-run)
10. [Project structure](#-project-structure)
11. [Demo orders](#-demo-orders)
12. [Local mode (Ollama)](#-local-mode-ollama)
13. [Troubleshooting](#-troubleshooting)
14. [License](#-license)

---

## ๐ŸŽฏ What is this?

This demo shows an online shop. When a new order comes in, **four AI agents**
work together like a team:

| Agent | What it does |
|-------|--------------|
| ๐Ÿ›ก๏ธ **FraudDetectionAgent** | Looks for risky orders. Checks the country, the device, and how many orders the customer made today. |
| ๐Ÿ“ฆ **InventoryAgent** | Checks if the products are in stock. Looks at all warehouses. Can reserve items. |
| ๐Ÿšš **FulfillmentAgent** | Picks the best warehouse. Calculates shipping cost. Can split the order if needed. |
| ๐Ÿ’ฌ **CustomerAgent** | Writes a nice email to the customer. Never shares secret data (like fraud scores). |

### Why is this cool?

- โœ… **Real C# code** does the math. The AI does **not** invent numbers.
- โœ… **Multiple warehouses** with real stock data.
- โœ… **Split shipments** when one warehouse is not enough.
- โœ… **Agent-as-a-tool**: one agent can use another agent like a function.
- โœ… **Local mode**: payment data stays on your computer (good for PCI-DSS).

---

## ๐Ÿ  Hosting model โ€” this is a **LOCAL agent demo**

> **Important:** In this repo the agents run **on your computer**, not in the cloud.
> Microsoft Foundry is used **only as the LLM gateway** (model + auth + project scope).
> All agent logic, tools, and state live inside your local `dotnet run` process.

### ๐Ÿ“ Architecture diagrams

| Scenario | SVG (preview) | draw.io (editable) |
|----------|---------------|--------------------|
| ๐Ÿ  **Local agents** (this repo) | _inline below_ | โ€” |
| โ˜๏ธ **Option 1 โ€” Container Apps** | [option2-container-apps.svg](docs/architecture/option2-container-apps.svg) | [.drawio](docs/architecture/option2-container-apps.drawio) |
| ๐Ÿ—๏ธ **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) |
| ๐Ÿ“– 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) |
| ๐Ÿค– 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) |
| โฑ๏ธ **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) |

### What runs where?

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ YOUR MACHINE (dotnet run) โ”‚
โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Pipeline orchestrator (Program.cs) โ”‚ โ”‚
โ”‚ โ”‚ โ”œโ”€ FraudDetectionAgent โ”‚ โ”‚
โ”‚ โ”‚ โ”œโ”€ InventoryAgent โ”‚ โ”‚
โ”‚ โ”‚ โ”œโ”€ FulfillmentAgent โ”‚ โ”‚
โ”‚ โ”‚ โ””โ”€ CustomerAgent โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ Tools = your C# code (FraudTools.cs etc.)โ”‚ โ”‚
โ”‚ โ”‚ State = in-memory (OrderDatabase) โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ HTTPS
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Microsoft Foundry โ”‚
โ”‚ โ€ข gpt-4o-mini model โ”‚ โ† only LLM calls go here
โ”‚ โ€ข DefaultAzureCredential
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### What Foundry does (in this demo)

| # | Feature | Used? | Notes |
|---|---------|:-----:|-------|
| ๐Ÿง  Model hosting | โœ… | `gpt-4o-mini` |
| ๐Ÿ” Authentication | โœ… | `DefaultAzureCredential` + `az login` (no API keys) |
| ๐Ÿ“ฆ Project scope | โœ… | One project for billing, quota, monitoring |
| ๐Ÿค– Foundry Agent Service (cloud-hosted agents) | โŒ | Agents are local |
| ๐Ÿ’ฌ Threads / conversation history | โŒ | Not persisted |
| ๐Ÿ“š Vector stores / file search | โŒ | Not used |
| ๐Ÿ”’ Content safety filters | โŒ | Not configured |
| ๐Ÿ“Š Tracing / evaluation | โŒ | Add OpenTelemetry to enable |

### Why this design?

- ๐Ÿš€ **Fast** to demo โ€” no deployment needed.
- ๐Ÿ’ฐ **Cheap** โ€” you only pay for LLM tokens.
- ๐Ÿงช **Easy to debug** โ€” set breakpoints in Visual Studio.
- ๐ŸŽค **Great for talks** โ€” everything visible on stage.

### Limitations of running locally

- โŒ No state persistence โ€” process restart wipes everything.
- โŒ Single user only.
- โŒ No autoscale.
- โŒ Not production-ready as-is.

๐Ÿ‘‰ If you need any of those, see the next section.

---

## โ˜๏ธ Other hosting options

Foundry can host much more than just the model. Here are **three ways** to move
the agents to the cloud, from least to most cloud-native.

### Comparison at a glance

| Option | Code change | State persistence | Multi-user | Scale-to-zero | Best for |
|--------|:-----------:|:-----------------:|:----------:|:-------------:|----------|
| ๐Ÿ  **Local** (this repo) | โ€” | โŒ | โŒ | โ€” | Demos, dev loop |
| โ˜๏ธ **Container Apps** | Small | โŒ (add Cosmos DB) | โœ… | โœ… | Most teams |
| ๐Ÿค– **Foundry Agent Service** | Medium | โœ… Auto | โœ… | โœ… | Cloud-first agents |
| โฑ๏ธ **Durable Functions** | Medium | โœ… Auto | โœ… | โœ… | Long-running workflows |

---

### Option 1 โ€” Azure Container Apps (recommended next step)

Wrap the same .NET 10 code in an ASP.NET Core API and deploy to a serverless
container runtime. Your agent code does **not** change โ€” only `Program.cs`
becomes a web app.

๐Ÿ“ **Architecture diagram:**
[`docs/architecture/option2-container-apps.svg`](docs/architecture/option2-container-apps.svg)
ยท editable [`.drawio`](docs/architecture/option2-container-apps.drawio)

**Topology:**

```
Client โ†’ Front Door / APIM โ†’ Container Apps (foundry-commerce-api)
โ”œโ”€ pulls image from ACR
โ”œโ”€ uses Managed Identity โ†’ Foundry (LLM)
โ”œโ”€ logs to App Insights
โ””โ”€ stores data in Cosmos DB / Service Bus
```

**Sketch of the code:**

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSingleton(sp =>
new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential()));

var app = builder.Build();

app.MapPost("/api/orders/{orderId}/process", async (string orderId, AIProjectClient client) =>
{
var fraudAgent = client.AsAIAgent(
model: "gpt-4o-mini",
instructions: "...",
tools: [...]);

var result = await fraudAgent.RunAsync($"Process order {orderId}");
return Results.Ok(result);
});

app.Run();
```

**Deploy:**

```powershell
az containerapp up `
--name foundry-commerce-api `
--resource-group rg-demo `
--location swedencentral `
--source .
```

or with Azure Developer CLI:

```powershell
azd up
```

**Pros**
- โœ… Minimal code changes.
- โœ… Scale-to-zero (you pay $0 when idle).
- โœ… Managed Identity โ†’ no secrets in code.
- โœ… HTTPS endpoint, custom domains, revisions, blue/green deploys.

**Cons**
- โŒ You still manage state yourself (add Cosmos DB or SQL).
- โŒ Threads/conversations are not built-in.

---

### Option 2 โ€” Microsoft Foundry **Agent Service** (cloud-hosted agents)

Let Foundry host the agent itself. Tool definitions, instructions, and
conversation threads all live in the cloud. Your code calls the agent and
responds to tool-call requests.

๐Ÿ—๏ธ **Azure architecture (production-ready resource topology):**
[`docs/architecture/option3-foundry-agent-service-azure.svg`](docs/architecture/option3-foundry-agent-service-azure.svg)
ยท editable [`.drawio`](docs/architecture/option3-foundry-agent-service-azure.drawio)

This is the **โ€œwhat do I deploy?โ€** view. It shows real Azure resources, resource
groups, networking, identity, and data services laid out the way they would look
in production.

**Resource groups in the diagram:**

| RG | Color | Contents |
|----|-------|----------|
| `rg-foundrycommerce-app` | ๐ŸŸฉ Green | Container Apps (api + worker), ACR, UAMI, Key Vault, App Configuration, Service Bus |
| `rg-foundrycommerce-foundry` | ๐ŸŸง Orange | Foundry Hub + Project, PersistentAgents, Threads/Runs, model deployments, vector store, content safety |
| `rg-foundrycommerce-data` | ๐ŸŸช Purple | Cosmos DB (NoSQL), Azure SQL, Storage Account, Azure Managed Redis |

**Cross-cutting concerns (shown on the side):**

- ๐Ÿ†” **Microsoft Entra ID** โ†’ issues tokens to a User-Assigned Managed Identity. **No API keys anywhere.**
- ๐Ÿ” **VNet** (`vnet-foundry-prod`) with private endpoints for Key Vault, ACR, Cosmos DB, Storage, Foundry.
- ๐Ÿ›ก๏ธ **Edge** โ€” Front Door + WAF + API Management + DDoS Protection.
- ๐Ÿ“Š **Observability** โ€” Application Insights, Log Analytics, Azure Monitor, Foundry built-in tracing, Defender for Cloud.

**Run lifecycle (numbered arrows on the diagram):**

| # | Color | What happens |
|---|-------|--------------|
| โ‘  | ๐ŸŸง Orange | Container App calls `Runs.CreateRunAsync` on Foundry Agent Service |
| โ‘ก | ๐ŸŸช Purple | Foundry replies with `requires_action` โ†’ โ€œcall tool Xโ€ |
| โ‘ข | ๐ŸŸฉ Green | Container App runs the C# tool and posts back via `SubmitToolOutputsAsync` |

For a step-by-step **run lifecycle** explanation (story-style), see
[`option3-foundry-agent-service-detailed.svg`](docs/architecture/option3-foundry-agent-service-detailed.svg).
For a single-page **compact overview**, see
[`option3-foundry-agent-service.svg`](docs/architecture/option3-foundry-agent-service.svg).

**Topology:**

```
Client โ†’ Container Apps (thin API)
โ”‚ โ‘  start run
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Microsoft Foundry โ€” Agent Service โ”‚
โ”‚ โ€ข PersistentAgents (definitions) โ”‚
โ”‚ โ€ข Threads + Runs (auto-saved state) โ”‚
โ”‚ โ€ข Vector store (optional, RAG) โ”‚
โ”‚ โ€ข Model deployment (gpt-4o-mini) โ”‚
โ”‚ โ€ข Built-in safety + tracing โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ โ‘ก "call tool X"
โ–ผ
Container Apps tool handler โ†’ runs C# in your code
โ”‚ โ‘ข returns tool result
โ–ผ
Foundry continues the run โ†’ โ‘ฃ final reply
```

**Run lifecycle (4 steps):**

| # | Who | What happens |
|---|-----|--------------|
| โ‘  | Your API | `Runs.CreateRunAsync(thread, agent)` |
| โ‘ก | Foundry | Sends a `requires_action` event with tool name + args |
| โ‘ข | Your API | Runs the C# tool, posts result back via `SubmitToolOutputsAsync` |
| โ‘ฃ | Foundry | Continues reasoning, returns the final assistant message |

> ๐Ÿ’ก Foundry stores **conversation data** (threads, runs, tool calls).
> Your backend stores **business data** (orders, warehouses) in Cosmos DB / SQL.

**Sketch:**

```csharp
using Azure.AI.Agents.Persistent;

var agentsClient = new PersistentAgentsClient(endpoint, credential);

// 1. Create the agent in Foundry (once)
var agent = await agentsClient.Administration.CreateAgentAsync(
model: "gpt-4o-mini",
name: "FraudDetectionAgent",
instructions: "You analyze fraud risk...",
tools: [
new FunctionToolDefinition(
name: "AnalyzeGeoConsistency",
description: "Checks geographic consistency",
parameters: BinaryData.FromString("""
{ "type": "object", "properties": {
"orderId": { "type": "string" }
}}
"""))
]);

// 2. Create a conversation thread
var thread = await agentsClient.Threads.CreateThreadAsync();

// 3. Send a message and run
await agentsClient.Messages.CreateMessageAsync(
thread.Id, MessageRole.User, "Check ORD-50002");
var run = await agentsClient.Runs.CreateRunAsync(thread.Id, agent.Id);
```

**What Foundry stores for you**
- โœ… Agent definition (tools, instructions, model)
- โœ… Thread history (every conversation)
- โœ… Run state (resumable if your code crashes)
- โœ… Tool call audit trail

**Pros**
- โœ… Automatic state, threads, history.
- โœ… Built-in safety, evaluation, tracing in Foundry portal.
- โœ… You only host the **tool execution** (a webhook or function).

**Cons**
- โŒ More refactoring โ€” moves agent definition out of C#.
- โŒ Slightly higher cost (storage + agent runtime).

---

### Option 3 โ€” Azure Durable Functions (long-running workflows)

Use this if your pipeline can take **hours or days** (e.g. waits for a manager
approval, retries failed shipments, cross-day reconciliation).

**Sketch:**

```csharp
[Function(nameof(OrderPipeline))]
public async Task OrderPipeline(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
var orderId = context.GetInput();

// Step 1: fraud check
var verdict = await context.CallActivityAsync(
nameof(RunFraudAgent), orderId);

if (verdict == "BLOCKED")
return await context.CallActivityAsync(
nameof(SendBlockEmail), orderId);

// Step 2: wait up to 24h for human approval
var approved = await context.WaitForExternalEvent(
"ManagerApproval", TimeSpan.FromHours(24));

// Step 3: fulfillment
return await context.CallActivityAsync(
nameof(RunFulfillmentAgent), orderId);
}
```

**Pros**
- โœ… State and progress are checkpointed automatically.
- โœ… Survives restarts, scale-out, and long waits.
- โœ… Perfect for human-in-the-loop steps.

**Cons**
- โŒ More moving parts (Functions runtime, storage account).
- โŒ Steeper learning curve than Container Apps.

---

### Which option should you pick?

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Do agents need to keep โ”‚
โ”‚ state across requests? โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
No โ”‚ โ”‚ Yes
โ–ผ โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Container โ”‚ โ”‚ Pipeline can take โ”‚
โ”‚ Apps โ”‚ โ”‚ hours / human waits? โ”‚
โ”‚ (Option 1) โ”‚ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ No โ”‚ โ”‚ Yes
โ–ผ โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Foundry Agent โ”‚ โ”‚ Durable โ”‚
โ”‚ Service โ”‚ โ”‚ Functions โ”‚
โ”‚ (Option 2) โ”‚ โ”‚ (Option 3) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

**Rule of thumb for this demo:** start with Container Apps. It is the smallest
jump from the local code in this repo and covers ~80% of real-world needs.

---

## ๐Ÿ—๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ NEW ORDER โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ FraudDetectionAgent โ”‚
โ”‚ โ€ข Geo check โ”‚
โ”‚ โ€ข Velocity check โ”‚
โ”‚ โ€ข Final verdict โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ–ผ BLOCKED โ–ผ APPROVED
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ CustomerAgent โ”‚ โ”‚ FulfillmentAgent โ”‚
โ”‚ writes a polite โ”‚ โ”‚ uses โ†“ as a tool โ”‚
โ”‚ "we need more โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ info" email. โ”‚ โ”‚ โ”‚ InventoryAgent โ”‚ โ”‚
โ”‚ No secret data. โ”‚ โ”‚ โ”‚ โ€ข CheckStock โ”‚ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ€ข Optimize โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Reserve โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ CustomerAgent โ”‚
โ”‚ writes a thank-you โ”‚
โ”‚ email with the ETA. โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

## ๐Ÿงฐ What you need

| Tool | Version | Note |
|------|---------|------|
| .NET SDK | **10.0** (8.0+ also works) | Check with `dotnet --version` |
| Azure CLI | latest | Check with `az --version` |
| Visual Studio 2022/2026 or VS Code | โ€” | C# Dev Kit is helpful |
| Microsoft Foundry project | โ€” | One model must be deployed (e.g. `gpt-4o-mini`) |
| (Optional) Ollama | latest | For local mode: `llama3.1`, `mistral`, or `qwen2.5` |

> โš ๏ธ Some models (like `llama3`) **cannot call functions**.
> Please use `llama3.1` or newer.

---

## ๐Ÿš€ Quick start

```powershell
# 1. Clone the repo
git clone
cd FoundryCommerceDemo

# 2. Sign in to Azure
az login

# 3. Set the Foundry endpoint
$env:FOUNDRY_PROJECT_ENDPOINT = "https://.services.ai.azure.com/api/projects/"
$env:FOUNDRY_MODEL_NAME = "gpt-4o-mini"

# 4. Build and run
dotnet restore
dotnet build
dotnet run
```

---

## ๐Ÿ” Azure setup (`az login` step by step)

### 1. Install Azure CLI

```powershell
# Windows (winget)
winget install -e --id Microsoft.AzureCLI

# macOS (brew)
brew update && brew install azure-cli

# Linux
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
```

Check that it works:

```powershell
az --version
```

### 2. Sign in to Azure

```powershell
az login
```

A browser window opens. Sign in with your Microsoft account.
Then go back to the terminal.

If you have more than one subscription, list all of them:

```powershell
az account list --output table
```

Pick the subscription you want to use:

```powershell
az account set --subscription ""
```

Check the active subscription:

```powershell
az account show
```

### 3. Create a Microsoft Foundry project (if you don't have one)

> Foundry Portal:

1. Click **+ New project** โ†’ choose a name, region, and subscription.
2. Open **Models** and deploy a model:
- ๐ŸŸข Fast and cheap: `gpt-4o-mini` or `gpt-4.1-mini`
- ๐Ÿ”ต More powerful: `gpt-4o`
3. On the project page, copy the **Project endpoint**. It looks like this:

```
https://.services.ai.azure.com/api/projects/
```

### 4. Give yourself the right role

Your user (or managed identity) needs the **Azure AI User** role on the project:

```powershell
$user = az ad signed-in-user show --query id -o tsv
$projectId = "/subscriptions//resourceGroups//providers/Microsoft.CognitiveServices/accounts/"

az role assignment create `
--assignee $user `
--role "Azure AI User" `
--scope $projectId
```

### 5. Test the connection

```powershell
$token = az account get-access-token --resource https://ai.azure.com --query accessToken -o tsv
curl -H "Authorization: Bearer $token" $env:FOUNDRY_PROJECT_ENDPOINT
```

If you see `200 OK`, you are ready! โœ…

---

## ๐Ÿ”ง Environment variables

| Variable | What it is | Example |
|----------|------------|---------|
| `FOUNDRY_PROJECT_ENDPOINT` | The URL of your Foundry project | `https://admin-5418-resource.services.ai.azure.com/api/projects/admin-5418` |
| `FOUNDRY_MODEL_NAME` | The name of your deployed model | `gpt-4o-mini` |

### PowerShell (only this session)

```powershell
$env:FOUNDRY_PROJECT_ENDPOINT = "https://.services.ai.azure.com/api/projects/"
$env:FOUNDRY_MODEL_NAME = "gpt-4o-mini"
```

### PowerShell (save for later)

```powershell
[Environment]::SetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT", "https://...", "User")
[Environment]::SetEnvironmentVariable("FOUNDRY_MODEL_NAME", "gpt-4o-mini", "User")
```

### Bash / Zsh

```bash
export FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/"
export FOUNDRY_MODEL_NAME="gpt-4o-mini"
```

> ๐Ÿ’ก **Tip:** In Visual Studio you can also add these in `launchSettings.json`
> under `environmentVariables`.

---

## โ–ถ๏ธ How to run

```powershell
dotnet run
```

The pipeline runs each demo order one by one:

```
+===================================================================+
| FOUNDRY โ€” Enterprise E-Commerce Operations Center |
+===================================================================+

STEP 1: Fraud Detection .....................................
STEP 2: Fulfillment Optimization ............................
STEP 3: Customer Communication ..............................
```

---

## ๐Ÿ“ Project structure

```
FoundryCommerceDemo/
โ”œโ”€โ”€ Program.cs # Entry point + pipeline
โ”œโ”€โ”€ FoundryCommerceDemo.csproj # Project file (.NET 10)
โ”œโ”€โ”€ Models/
โ”‚ โ””โ”€โ”€ Order.cs # Order, LineItem, WarehouseStock
โ”œโ”€โ”€ Data/
โ”‚ โ”œโ”€โ”€ OrderDatabase.cs # Demo orders + customer history
โ”‚ โ””โ”€โ”€ WarehouseDatabase.cs # Stock and shipping rates
โ”œโ”€โ”€ Tools/
โ”‚ โ”œโ”€โ”€ FraudTools.cs # Geo + velocity + verdict
โ”‚ โ”œโ”€โ”€ scoring/
โ”‚ โ”‚ โ””โ”€โ”€ InventoryTools.cs # Stock matrix, optimize, reserve
โ”‚ โ””โ”€โ”€ split-shipment/
โ”‚ โ””โ”€โ”€ CustomerTools.cs # Customer email helpers
โ””โ”€โ”€ Agents/
โ””โ”€โ”€ AgentDefinitions.cs # Agent instructions
```

---

## ๐Ÿงช Demo orders

| Order | Customer | Total | What happens |
|-------|----------|-------|--------------|
| `ORD-50001` | Zeynep Arslan (Platinum) | $18,249 | โœ… APPROVED โ†’ split shipment (IST + FRA) |
| `ORD-50002` | John Smith (Standard) | $11,599 | ๐Ÿšซ BLOCKED โ€” country mismatch + too many orders + GPUs |
| `ORD-50003` | Maria Gonzalez (Gold) | $8,219 | โš ๏ธ APPROVED โ†’ smart stock plan |

### The "wow" moment โ€” `ORD-50002`

- ๐Ÿ’ณ Card from: ๐Ÿ‡บ๐Ÿ‡ธ USA
- ๐ŸŒ IP from: ๐Ÿ‡ท๐Ÿ‡ด Romania
- ๐Ÿ“ฆ Ship to: ๐Ÿ‡ณ๐Ÿ‡ฌ Nigeria
- ๐Ÿ›’ **7 orders** in the last 24 hours + new device
- ๐ŸŽฎ 4x RTX 5090 GPUs + a throwaway email
- โ†’ **Risk: CRITICAL โ†’ BLOCKED**
- The `CustomerAgent` writes a polite "we need more info" email.
It does **not** mention the fraud reasons. โœจ

---

## ๐Ÿ  Local mode (Ollama)

Do you want payment data to stay on your computer? (Good for PCI-DSS.)

```powershell
# 1. Install Ollama
winget install -e --id Ollama.Ollama
# or download from: https://ollama.com/download

# 2. Start the service
ollama serve

# 3. Pull a model that supports function calling
ollama pull llama3.1
```

In `Program.cs`, uncomment the local mode block and run again.
The same `Tools` and `Agents` code works โ€” only the "brain" changes.

---

## ๐Ÿฉบ Troubleshooting

| Error | Reason | Fix |
|-------|--------|-----|
| `AuthenticationFailedException` | Token is expired | Run `az login` again |
| `404 โ€” Model not found` | Model is not deployed | Foundry Portal โ†’ Models โ†’ deploy a model |
| `429 โ€” Rate limited` | Too many requests | Wait 60 seconds or ask for more quota |
| `Insufficient permissions` | Missing role | Add the `Azure AI User` role |
| `Connection refused (Ollama)` | Ollama is not running | Run `ollama serve` in another terminal |
| `Wrong endpoint format` | Bad URL | Use `https://.services.ai.azure.com/api/projects/` |

### Quick check commands

```powershell
az account show # Check Azure login
dotnet list package # See package versions
dotnet clean; dotnet build # Clean and rebuild
curl http://localhost:11434/api/tags # Check Ollama
```

---

## ๐Ÿ“š Resources

- [Microsoft Foundry Portal](https://foundry.azure.com)
- [Agent Framework on GitHub](https://github.com/microsoft/agent-framework)
- [Agent Framework Samples](https://github.com/microsoft/Agent-Framework-Samples)
- [Learn Docs โ€” Overview](https://learn.microsoft.com/agent-framework/overview/)
- [Learn Docs โ€” Workflows](https://learn.microsoft.com/agent-framework/workflows/)

---

## ๐Ÿ“„ License

This demo is made for the **DOTNET Conference** talk. It is for learning only.

- All company names, customer names, and order data are **fictional**.
- The fraud detection logic is **simplified** for the demo.
Please do **not** use it in production.

---

Built with Microsoft Agent Framework v1.0 โ€” a unified SDK for enterprise AI agents.
Presented at DOTNET Conference ยท 7 May 2026 ยท Sheraton Grand Istanbul Hotel.