Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Build .NET AI agents, harnesses, and multi-agent workflows with Microsoft Agent Framework using the right agent type, sessions, tools, workflows, hosting protocols, and enterprise guardrails. USE FOR: building or reviewing .NET code that uses Microsoft.Agents.*, Microsoft.Extensions.AI, AIAgent, HarnessAgent, AgentThread, AgentSession, or Agent Framework hosting packages; choosing agent, harness, workflow, and hosting shapes. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this
.claude/skills/managedcode-microsoft-agent-framework/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 13% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 81% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 3% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 100% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 137% | 0% |
.NET code that uses Microsoft.Agents.*, Microsoft.Extensions.AI, AIAgent, HarnessAgent, AgentThread, AgentSession, or Agent Framework hosting packagesChatClientAgent, Responses agents, hosted agents, custom agents, Anthropic agents, workflows, or durable agentsMicrosoft.Agents.AI.Harness surface for planning, todos, compaction, file memory/access, tool approvals, skills, shell execution, or background agentsMicrosoft.Agents.AI.Workflows.Declarative* packages or wrapping a workflow with workflow.AsAIAgent()AnthropicClient or through Azure Foundry with AnthropicFoundryClientAIAgent, batteries-included HarnessAgent, explicit programmatic Workflow, workflow-as-agent wrapper, declarative workflow when YAML portability is explicitly required, Azure Functions durable agent, ASP.NET Core hosted agent, AG-UI remote UI, or DevUI local debugging.AgentThread, while newer middleware and background-response examples may surface AgentSession. Treat both as opaque provider-specific state.RequestPort boundaries, checkpoints, shared state, and human-in-the-loop explicitly rather than hiding control flow in prompts.dotnet-1.15.0 adds public OpenAI Responses protocol helpers, session deletion, and hosted workflow state. The application still owns routing, authorization, and durable storage.dotnet-1.14.0 graduates the core Harness API but keeps its package and advanced options prerelease or experimental. It also makes file access opt-in, binds approvals to surfaced requests, and splits AG-UI packages and server registration. See harness.md and hosting.md.Microsoft.Agents.AI.Hosting.AGUI.AspNetCore with AddAGUIServer() and MapAGUIServer(...); the client uses AGUI.Client, and conversation state flows through AgentSession. Do not copy older AddAGUI/MapAGUI or AgentThread hosting examples into current applications.172 current markdown pages and now treats middleware, function tools and approvals, sessions, multimodal input, background responses, Azure Functions durable agents, AG-UI frontend and backend tools, MCP-hosted agents, observability, support, upgrades, and Semantic Kernel or AutoGen migration as first-class paths. Load the matching reference file before implementation and verify package maturity plus exact signatures against the linked official page; the expanded documentation does not make every provider or preview feature interchangeable.mermaidflowchart LR A["Task"] --> B{"Deterministic code is enough?"} B -->|Yes| C["Write normal .NET code or a plain workflow"] B -->|No| D{"One dynamic decision-maker is enough?"} D -->|Yes| O{"Needs a packaged long-task runtime?"} O -->|No| E["Use an `AIAgent` / `ChatClientAgent`"] O -->|Yes| P["Use `HarnessAgent` with scoped capabilities"] D -->|No| F["Use a typed `Workflow`"] F --> G{"Needs durable Azure hosting or week-long execution?"} G -->|Yes| H["Use durable agents on Azure Functions"] G -->|No| I["Use in-process workflows"] E --> J{"Need a remote protocol or UI?"} P --> J F --> J J -->|OpenAI-compatible HTTP| K["ASP.NET Core Hosting.OpenAI"] J -->|Agent-to-agent protocol| L["A2A hosting"] J -->|Web UI protocol| M["AG-UI"] J -->|Local debug shell| N["DevUI (dev only)"]
AIAgent is the common runtime abstraction. It should stay mostly stateless.AgentThread still anchors most persisted conversation guidance, but some newer runtime surfaces now pass AgentSession instead. Treat either state object as opaque provider-owned data and verify exact callback signatures against the current official page.AgentResponse and AgentResponseUpdate are not just text containers. They can include tool calls, tool results, structured output, reasoning-like updates, and response metadata.ChatClientAgent is the safest default when you already have an IChatClient and do not need a hosted-agent service.HarnessAgent is an opinionated ChatClientAgent composition from the prerelease Microsoft.Agents.AI.Harness package. Its core API is stable, while advanced options can remain experimental. It adds automatic tool loops, per-service-call history persistence, plan/execute modes, todos, optional token-budget compaction, file memory, opt-in file access, tool approval, OpenTelemetry, web search, and optional skills, shell, looping, and background agents. Enable and scope only the capabilities that the task needs.Workflow is an explicit graph of executors and edges. Use it when the control flow must stay inspectable, typed, resumable, or human-steerable.workflow.AsAIAgent() is the escape hatch when a complex workflow needs to present a normal agent surface. It keeps sessions, streaming, and agent response APIs, but the workflow start executor still needs chat-message-compatible input.AgentWorkflowBuilder provides high-level factory methods such as BuildConcurrent for common agent orchestration patterns. Use it when you need concurrent or sequential agent pipelines without writing custom executor classes.InProcessExecution.RunStreamingAsync(...). For sensitive agent tools, wrap the function with ApprovalRequiredAIFunction, listen for RequestInfoEvent with ToolApprovalRequestContent, and send the external approval response back through the run.| If you need | Default choice | Why | |---|---|---| | One model-backed assistant with normal .NET composition | ChatClientAgent or chatClient.AsAIAgent(...) | Lowest friction, middleware-friendly, works with IChatClient | | Long multi-step autonomous task with planning, todos, compaction, memory, approvals, and optional file/shell/delegation tools | chatClient.AsHarnessAgent(...) | Uses the packaged Harness pipeline instead of rebuilding an agent runtime from decorators and providers | | OpenAI-style future-facing APIs, background responses, or richer response state | Responses-based agent | Better fit for new OpenAI-compatible integrations | | Simple client-managed chat history | Chat Completions agent | Keeps request/response simple | | Service-hosted agents and service-owned threads/tools | Microsoft Foundry Agent or other hosted agent | Managed runtime is the requirement | | Azure-hosted OpenAI-compatible models with the richest hosted-tool surface but app-owned composition | Azure OpenAI Responses agent | Best Azure OpenAI default when you need code interpreter, file search, web search, hosted MCP, or tool approval without moving to a persistent service-managed agent | | Anthropic Claude models (haiku, sonnet, opus) directly or via Azure Foundry | AnthropicClient.AsAIAgent(...) or AnthropicFoundryClient.AsAIAgent(...) | Use Microsoft.Agents.AI.Anthropic; add Anthropic.Foundry for Azure-hosted Claude | | Typed multi-step orchestration | Workflow or AgentWorkflowBuilder helpers | Control flow stays explicit and testable; use BuildConcurrent for agent fan-out/fan-in | | YAML-defined orchestration that non-developers or operators need to edit | Declarative workflow packages | Good for portable trigger/action graphs; do not pretend the .NET preview is as flexible as programmatic workflows | | Week-long or failure-resilient Azure execution | Durable agent on Azure Functions | Durable Task gives replay and persisted state | | Agent-to-agent interoperability | A2A hosting or A2A proxy agent | This is protocol-level delegation, not local inference | | Browser or web UI protocol integration | AG-UI | Designed for remote UI sync and approval flows |
AgentThread, stores, or workflow state.IChatClient agents as if they share the same thread and tool guarantees.FileAccessStore, compaction has explicit token budgets when needed, and shell/file boundaries are not treated as security sandboxesAgentThread or AgentSession lifecycle, serialization, and compatibility boundaries are explicit for the chosen provider surfaceWhen a decision depends on exact wording, long-tail feature coverage, or a less-common integration, check the local official docs snapshot before relying on summaries.
HarnessAgent selection, options, compaction, approvals, file/shell boundaries, and validationAgentThread, chat history storage, reducers, context providers, and thread serializationIChatClient middleware with guardrail patternsOther measured skills in the registry, with their headline benchmark lift.