THR1804 · Theater

Build an Agent Harness with Microsoft Agent Framework

  • Thursday 19 November
  • 26 min
  • Catalogue level: (300) Advanced
  • Our depth rating: 300
  • Worth watching: 2/3

Speakers: Tomas Herceg

Watch on Microsoft’s site from 11:34

Microsoft’s player cannot open a video at a given time: once it plays, skip to the time shown.

What the session covers

Tomas Herceg explains what an agent harness adds to plain request-response LLM calls: repeated model calls, planning, to-do tracking, session compaction, selective memory, persistence and sandboxing. He then shows it in Microsoft Agent Framework with an invoicing agent. The agent reads consultants' Excel timesheets from SharePoint, totals the hours and creates invoices in an internal system through MCP servers, with a human approving each invoice. The code walkthrough covers the skill file, the ASP.NET Core (.NET 10) host with AG-UI and a session store, three stdio MCP servers, the approval wrapper, harness options and the hooks for overriding the run method. The session ends by recommending the Foundry hosted agent service over in-process hosting for production.

Best for: .NET developers and architects who build stateful, multi-step agents with MCP tools and human approvals in Microsoft Agent Framework.

Session timeline by chapter

New material starts at 11:34. Up to this point the session covers the harness concept, a framework overview and the demo scenario; at 11:34 the detailed code walkthrough starts, beginning with the skill file and the ASP.NET Core setup.

Where to skip: If you know what a harness is, skip to 07:20 for the scenario, or straight to 11:34. The core is the code from 11:34 to 21:54, especially the harness options and hooks at 18:30. Watch the approval flow at 21:54 and the production hosting advice at 23:54. The 05:44 framework overview can be skipped.

Chapters (9)

  1. 00:00 Recap Depth 200 · Novelty 0/3

    Session intro: from simple request-response LLM calls to the need for a harness

    The host introduces Tomas Herceg, who says the session will mostly be code and a demo of orchestrating a complex process with the agent harness in Microsoft Agent Framework. He describes the basic chat pattern: a model provisioned in Foundry gets the message history (system and user messages) and returns one response. Tools can be declared, but the model only says which tool it wants to call. The caller has to invoke it, and nothing loops back on the result.

  2. 02:08 Deep dive Depth 300 · Novelty 1/3

    How an agent harness works: planning, to-dos, compaction, memory, persistence, sandbox

    The speaker explains that a harness calls the LLM again and again. First it asks for a plan, then it works on each step, invokes any requested tools and passes the results back, until the task is finished. Harnesses also track to-do state, compact long sessions by summarising earlier history, load memory and context selectively to save tokens, and handle loops, conditions and parallel tool calls. Human approvals can stretch a session over weeks, so sessions must be persisted and resumable, and powerful tools such as file or process access must run in a sandbox.

  3. 05:44 Recap Depth 200 · Novelty 0/3

    Microsoft Agent Framework overview: SDK, languages, providers, MCP, A2A, AG-UI

    The speaker calls Microsoft Agent Framework a low-level SDK and runtime for when you need the most control and extensibility. It works with C# or any .NET language and with Python, and supports many model providers. It supports the MCP, Agent-to-Agent and AG-UI protocols. AG-UI streams the agent's activity to a user interface. He notes that Semantic Kernel was merged with other libraries into Microsoft Agent Framework.

  4. 07:20 Demo Depth 200 · Novelty 1/3

    Demo: invoicing agent reads SharePoint timesheets and streams AG-UI events

    The scenario is a real company process. Consultants file monthly Excel timesheets in per-person SharePoint folders. Once the customer approves and sends a PO number, the agent should find the right month's reports, total the hours (even when the total row is missing) and create invoices in a test copy of the internal invoicing system through an MCP server. In a simple AI-generated web UI, the agent loads a skill, creates to-dos and asks for the missing PO number. It then lists SharePoint files, and the UI renders every step from AG-UI events, including the tool-call arguments.

  5. 11:34 Deep dive Depth 400 · Novelty 2/3

    Skill file and ASP.NET Core setup: Microsoft.Agents.AI packages, AG-UI server, session store

    The business process is written as a skill: a markdown file with a header that tells the agent which MCP servers to use for which resources. The host is a standard ASP.NET Core app on .NET 10 using Microsoft.Agents.AI NuGet packages, with sub-packages for the harness, AG-UI and OpenAI. Program.cs checks for the Foundry endpoint, API key and model name, calls the AG-UI server registration, registers an in-memory agent session store (state is lost on restart) and exposes the agent on a URL. Back in the UI, one tool call has failed, but the agent recovers and reports that there are no October reports. The speaker then asks it to use September with the same PO number.

  6. 14:47 Deep dive Depth 400 · Novelty 2/3

    Building the agent: approval list, scratch folder, system prompt, chat client, skills, MCP servers

    The InvoicingAgent class defines which tools need human approval (create invoice), a temporary scratch folder for downloaded files, the skills directory, and a generic system prompt. The prompt describes the operating environment, while the process itself lives in the skill file so it can change separately. The code creates a basic chat client from the endpoint and API key and registers a skills provider that scans the skills folder. It starts three stdio console MCP servers, kept in a wrapper that tracks their processes: a restricted custom SharePoint server, an Excel server and one for the internal invoicing system. It then collects all the tools they expose.

  7. 18:30 Deep dive Depth 400 · Novelty 2/3

    Approval wrapper, harness options (defaults, opt-in/out) and extensibility hooks

    Tools that need approval are wrapped in an approval-required AI function, which pauses the session until a human approves. The chat client, system prompt, MCP tools and AI skills (as AI context providers) are combined, and the harness options are tuned. The speaker advises checking them all in IntelliSense: the to-do provider is on by default and must be explicitly disabled, while the file access store must be explicitly enabled. He turns off web search and process execution for security, then calls AsHarnessAgent to build the harness. By overriding the per-session run method he adds the current date and time to the instructions, emits custom AG-UI events such as model-call progress, and hooks into the event loop.

  8. 21:54 Demo Depth 200 · Novelty 1/3

    Demo result: hour totals, human-in-the-loop approvals, invoices created via MCP

    The agent downloaded the September reports, pulled the hours from each file into a table and calculated amounts using the hourly rate defined in the skill. The invoicing system recalculates the totals anyway. When the agent tries to create each invoice, the UI asks for approval, and the session resumes after each click. After a refresh, two invoices appear in the speaker's 15-year-old invoicing system, written through a custom MCP server. He stresses that the agent can reach only the SharePoint folder and the API surface it needs.

  9. 23:54 Closing Depth 300 · Novelty 1/3

    Running in production: Foundry hosted agent service vs. self-hosting, then closing

    The speaker notes that the demo agent ran inside the web app process, which is not suitable for production. He recommends deploying to the Foundry hosted agent service, which gives every session a sandbox, scales to thousands of concurrent requests, stores long-running sessions so they can be recovered, and gives each agent its own identity with assignable permissions for Azure or Microsoft 365 resources. Self-hosting as a console app is also possible, but file access outside the container and egress must be secured. Q&A happens offstage.

