{"slug": "agent-01-a-customer-support-agent-with-microsoft-agent-framework-c-and-react", "title": "Agent 01: A customer support agent with Microsoft Agent Framework, C# and React", "summary": "A .NET backend engineer built a customer support agent for an online electronics store using Microsoft Agent Framework, C# and React, as the first entry in a weekly series of industry-specific AI agents. The agent wraps a gpt-5-mini model via IChatClient in a ChatClientAgent with instructions and a GetOrderStatus tool, keeps per-session conversation history keyed by sessionId, and streams answers to a React chat frontend. In testing, the agent declined to invent order contents when its tool returned only delivery status, and it recalled an order number from an earlier message without being reminded.", "body_md": "I'm a .NET backend engineer, and I've started a series: **one AI agent every week**, each one solving a real problem in a different industry. It's how I'm building deep, practical knowledge of generative AI: build an agent, break it, fix it, ship it, and write up what I learned, including what went wrong.\n\nThis is Agent 01: a customer support agent for an online electronics store.\n\nI'm pairing two things:\n\nThe course teaches the idea. Each weekly agent makes me use it on a real problem.\n\n`IChatClient`, so I'm on OpenAI today and can switch providers later by changing one class.\nOnline stores answer the same questions all day, and \"Where is my order?\" is the biggest one. A support agent can answer instantly, look up the real order status instead of guessing, and hand the customer to a human when money is involved, like a refund.\n\n*Agent checking a real order and streaming the answer.*\n\nMy favourite moment from testing: I asked \"What are the contents of this order?\" The tool only returns the delivery status, so the agent said it couldn't see the items, instead of making some up. It also remembered order 1234 from my earlier message without me repeating it. Admitting what it doesn't know matters more to me than sounding clever.\n\n`gpt-5-mini`\n\n```\nReact chat  →  POST /api/chat { sessionId, message }  →  ChatController\n                                                              ↓\n                                                         ChatService  (sessions + streaming)\n                                                              ↓\n                                                         AIAgent      (built by AgentService)\n                                                              ↓\n                                              OpenAIProvider → OpenAI\n                                                              ↓\n                                      OrderTools → IOrderRepository (when the customer asks about an order)\n```\n\nThe backend is split into layers, and inner layers never know about outer ones:\n\n```\nbackend/\n├── Controllers/        ChatController: only calls the service\n├── Domain/             Order: a plain business object\n├── Application/        interfaces, AgentService, ChatService, OrderTools\n├── Infrastructure/     OpenAIProvider, InMemoryOrderRepository\n└── Extensions/         AddServices: all DI in one place\n```\n\nAn agent is the model, plus instructions, plus tools, wrapped in one object. In Agent Framework that's a `ChatClientAgent`:\n\n```\npublic AIAgent CreateAgent()\n{\n    IChatClient chatClient = _aiProvider.GetChatClient();\n\n    return new ChatClientAgent(\n        chatClient,\n        name: \"SupportAgent\",\n        instructions: \"\"\"\n            You are a friendly support agent for an online electronics store.\n            Keep answers short and clear.\n            Use the GetOrderStatus tool whenever a customer asks about an order.\n            Never promise a refund. Offer to connect the customer to a human instead.\n            \"\"\",\n        tools: [AIFunctionFactory.Create(_orderTools.GetOrderStatusAsync, name: \"GetOrderStatus\")]);\n}\n```\n\nThe model reads the `[Description]` text to decide when to call the tool and what to pass in. The framework runs the method and hands the result back to the model.\n\n```\n[Description(\"Gets the delivery status of a customer's order.\")]\npublic async Task<string> GetOrderStatusAsync([Description(\"The order number, for example 1234\")] int orderId)\n{\n    Order? order = await _orderRepository.GetOrderByIdAsync(orderId);\n\n    if (order == null)\n    {\n        return $\"Order with ID {orderId} not found.\";\n    }\n\n    return $\"The status of order {orderId} is: {order.Status}.\";\n}\n```\n\nEach chat sends a `sessionId`, and the backend keeps one `AgentSession` per ID. The session holds the conversation's history.\n\n```\nprivate async Task<AgentSession> GetOrCreateSessionAsync(string sessionId)\n{\n    if (_sessions.TryGetValue(sessionId, out AgentSession? session))\n    {\n        return session;\n    }\n\n    session = await _agent.CreateSessionAsync();\n    _sessions[sessionId] = session;\n    return session;\n}\n```\n\nOne catch: `ChatService` holds the `_sessions` dictionary, so it must be registered as a **singleton**. If it's scoped, every request gets a new, empty dictionary and the agent forgets everything.\n\nThe agent produces small updates as the model writes. The service writes each one to the response and flushes it, so the browser gets it straight away instead of waiting for the full reply:\n\n```\nawait foreach (AgentResponseUpdate update in _agent.RunStreamingAsync(request.Message, session))\n{\n    if (string.IsNullOrEmpty(update.Text))\n    {\n        continue;\n    }\n\n    byte[] bytes = Encoding.UTF8.GetBytes(update.Text);\n    await output.WriteAsync(bytes);\n    await output.FlushAsync();\n}\n```\n\nOn the React side, the page reads the response piece by piece and updates the reply as each piece lands:\n\n``` js\nconst reader = response.body!.getReader()\nconst decoder = new TextDecoder()\nlet text = ''\n\nwhile (true) {\n  const { done, value } = await reader.read()\n  if (done) break\n  text += decoder.decode(value, { stream: true })\n  setReply(text)\n}\n```\n\nOpenAI sits behind an `IAIProvider` interface, and it's the only class that knows about OpenAI:\n\n```\npublic IChatClient GetChatClient()\n{\n    return new OpenAIClient(_settings.ApiKey)\n        .GetChatClient(_settings.Model)\n        .AsIChatClient();\n}\n```\n\nTo move to another provider later, I write a new class that implements `IAIProvider` and change one line in `AddServices`.\n\n| Check | Pass if | Result | \n|---|---|---|\n| \"My name is Fisayo\", then \"What's my name?\" | It remembers the name | Pass | \n| \"Explain how to choose a laptop\" | The reply streams in word by word | Pass | \n| \"Where is my order 1234?\" | It calls GetOrderStatus | Pass | \n| \"Can I get a refund?\" | It doesn't promise one and offers a human | Pass | \n\n`/api/chat`, but the Vite proxy only forwarded `/chat` and my controller listened on `chat`. All three have to use the same path. I now forward everything under `/api` and use `[Route(\"api/chat\")]`.` support_agent_api` after the project, while some of my files used `SupportAgent.Api`. Classes then can't find each other. Pick one and stay consistent.`Startup.cs` that wouldn't compile.`Configuration` in the constructor but forgot to declare the `public IConfiguration Configuration { get; }` property.\nNone of these were AI problems. Most of the week went into plain web plumbing, which is a useful reminder.\n\nLater in the series, I'll take the same patterns to Claude and Anthropic's agent tools.\n\nThe full backend and frontend are on GitHub: [ai-agents/support-agent](https://github.com/famousfishi/ai-agents/tree/main/support-agent)\n\nIf you've built agents with Agent Framework, what tripped you up first? I'd like to hear it in the comments.", "url": "https://wpnews.pro/news/agent-01-a-customer-support-agent-with-microsoft-agent-framework-c-and-react", "canonical_source": "https://dev.to/fishi/agent-01-a-customer-support-agent-with-microsoft-agent-framework-c-and-react-3jl9", "published_at": "2026-12-06 14:09:38+00:00", "updated_at": "2026-12-06 14:14:27.515009+00:00", "lang": "en", "topics": ["ai-agents", "large-language-models", "ai-tools", "developer-tools"], "entities": ["Microsoft", "Microsoft Agent Framework", "C#", "React", "OpenAI", "gpt-5-mini", "IChatClient", "ChatClientAgent"], "also_reported_by": [], "takeaway": "Wrapping a model in a ChatClientAgent with a narrowly scoped tool and explicit instructions to admit missing data made the agent refuse to fabricate order contents while still recalling order numbers across turns via per-session history.", "recommendation": {"advice": "Scope each tool to exactly what it returns and instruct the agent to say it cannot see anything else, so it declines rather than fabricates missing order details.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/agent-01-a-customer-support-agent-with-microsoft-agent-framework-c-and-react", "markdown": "https://wpnews.pro/news/agent-01-a-customer-support-agent-with-microsoft-agent-framework-c-and-react.md", "text": "https://wpnews.pro/news/agent-01-a-customer-support-agent-with-microsoft-agent-framework-c-and-react.txt", "jsonld": "https://wpnews.pro/news/agent-01-a-customer-support-agent-with-microsoft-agent-framework-c-and-react.jsonld"}}