Microsoft Agent Framework
Overview
Use this skill to implement or explain Microsoft Agent Framework usage in Python. Prefer Microsoft Learn docs for conceptual guidance and use Context7 to fetch exact snippets (package extras, Azure/OpenAI client specifics).
Workflow
- Identify runtime and provider
- Confirm Python.
- Pick provider: OpenAI, Azure OpenAI, or Azure AI Foundry.
- Confirm required environment variables before coding.
- Install and configure
- Use pip packages and extras for the provider you need.
- Load env vars from the shell or a
.envfile.
- Create a basic agent
- Choose an agent type:
ChatAgent,OpenAIResponsesClient,AzureOpenAIResponsesClient, orAzureAIAgentClient(Azure AI). - Use
OpenAIChatClient(OpenAI) orAzureOpenAIResponsesClient(Azure OpenAI) for common setups. - Start with non-streaming, then add streaming if needed.
- Add tools and functions
- Python: pass callables via
tools=[...]onChatAgentor per request. - Use
HostedCodeInterpreterToolwhen you need sandboxed Python execution. - Use
@ai_function(approval_mode="always_require")for human approvals and handleuser_input_requests.
- Orchestrate multi-agent workflows
- Use
WorkflowBuilderand edges for simple graphs. - Use fan-out/fan-in and branching edge groups when you need concurrency or routing.
- Use
SequentialBuilderfor pipeline workflows andworkflow.as_agent()when you need a workflow to behave like a single agent. - Use
MagenticBuilderfor manager/participant orchestration (advanced). - Inspect
AgentRunEventoutputs to debug.
- Integrate external tools via MCP
- Use
HostedMCPToolfor Microsoft Learn MCP. - Use
MCPStreamableHTTPToolfor HTTP/SSE MCP servers.
- Add memory and storage
- Serialize/deserialize threads for persistence.
- Use a memory provider or chat message store for long-term history.
- Add middleware
- Use agent-level middleware for cross-cutting concerns (logging, security).
- Add run-level middleware when behavior is per-request.
- Integrate AG-UI (optional)
- Use AG-UI for web clients, streaming, state management, and human approvals.
Context7 usage
- Preferred library id:
/microsoft/agent-framework - Alternative docs:
/websites/learn_microsoft_en-us_agent-framework - Example queries:
- "OpenAIChatClient ChatAgent Python example"
- "AzureOpenAIResponsesClient Python example"
- "running agents run_stream Python"
- "multi-turn conversation agent threads Python"
- "WorkflowBuilder Python example"
- "HostedMCPTool MCPStreamableHTTPTool Python example"
- "SequentialBuilder workflow as_agent"
- "AzureAIAgentClient agent types Python"
References
references/quickstart.mdreferences/env-vars.mdreferences/agent-types.mdreferences/tools.mdreferences/function-tools-approvals.mdreferences/running-agents.mdreferences/agents-images.mdreferences/agents-structured-output.mdreferences/agents-as-mcp-tool.mdreferences/agents-as-tool.mdreferences/agents-memory.mdreferences/agent-rag.mdreferences/agent-middleware.mdreferences/mcp-overview.mdreferences/mcp-tools.mdreferences/ag-ui.mdreferences/workflows.mdreferences/workflow-tutorials.mdreferences/workflow-core.mdreferences/orchestrations.mdreferences/requests-responses.mdreferences/checkpointing.mdreferences/magentic.mdreferences/shared-states.mdreferences/workflow-observability.mdreferences/workflow-visualization.mdreferences/workflow-state-isolation.mdreferences/devui.mdreferences/observability.md