Microsoft's Agent Framework Gets a Hands-On Tutorial Series in C#

If you have ever built an AI agent from scratch, you know the pattern. You write a chat completion call, then realize you need a tool loop. Then history persistence. Then planning. Then file access. Then approvals for dangerous actions. Then memory. Then observability. Each piece is straightforward in isolation, but wiring them together into a coherent runtime takes weeks before you write a single line of domain logic.

Microsoft Agent Framework ships that runtime out of the box, and a new four-part live series walks through building a complete C# agent with it, one capability at a time. The series is called "From Model to Agent: The Agent Framework Harness, Live in C#," hosted by Bruno Capuano, a Cloud Advocate at Microsoft. It streams on the .NET YouTube channel and Microsoft Reactor, with two sessions already available and two more scheduled for late September 2026.

What the Harness Actually Provides

The core idea is simple. A language model generates text. An agent needs a loop around that model: one that can call tools, inspect results, update a plan, remember information, request human approval for risky actions, manage a growing context window, and keep working until the task is complete. That surrounding runtime is the harness.

In C#, you get the harness with a single extension method call:

AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions
{
    ChatOptions = new ChatOptions
    {
        Instructions = instructions,
        Tools = tools
    }
});

That call wires up automatic function invocation, history persistence after every model call, planning with todo and agent-mode providers, context compaction, file memory, web search, tool approvals, skills, and OpenTelemetry instrumentation. Each capability is configurable, replaceable, or removable depending on what the agent needs.

Microsoft Agent Framework reached general availability on April 2, 2026, as the convergence of AutoGen and Semantic Kernel into a single supported platform. The harness layer became first-class at Build 2026 in June, and the harness itself shipped as a release in July. The framework supports .NET, Python, and Go with consistent APIs across languages.

Four Sessions, One Agent

The series builds a single personal finance education assistant across four weekly sessions. Finance was chosen because it provides realistic risk boundaries: looking up a stock price is a read-only operation, reading a portfolio accesses user data, writing a report changes a file, and placing a simulated trade is a side effect that needs human approval.

Session 1, already available, covers the basics: creating an IChatClient backed by a Microsoft Foundry model, wrapping it with the harness, and adding a custom stock price tool. The tool is ordinary C# with a Description attribute, and Agent Framework generates the tool schema from the function signature. The session also demonstrates hosted web search and the built-in todo list for multi-step work.

Session 2, also available, tackles data access safety. The finance assistant gets access to a portfolio CSV, but only inside an approved working directory. The model does not receive arbitrary filesystem access. The application supplies a file store rooted at one folder, and the harness enforces that boundary. The session also covers human approval for simulated trades using an ApprovalRequiredAIFunction wrapper, and compares local JSON memory with managed Foundry Memory.

Session 3, scheduled for September 25, adds four expansion mechanisms. Skills package domain knowledge in discoverable files so the agent loads full instructions only when needed instead of stuffing everything into the system prompt. Shell access lets the agent run commands inside a confined directory with policy and timeouts. CodeAct lets the agent write and execute code in a controlled environment, which is more reliable than asking the model to do arithmetic in prose. Background agents let the main agent delegate independent research tasks to parallel sub-agents that report back.

Session 4, scheduled for October 2, closes the loop with production concerns: OpenTelemetry traces for observability, Microsoft Purview policy integration for governance, repeatable evaluations, and deployment as a Foundry Hosted Agent. The key point is that a hosted deployment should not inherit local filesystem or shell access just because those capabilities were useful during development. Every capability has a production-appropriate equivalent, and choosing between them is a deliberate decision.

A Live Audience Question Produced a New Feature

During the Session 2 live Q&A, someone asked what happens when a user does not answer an approval request. The answer turned into a new sample: a bounded approval policy with a five-second timeout per attempt, a maximum of five retries, automatic denial after the final attempt, and sticky denial for the rest of the user prompt. The policy starts with a small configuration block and handles edge cases like missing input, invalid responses, and repeated approval rounds from the model.

This is a useful pattern for any agent that needs to interact with humans. An approval flow that waits forever is not complete. Silence is not consent, and a production agent needs explicit timeout and retry logic to avoid hanging on unresponsive users.

Why the Harness Model Matters for .NET Teams

You can build every piece of this yourself. Write a tool loop, serialize history after every service call, maintain a plan, compact context, build a memory layer, design an approval protocol, load skills, manage background workers, and instrument the pipeline. Sometimes that level of control is necessary.

But most teams building agents want to spend their time on domain behavior: which tools the agent should have, which data it can access, which actions require approval, what it should remember, which skills to load, which tasks can run concurrently, and how to evaluate whether it works. The harness gives those decisions a composable home without rebuilding the agent runtime for every project.

The complete sample code is available in the MafClaw repository, and all four sessions remain available on demand after the live broadcasts. The series registration page and the Agent Framework documentation at learn.microsoft.com provide the starting points for both the live walkthrough and the underlying framework concepts.