middleware
Legacy tutorial alias retained locally; the live Learn URL now resolves to the canonical middleware article
$ npx -y skills add managedcode/dotnet-skills --agent claude-codeHow it fires
How this agent gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
Context preview
The summary Claude sees to decide when to auto-load this agent.
Legacy tutorial alias retained locally; the live Learn URL now resolves to the canonical middleware article
Agent definition
middleware.mdtitle: Adding middleware to agents
description: Legacy tutorial alias retained locally; the live Learn URL now resolves to the canonical middleware article
zone_pivot_groups: programming-languages
author: dmytrostruk
ms.topic: tutorial
ms.author: dmytrostruk
ms.date: 03/17/2026
ms.service: agent-framework
Adding middleware to agents
> [!NOTE] > The live Learn URL for this old tutorial now resolves to the same canonical middleware page as `user-guide/agents/agent-middleware.md`: > `https://learn.microsoft.com/agent-framework/agents/middleware/` > > Keep this local file only as a compatibility alias for existing references inside the skill catalog.
Learn how to add middleware to your agents in a few simple steps. Middleware allows you to intercept and modify agent interactions for logging, security, and other cross-cutting concerns.
::: zone pivot="programming-language-csharp"
For the current C# walkthrough, use `references/official-docs/user-guide/agents/agent-middleware.md`.
Current tutorial-level takeaways
1. Register agent-run middleware through `AsBuilder().Use(...)`. 2. Prefer supplying both `runFunc` and `runStreamingFunc`; use `Use(sharedFunc: ...)` only for input inspection that should not rewrite output. 3. Current run middleware examples use `AgentSession? session` instead of `AgentThread? thread`. 4. Function middleware is still the right place for approvals, allow/deny policy, and risky-tool interception. 5. Current official C# samples use `DefaultAzureCredential` and explicitly warn against carrying that default into production unchanged.
::: zone-end ::: zone pivot="programming-language-python"
The live alias now resolves to the canonical middleware article. Use the canonical live docs for current Python examples.
::: zone-end
Read more
title: Adding middleware to agents description: Legacy tutorial alias retained locally; the live Learn URL now resolves to the canonical middleware article zone_pivot_groups: programming-languages author: dmytrostruk ms.topic: tutorial ms.author: dmytrostruk ms.date: 03/17/2026 ms.service: agent-framework
Adding middleware to agents
> [!NOTE] > The live Learn URL for this old tutorial now resolves to the same canonical middleware page as `user-guide/agents/agent-middleware.md`: > `https://learn.microsoft.com/agent-framework/agents/middleware/` > > Keep this local file only as a compatibility alias for existing references inside the skill catalog.
Learn how to add middleware to your agents in a few simple steps. Middleware allows you to intercept and modify agent interactions for logging, security, and other cross-cutting concerns.
::: zone pivot="programming-language-csharp"
For the current C# walkthrough, use `references/official-docs/user-guide/agents/agent-middleware.md`.
Current tutorial-level takeaways
1. Register agent-run middleware through `AsBuilder().Use(...)`. 2. Prefer supplying both `runFunc` and `runStreamingFunc`; use `Use(sharedFunc: ...)` only for input inspection that should not rewrite output. 3. Current run middleware examples use `AgentSession? session` instead of `AgentThread? thread`. 4. Function middleware is still the right place for approvals, allow/deny policy, and risky-tool interception. 5. Current official C# samples use `DefaultAzureCredential` and explicitly warn against carrying that default into production unchanged.
::: zone-end ::: zone pivot="programming-language-python"
The live alias now resolves to the canonical middleware article. Use the canonical live docs for current Python examples.
::: zone-end
Stop explaining .NET to your AI. Start building. We've all been there: asking Claude to use Entity Framework, only to get EF6 patterns in a .NET 8 project. Explaining to Copilot that Blazor Server and Blazor WebAssembly aren't the same thing.
Repo: managedcode/dotnet-skills
Other agents on dotnet-skills.
- AGENT
Specialist orchestration agent for .NET Aspire work. Use when the problem is clearly about AppHost design, ServiceDefaults, first-party versus CommunityToolkit/Aspire integrations, dashboard and testing, `DistributedApplicationTestingBuilder`, `WebApplicationFactory`
Open agent - agent-as-function-tool
Legacy tutorial alias retained locally; the live Learn URL now resolves into the broader Function Tools surface
Open agent - agent-as-mcp-tool
Learn how to expose an agent as a tool over the MCP protocol
Open agent - create-and-run-durable-agent
Learn how to create and run a durable AI agent with Azure Functions and the durable task extension for Microsoft Agent Framework
Open agent - enable-observability
Enable OpenTelemetry for an agent so agent interactions are automatically logged
Open agent - function-tools-approvals
Learn how to use function tools with human in the loop approvals
Open agent

