microsoft-agent-framework
Build multi-agent AI systems with Microsoft's Agent Framework (formerly Semantic Kernel Agents). Use when: defining AI agents, orchestrating multi-agent workflows (sequential, parallel, conditional), creating custom agents in Python or .NET, using built-in agents (ChatCompletion, OpenAI Assistant), deploying agent systems, or comparing agent orchestration patterns.
What this skill does
# Microsoft Agent Framework
## Overview
Microsoft Agent Framework provides primitives for building single and multi-agent AI systems. It supports agent definition, orchestration patterns, tool integration, and deployment — available in both Python and .NET.
**Repo:** `microsoft/semantic-kernel` (agents module)
**Docs:** learn.microsoft.com/semantic-kernel/agents
**Requirements:** Python 3.10+ or .NET 8+
## Installation
### Python
```bash
pip install semantic-kernel
# Agents are included in the core package
```
### .NET
```bash
dotnet add package Microsoft.SemanticKernel
dotnet add package Microsoft.SemanticKernel.Agents.Core
dotnet add package Microsoft.SemanticKernel.Agents.OpenAI # For OpenAI Assistant agent
```
## Core Concepts
### Agent Definition
An agent = instructions + model + tools + optional name/description.
```python
from semantic_kernel.agents import ChatCompletionAgent
from semantic_kernel import Kernel
kernel = Kernel()
# Add AI service to kernel (OpenAI, Azure OpenAI, etc.)
researcher = ChatCompletionAgent(
kernel=kernel,
name="Researcher",
instructions="""You are a research analyst. Given a topic,
find key facts, statistics, and recent developments.
Always cite sources. Output structured findings.""",
)
writer = ChatCompletionAgent(
kernel=kernel,
name="Writer",
instructions="""You are a technical writer. Take research findings
and produce clear, engaging content. Use simple language.
Target audience: software developers.""",
)
```
### Built-in Agent Types
| Type | Description | Use Case |
|------|------------|----------|
| `ChatCompletionAgent` | Wraps any chat model | General tasks, most common |
| `OpenAIAssistantAgent` | Uses OpenAI Assistants API | Code interpreter, file search |
| `AzureAIAgent` | Azure AI Foundry agent | Enterprise, Azure-integrated |
### Agent with Tools
```python
from semantic_kernel.functions import kernel_function
class WebSearch:
@kernel_function(description="Search the web for information")
def search(self, query: str) -> str:
# Implement search logic
return f"Results for: {query}"
class Calculator:
@kernel_function(description="Perform mathematical calculations")
def calculate(self, expression: str) -> str:
return str(eval(expression)) # Use safe eval in production
kernel.add_plugin(WebSearch(), plugin_name="web")
kernel.add_plugin(Calculator(), plugin_name="math")
agent = ChatCompletionAgent(
kernel=kernel,
name="Assistant",
instructions="Use tools to answer questions accurately.",
)
```
## Multi-Agent Orchestration
### AgentGroupChat
The primary way to orchestrate multiple agents:
```python
from semantic_kernel.agents import AgentGroupChat
from semantic_kernel.agents.strategies import (
SequentialSelectionStrategy,
KernelFunctionTerminationStrategy,
)
chat = AgentGroupChat(
agents=[researcher, writer, editor],
selection_strategy=SequentialSelectionStrategy(
agents=[researcher, writer, editor]
),
termination_strategy=KernelFunctionTerminationStrategy(
agents=[editor],
max_iterations=6,
),
)
await chat.add_chat_message(message="Write a blog post about WebAssembly in 2025")
async for response in chat.invoke():
print(f"[{response.name}]: {response.content}")
```
### Orchestration Patterns
#### Sequential — agents take turns in fixed order
```python
from semantic_kernel.agents.strategies import SequentialSelectionStrategy
strategy = SequentialSelectionStrategy(
agents=[researcher, writer, editor],
initial_agent=researcher,
)
```
Use for: pipelines where each agent builds on the previous output.
#### Conditional — kernel function picks the next agent
```python
from semantic_kernel.agents.strategies import KernelFunctionSelectionStrategy
selector_fn = KernelFunction.from_prompt("""
Given the conversation, determine which agent should respond next.
Agents: Researcher, Writer, Editor.
If research is needed, pick Researcher.
If draft is ready for writing, pick Writer.
If draft needs review, pick Editor.
Respond with only the agent name.
""")
strategy = KernelFunctionSelectionStrategy(
kernel=kernel,
function=selector_fn,
agents=[researcher, writer, editor],
)
```
Use for: dynamic workflows where the next step depends on current state.
#### Parallel — fan-out to multiple agents, aggregate results
```python
import asyncio
async def parallel_analysis(topic: str):
tasks = [
researcher.invoke(f"Research {topic}"),
competitor_analyst.invoke(f"Analyze competitors in {topic}"),
trend_analyst.invoke(f"Identify trends in {topic}"),
]
results = await asyncio.gather(*tasks)
# Feed aggregated results to synthesizer agent
summary = await synthesizer.invoke(
f"Synthesize these analyses:\n" +
"\n---\n".join(r.content for r in results)
)
return summary
```
Use for: independent analyses that combine into a final output.
## .NET Example
```csharp
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.Chat;
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(deployment, endpoint, apiKey)
.Build();
ChatCompletionAgent researcher = new()
{
Kernel = kernel, Name = "Researcher",
Instructions = "You are a research analyst. Find key facts and statistics."
};
ChatCompletionAgent writer = new()
{
Kernel = kernel, Name = "Writer",
Instructions = "You are a technical writer. Produce clear, engaging content."
};
AgentGroupChat chat = new(researcher, writer)
{
ExecutionSettings = new()
{
SelectionStrategy = new SequentialSelectionStrategy { InitialAgent = researcher },
TerminationStrategy = new MaxIterationTerminationStrategy(4)
}
};
chat.AddChatMessage(new("Write about Kubernetes security best practices"));
await foreach (var msg in chat.InvokeAsync())
{
Console.WriteLine($"[{msg.AuthorName}]: {msg.Content}");
}
```
## Deployment
### As API Service
```python
from fastapi import FastAPI
from semantic_kernel.agents import ChatCompletionAgent
app = FastAPI()
# Initialize agents at startup
@app.post("/chat")
async def chat(message: str):
response = await agent.invoke(message)
return {"response": response.content}
```
## Tips
- Start with `ChatCompletionAgent` — it works with any chat model provider
- Use `SequentialSelectionStrategy` first, upgrade to `KernelFunctionSelectionStrategy` when you need dynamic routing
- Set `max_iterations` on termination strategy to prevent infinite agent loops
- Each agent can have its own kernel with different models — use cheaper models for simple tasks
- `AgentGroupChat` maintains shared conversation history — all agents see all messages
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.