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.
This is Agent 01: a customer support agent for an online electronics store.
I'm pairing two things:
The course teaches the idea. Each weekly agent makes me use it on a real problem.
IChatClient, so I'm on OpenAI today and can switch providers later by changing one class.
Online 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.
Agent checking a real order and streaming the answer.
My 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.
gpt-5-mini
React chat β POST /api/chat { sessionId, message } β ChatController
β
ChatService (sessions + streaming)
β
AIAgent (built by AgentService)
β
OpenAIProvider β OpenAI
β
OrderTools β IOrderRepository (when the customer asks about an order)
The backend is split into layers, and inner layers never know about outer ones:
backend/
βββ Controllers/ ChatController: only calls the service
βββ Domain/ Order: a plain business object
βββ Application/ interfaces, AgentService, ChatService, OrderTools
βββ Infrastructure/ OpenAIProvider, InMemoryOrderRepository
βββ Extensions/ AddServices: all DI in one place
An agent is the model, plus instructions, plus tools, wrapped in one object. In Agent Framework that's a ChatClientAgent:
public AIAgent CreateAgent()
{
IChatClient chatClient = _aiProvider.GetChatClient();
return new ChatClientAgent(
chatClient,
name: "SupportAgent",
instructions: """
You are a friendly support agent for an online electronics store.
Keep answers short and clear.
Use the GetOrderStatus tool whenever a customer asks about an order.
Never promise a refund. Offer to connect the customer to a human instead.
""",
tools: [AIFunctionFactory.Create(_orderTools.GetOrderStatusAsync, name: "GetOrderStatus")]);
}
The 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.
[Description("Gets the delivery status of a customer's order.")]
public async Task<string> GetOrderStatusAsync([Description("The order number, for example 1234")] int orderId)
{
Order? order = await _orderRepository.GetOrderByIdAsync(orderId);
if (order == null)
{
return $"Order with ID {orderId} not found.";
}
return $"The status of order {orderId} is: {order.Status}.";
}
Each chat sends a sessionId, and the backend keeps one AgentSession per ID. The session holds the conversation's history.
private async Task<AgentSession> GetOrCreateSessionAsync(string sessionId)
{
if (_sessions.TryGetValue(sessionId, out AgentSession? session))
{
return session;
}
session = await _agent.CreateSessionAsync();
_sessions[sessionId] = session;
return session;
}
One 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.
The 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:
await foreach (AgentResponseUpdate update in _agent.RunStreamingAsync(request.Message, session))
{
if (string.IsNullOrEmpty(update.Text))
{
continue;
}
byte[] bytes = Encoding.UTF8.GetBytes(update.Text);
await output.WriteAsync(bytes);
await output.FlushAsync();
}
On the React side, the page reads the response piece by piece and updates the reply as each piece lands:
const reader = response.body!.getReader()
const decoder = new TextDecoder()
let text = ''
while (true) {
const { done, value } = await reader.read()
if (done) break
text += decoder.decode(value, { stream: true })
setReply(text)
}
OpenAI sits behind an IAIProvider interface, and it's the only class that knows about OpenAI:
public IChatClient GetChatClient()
{
return new OpenAIClient(_settings.ApiKey)
.GetChatClient(_settings.Model)
.AsIChatClient();
}
To move to another provider later, I write a new class that implements IAIProvider and change one line in AddServices.
| Check | Pass if | Result |
|---|---|---|
| "My name is Fisayo", then "What's my name?" | It remembers the name | Pass |
| "Explain how to choose a laptop" | The reply streams in word by word | Pass |
| "Where is my order 1234?" | It calls GetOrderStatus | Pass |
| "Can I get a refund?" | It doesn't promise one and offers a human | Pass |
/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.
None of these were AI problems. Most of the week went into plain web plumbing, which is a useful reminder.
Later in the series, I'll take the same patterns to Claude and Anthropic's agent tools.
The full backend and frontend are on GitHub: ai-agents/support-agent
If you've built agents with Agent Framework, what tripped you up first? I'd like to hear it in the comments.