Announcements (0)

No specific announcement was made in this session.

Demos (5)

  • 09:37 Not easy to reproduce Microsoft Agent Framework

    An agent automates monthly invoicing for a consulting company. It reads consultants' Excel timesheets from SharePoint, totals the hours and prepares invoices in an internal invoicing system through MCP.

    Steps (5)
    1. Show the per-consultant SharePoint folders, which hold one Excel timesheet per month with name, date, hours, activity and a total row.
    2. In the demo web UI, ask the agent to create invoices because the reports are ready.
    3. Watch the AG-UI events in the UI: thinking, model calls, skill loading and to-do creation.
    4. When the agent asks for missing information, reply with the PO number.
    5. Watch the agent track its to-dos, list SharePoint files and call the invoicing MCP server, and expand the tool calls to see their arguments.

    Prerequisites: SharePoint folders with the Excel timesheets, custom MCP servers for SharePoint, Excel and the internal invoicing system, a model deployed in Foundry, and a web UI that speaks AG-UI.

  • 12:28 Not stated Microsoft Agent Framework

    Code walkthrough of how the invoicing agent's host app is set up and how the agent copes with a failed tool call and missing data.

    Steps (6)
    1. Open the skill markdown file that describes the business process and names the MCP servers for each resource.
    2. Reference the Microsoft.Agents.AI NuGet packages in an ASP.NET Core .NET 10 project: harness, AG-UI and OpenAI sub-packages.
    3. In Program.cs, check the configuration for the Foundry resource URL, API key and model name.
    4. Register the AG-UI server services and an in-memory agent session store.
    5. Create the agent and map it to a URL so the web page can talk to it over AG-UI.
    6. In the UI, review the tool error and the agent's reply that October reports are missing, then ask it to use September with the same PO number.

    Prerequisites: A .NET 10 ASP.NET Core project, the Microsoft.Agents.AI NuGet packages, and a Foundry resource URL, API key and model name.

  • 15:14 Not stated Microsoft Agent Framework

    Code walkthrough of how the invoicing agent is assembled from a chat client, skills and MCP tools.

    Steps (7)
    1. Define constants that list the tools needing human approval (create invoice), the scratch folder temp path and the skills directory.
    2. Write a generic system prompt that describes the operating environment and keep the process itself in the skill file.
    3. Read the endpoint URL and API key from configuration and start a wrapper that tracks the MCP server processes.
    4. Create a basic chat client from the API key, endpoint and model.
    5. Register a skills provider that points to the skills folder.
    6. Delete and recreate the scratch folder.
    7. Start the SharePoint, Excel and invoicing-system MCP servers as stdio console apps and collect their tools.

    Prerequisites: Custom MCP servers built as console apps, a skills folder, and a Foundry model endpoint and API key.

  • 18:30 Not stated Microsoft Agent Framework

    Code walkthrough of how to finish and harden the harness agent and add custom behaviour.

    Steps (6)
    1. Wrap the tools that need approval in an approval-required AI function.
    2. Combine the chat client, system prompt, MCP tools and AI skills (in the AI context providers collection).
    3. Review the harness options in IntelliSense: keep the to-do provider (on by default), turn off web search and process execution, and opt in to the file access store only if needed.
    4. Call AsHarnessAgent to build the agent harness.
    5. Override the per-session run method to add the current date and time to the instructions.
    6. Emit custom AG-UI events, such as model-call progress, and add your own hooks in the event loop.
  • 22:04 Not easy to reproduce Microsoft Agent Framework

    The agent finishes the September invoicing run, and a human approves each invoice before it is created.

    Steps (4)
    1. Review the table of hours the agent extracted from each September report and the amounts calculated from the hourly rate in the skill.
    2. When the agent asks to create the first invoice, click Approve in the UI and wait for the session to resume.
    3. Approve the second invoice request.
    4. Refresh the invoicing system and confirm that two invoices were created.

    Prerequisites: The approval-wrapped create-invoice tool and the invoicing-system MCP server.

Watch on Microsoft’s site: THR1804