{"article":{"slug":"build-your-own-ai-agent-harness-in-c-the-mafclaw-live-series","title":"Build Your Own AI Agent Harness in C#, the MafClaw Live Series","subtitle":null,"summary":"Bruno Capuano’s four-part .NET / Microsoft Reactor series builds a finance-education agent on the Microsoft Agent Framework harness—tools, file boundaries, approvals, skills, shell, CodeAct, observability, and Foundry hosting.","content_type":"tutorial","language":"en","canonical_url":"https://devblogs.microsoft.com/dotnet/build-your-own-ai-agent-harness-in-csharp-the-maf-claw-live-series/","author":{"name":"Bruno Capuano","url":"https://devblogs.microsoft.com/dotnet/author/bruno-capuano/","person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":".NET Blog","url":"https://devblogs.microsoft.com/dotnet/","listing_slug":null,"listing":null},"topics":[{"name":"AI Agents","slug":"ai-agents","url":"https://listedarticles.com/topics/ai-agents"},{"name":"Programming","slug":"programming","url":"https://listedarticles.com/topics/programming"},{"name":"Engineering","slug":"engineering","url":"https://listedarticles.com/topics/engineering"},{"name":"LLMs","slug":"llms","url":"https://listedarticles.com/topics/llms"},{"name":"Tutorials","slug":"tutorials","url":"https://listedarticles.com/topics/tutorials"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":349,"reading_minutes":2,"published_at":"2026-09-16T00:00:00.000Z","added_at":"2026-09-22T06:15:28.110Z","updated_at":"2026-09-22T06:15:28.110Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/build-your-own-ai-agent-harness-in-c-the-mafclaw-live-series","markdown_url":"https://listedarticles.com/articles/build-your-own-ai-agent-harness-in-c-the-mafclaw-live-series.md","example":false,"citation":"Bruno Capuano, .NET Blog. \"Build Your Own AI Agent Harness in C#, the MafClaw Live Series.\" 16 Sept 2026. https://devblogs.microsoft.com/dotnet/build-your-own-ai-agent-harness-in-csharp-the-maf-claw-live-series/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://devblogs.microsoft.com/dotnet/build-your-own-ai-agent-harness-in-csharp-the-maf-claw-live-series/"},"body_markdown":"# Build Your Own AI Agent Harness in C#, the MafClaw Live Series\n\nA few weeks ago Bruno Capuano wrote about going from `dotnet run` to a Foundry Hosted Agent in three lines of C#. That post starts near the end of the journey. The next question: what should you put inside the agent before you deploy it?\n\nTools. Planning. Safe file access. Human approval. Memory. Skills. Shell. Code execution. Background agents. Observability. Governance. Evaluations.\n\nMicrosoft Agent Framework includes an **agent harness**. Capuano is building a complete C# agent with it live in a four-part series—*From Model to Agent: The Agent Framework Harness, Live in C#*—streaming on the .NET YouTube channel and Microsoft Reactor.\n\n## What is an agent harness?\n\nA language model generates text. An agent needs a loop that calls tools, inspects results, updates a plan, remembers information, requests approval for risky actions, manages context, and keeps working until the task is complete. That surrounding runtime is the harness.\n\nIn .NET:\n\n```csharp\nAIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions\n{\n    ChatOptions = new ChatOptions\n    {\n        Instructions = \"You are a personal finance education assistant.\",\n        Tools = [StockTools.GetStockPrice]\n    }\n});\n```\n\nThe harness supplies automatic function invocation, history persistence, planning, context compaction, file memory, web search, tool approvals, skills, and OpenTelemetry—each configurable.\n\n## What the series builds\n\nAcross four sessions, one personal finance education assistant grows through:\n\n1. **Tools, web search, and a plan** — smallest useful agent with a custom stock-price tool and todo planning\n2. **Files, approvals, and memory** — portfolio CSV inside an approved working directory; `ApprovalRequiredAIFunction` for simulated trades; local vs Foundry Memory; timed approval policy for unanswered prompts\n3. **Skills, shell, CodeAct, and background agents** — discoverable skills, confined shell, code execution for arithmetic, parallel research agents\n4. **Observability, governance, evaluations, and Foundry Hosted Agent deployment**\n\nAll prices and transactions in the samples are mock and illustrative—not financial advice.\n\n## Why start with the harness?\n\nYou can rebuild every piece yourself. Most teams want to spend time on domain behavior: which tools, which data, which approvals, what memory, which skills, which policies, how to evaluate. The harness gives those decisions a composable home. You still own the boundaries.\n\n*Source: [devblogs.microsoft.com/dotnet/...](https://devblogs.microsoft.com/dotnet/build-your-own-ai-agent-harness-in-csharp-the-maf-claw-live-series/)*\n","body_html":"<h1 id=\"build-your-own-ai-agent-harness-in-c-the-mafclaw-live-series\">Build Your Own AI Agent Harness in C#, the MafClaw Live Series</h1>\n<p>A few weeks ago Bruno Capuano wrote about going from <code>dotnet run</code> to a Foundry Hosted Agent in three lines of C#. That post starts near the end of the journey. The next question: what should you put inside the agent before you deploy it?</p>\n<p>Tools. Planning. Safe file access. Human approval. Memory. Skills. Shell. Code execution. Background agents. Observability. Governance. Evaluations.</p>\n<p>Microsoft Agent Framework includes an <strong>agent harness</strong>. Capuano is building a complete C# agent with it live in a four-part series—<em>From Model to Agent: The Agent Framework Harness, Live in C#</em>—streaming on the .NET YouTube channel and Microsoft Reactor.</p>\n<h2 id=\"what-is-an-agent-harness\">What is an agent harness?</h2>\n<p>A language model generates text. An agent needs a loop that calls tools, inspects results, updates a plan, remembers information, requests approval for risky actions, manages context, and keeps working until the task is complete. That surrounding runtime is the harness.</p>\n<p>In .NET:</p>\n<pre><code class=\"language-csharp\">AIAgent agent = chatClient.AsHarnessAgent(new HarnessAgentOptions\n{\n    ChatOptions = new ChatOptions\n    {\n        Instructions = &quot;You are a personal finance education assistant.&quot;,\n        Tools = [StockTools.GetStockPrice]\n    }\n});</code></pre>\n<p>The harness supplies automatic function invocation, history persistence, planning, context compaction, file memory, web search, tool approvals, skills, and OpenTelemetry—each configurable.</p>\n<h2 id=\"what-the-series-builds\">What the series builds</h2>\n<p>Across four sessions, one personal finance education assistant grows through:</p>\n<ol><li><strong>Tools, web search, and a plan</strong> — smallest useful agent with a custom stock-price tool and todo planning</li><li><strong>Files, approvals, and memory</strong> — portfolio CSV inside an approved working directory; <code>ApprovalRequiredAIFunction</code> for simulated trades; local vs Foundry Memory; timed approval policy for unanswered prompts</li><li><strong>Skills, shell, CodeAct, and background agents</strong> — discoverable skills, confined shell, code execution for arithmetic, parallel research agents</li><li><strong>Observability, governance, evaluations, and Foundry Hosted Agent deployment</strong></li></ol>\n<p>All prices and transactions in the samples are mock and illustrative—not financial advice.</p>\n<h2 id=\"why-start-with-the-harness\">Why start with the harness?</h2>\n<p>You can rebuild every piece yourself. Most teams want to spend time on domain behavior: which tools, which data, which approvals, what memory, which skills, which policies, how to evaluate. The harness gives those decisions a composable home. You still own the boundaries.</p>\n<p><em>Source: <a href=\"https://devblogs.microsoft.com/dotnet/build-your-own-ai-agent-harness-in-csharp-the-maf-claw-live-series/\" rel=\"nofollow ugc noopener\">devblogs.microsoft.com/dotnet/...</a></em></p>","headings":[{"level":1,"text":"Build Your Own AI Agent Harness in C#, the MafClaw Live Series","id":"build-your-own-ai-agent-harness-in-c-the-mafclaw-live-series"},{"level":2,"text":"What is an agent harness?","id":"what-is-an-agent-harness"},{"level":2,"text":"What the series builds","id":"what-the-series-builds"},{"level":2,"text":"Why start with the harness?","id":"why-start-with-the-harness"}]}}