AI Agents for Beginners - 14. Microsoft Agent Framework
Microsoft Agent Framework (MAF) core concepts — Agents, Threads, Middleware, Memory, Observability — and advanced workflow patterns including Sequential, Concurrent, Handoff orchestration, Middleware injection, and Human-in-the-Loop with code examples.
June 9, 2026
AI Agents for Beginners - 14. Microsoft Agent Framework
이 글은 Microsoft의 AI Agents for Beginners 강좌 Lesson 14을 기반으로 정리한 내용입니다.
AI Agent의 다양한 개념 모든 것을 프로덕션 수준으로 구현할 수 있는 Microsoft Agent Framework (MAF) 를 소개합니다.
Understanding Microsoft Agent Framework
Microsoft Agent Framework (MAF)는 프로덕션과 연구 환경 모두에서 다양한 에이전트 사용 사례를 다룰 수 있는 유연성을 제공하는 통합 프레임워크입니다.
Orchestration Types
MAF는 에이전트 협업 방식에 따라 5가지 오케스트레이션 패턴을 지원합니다:
| Orchestration | Description |
|---|---|
| Sequential | 단계별 워크플로우가 필요한 시나리오에서의 순차적 에이전트 오케스트레이션 |
| Concurrent | 에이전트가 동시에 작업을 완료해야 하는 시나리오에서의 동시 오케스트레이션 |
| Group Chat | 에이전트들이 하나의 작업을 함께 협력하는 시나리오에서의 그룹 채팅 오케스트레이션 |
| Handoff | 하위 작업이 완료될 때 에이전트가 서로 작업을 넘기는 전달 오케스트레이션 |
| Magnetic | 매니저 에이전트가 작업 목록을 만들고 하위 에이전트를 조정하는 마그네틱 오케스트레이션 |
SequentialMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A1[Agent 1] --> A2[Agent 2] --> A3[Agent 3]
ConcurrentMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR D[Dispatcher] --> A1[Agent 1] & A2[Agent 2] & A3[Agent 3]
Group ChatMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Agent A] <--> B[Agent B] B <--> C[Agent C] A <--> C
HandoffMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A1[Agent 1] -->|subtask done| A2[Agent 2] -->|subtask done| A3[Agent 3]
MagneticMermaid%%{init: {'look': 'handDrawn'}}%% flowchart TD M[Manager] --> TL[Task List] TL --> S1[Sub-Agent 1] & S2[Sub-Agent 2] & S3[Sub-Agent 3]
Production Features
MAF는 단순한 에이전트 실행을 넘어 엔터프라이즈급 기능을 내장합니다:
| Feature | Description |
|---|---|
| Observability | OpenTelemetry를 통해 모든 행동(도구 호출, 추론 흐름)을 추적하고 Microsoft Foundry 대시보드로 성능 모니터링 |
| Security | 역할 기반 접근 제어, 개인 데이터 처리, 내장 안전 콘텐츠 포함 |
| Durability | 에이전트 스레드와 워크플로우가 일시 중지·재개·오류 복구 가능한 장시간 실행 프로세스 |
| Control | 사람이 승인이 필요한 작업에 대해 Human-in-the-Loop 워크플로우 지원 |
ObservabilityMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Agent] --> T[Tool Call] --> O[OTel Trace] --> D[Dashboard]
SecurityMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR R[Request] --> RB[RBAC Check] --> A[Agent]
DurabilityMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR R[Run] --> P[Pause] --> RS[Resume] --> C[Complete]
ControlMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Agent] --> H[Human Approval] --> C[Continue]
Interoperability
MAF는 특정 벤더에 종속되지 않습니다:
| Feature | Description |
|---|---|
| Cloud-agnostic | 컨테이너, 온프레미스, 여러 클라우드 환경에서 에이전트 실행 가능 |
| Provider-agnostic | Azure OpenAI, OpenAI 등 선호하는 SDK를 통해 에이전트 생성 가능 |
| Open Standards | A2A (Agent-to-Agent) 및 MCP (Model Context Protocol)와 같은 프로토콜 활용 |
| Plugins and Connectors | Microsoft Fabric, SharePoint, Pinecone, Qdrant 등 데이터 서비스 연결 |
Cloud-agnosticMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Agent] --> C1[Container] & C2[On-prem] & C3[Multi-Cloud]
Provider-agnosticMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Agent] --> P1[Azure OpenAI] & P2[OpenAI] & P3[MiniMax]
Open StandardsMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Agent] <--> S1[A2A] & S2[MCP]
Plugins & ConnectorsMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Agent] --> P1[Fabric] & P2[SharePoint] & P3[Pinecone/Qdrant]
Key Concepts of Microsoft Agent Framework
Agents
Creating Agents
에이전트는 추론 서비스(LLM 제공자), 명령 집합,
name을 정의하여 생성합니다:다양한 LLM 제공자를 지원합니다 — Azure AI Foundry Agent Service:
OpenAI나 204K 토큰 컨텍스트 윈도우를 제공하는 MiniMax 같은 OpenAI 호환 API도 사용 가능합니다:
A2A 프로토콜을 사용하는 원격 에이전트도 지원합니다:
Running Agents
에이전트는 비스트리밍 또는 스트리밍 응답으로 실행합니다:
Non-Streaming (agent.run)Mermaid%%{init: {'look': 'handDrawn'}}%% sequenceDiagram participant User participant Agent participant LLM User->>Agent: run("question") Agent->>LLM: request Note over LLM: generates full response LLM-->>Agent: complete response Agent-->>User: result.text (all at once)
Streaming (agent.run_stream)Mermaid%%{init: {'look': 'handDrawn'}}%% sequenceDiagram participant User participant Agent participant LLM User->>Agent: run_stream("question") Agent->>LLM: request loop token by token LLM-->>Agent: chunk Agent-->>User: update.text (partial) end
각 에이전트 실행에서
max_tokens, tools, model 등의 매개변수를 사용자 정의할 수 있습니다.Tools
도구는 에이전트 정의 시에, 또는 실행 시에 제공할 수 있습니다:
Agent Threads
에이전트 스레드는 다중 턴 대화를 처리합니다.
get_new_thread()로 생성하거나 실행 시 자동으로 생성됩니다:스레드를 직렬화하여 저장하고, 이후 세션에서 재사용할 수 있습니다:
Sequence DiagramMermaid%%{init: {'look': 'handDrawn'}}%% sequenceDiagram participant User participant Agent participant Thread User->>Agent: run("Where to go?", thread=thread) Agent->>Thread: append message Agent-->>User: response User->>Agent: run("What about hotels?", thread=thread) Agent->>Thread: append message + read history Agent-->>User: response (with context) Agent->>Thread: serialize() Thread-->>Agent: serialized_thread Note over Thread: 다음 세션에서 재사용 가능
Agent Middleware
에이전트와 도구·LLM 사이에서 작업을 실행하거나 추적하려면 미들웨어를 사용합니다.
Function Middleware — executes between the agent and function/tool calls:
Chat Middleware — executes between the agent and AI service requests:
두 미들웨어 모두
next(context) 호출 전·후에 전처리/후처리 로직을 삽입합니다:Process FlowchartMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR subgraph FunctionMiddleware["Function Middleware"] direction LR Pre1["전처리\n(로깅 등)"] --> Func["실제 함수\n실행"] --> Post1["후처리\n(결과 검사)"] end subgraph ChatMiddleware["Chat Middleware"] direction LR Pre2["전처리\n(메시지 수 확인)"] --> LLM["LLM\n호출"] --> Post2["후처리\n(응답 로깅)"] end Agent --> FunctionMiddleware Agent --> ChatMiddleware
Agent Memory
MAF는 3가지 메모리 유형을 제공합니다:
In-Memory Storage — retained only during application runtime:
In-Memory StorageMermaid%%{init: {'look': 'handDrawn'}}%% sequenceDiagram participant User participant Agent participant Thread User->>Agent: run(message, thread=thread) Agent->>Thread: store message Agent-->>User: response Note over Thread: app 종료 시 소멸
Persistent Messages — stores conversation history across sessions:
Persistent MessagesMermaid%%{init: {'look': 'handDrawn'}}%% sequenceDiagram participant User participant Agent participant ChatMessageStore User->>Agent: Session 1 Agent->>ChatMessageStore: save messages Note over Agent: session ends User->>Agent: Session 2 Agent->>ChatMessageStore: load history ChatMessageStore-->>Agent: previous messages Agent-->>User: response (with context)
Dynamic Memory — added to context before agents run, stored in external services like Mem0:
Dynamic MemoryMermaid%%{init: {'look': 'handDrawn'}}%% sequenceDiagram participant User participant Agent participant Mem0 participant LLM User->>Agent: run(message) Agent->>Mem0: fetch memories Mem0-->>Agent: relevant context Agent->>LLM: messages + memory context LLM-->>Agent: response Agent-->>User: response
Agent Observability
MAF는 OpenTelemetry와 통합되어 추적과 메트릭을 제공합니다:
Workflows
MAF는 사전 정의된 단계로 작업을 완료하는 워크플로우를 제공합니다. 다중 에이전트 오케스트레이션과 Workflow Checkpointing 을 지원합니다.
Executors
실행자는 입력 메시지를 받고, 할당된 작업을 수행하며, 출력 메시지를 생성합니다. AI 에이전트나 사용자 정의 로직 모두 실행자가 될 수 있습니다.
Edges
에지는 워크플로우 내 메시지 흐름을 정의합니다:
| Edge Type | Description |
|---|---|
| Direct Edge | Simple 1 connection between executors |
| Conditional Edge | Activated after a certain condition is met |
| Switch-case Edge | Routes messages to different executors based on defined conditions |
| Fan-out Edge | Sends one message to multiple targets |
| Fan-in Edge | Collects messages from multiple executors and sends to one target |
Direct Edge Example:
Direct EdgeMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Executor A] --> B[Executor B]
Conditional EdgeMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Executor A] -->|"condition met"| B[Executor B] A -->|"condition not met"| A
Switch-case EdgeMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Executor A] -->|"case 1"| B[Executor B] A -->|"case 2"| C[Executor C] A -->|"case 3"| D[Executor D]
Fan-out EdgeMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Executor A] --> B[Executor B] A --> C[Executor C] A --> D[Executor D]
Fan-in EdgeMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR A[Executor A] --> D[Executor D] B[Executor B] --> D C[Executor C] --> D
Events
워크플로우 관찰 가능성을 위해 MAF는 다음 실행 이벤트를 제공합니다:
| Event | Triggered When |
|---|---|
WorkflowStartedEvent | 워크플로우 실행 시작 |
WorkflowOutputEvent | 워크플로우 출력 생성 |
WorkflowErrorEvent | 워크플로우에서 오류 발생 |
ExecutorInvokeEvent | 실행자 작업 시작 |
ExecutorCompleteEvent | 실행자 작업 완료 |
RequestInfoEvent | 요청이 발행됨 |
Workflow Events — Hooking PointsMermaid%%{init: {'look': 'handDrawn'}}%% sequenceDiagram participant App participant Workflow participant Executor participant Logger as Logger / Hook App->>Workflow: workflow.run_stream(input) Workflow-->>Logger: WorkflowStartedEvent loop 각 Executor 순서대로 Workflow->>Executor: invoke Executor-->>Logger: ExecutorInvokeEvent Note over Executor: 작업 처리 Executor-->>Logger: ExecutorCompleteEvent Executor->>Workflow: output end alt Human 입력 필요 Workflow-->>Logger: RequestInfoEvent Logger->>App: 사용자에게 질문 App->>Workflow: send_responses_streaming() else 오류 발생 Workflow-->>Logger: WorkflowErrorEvent end Workflow-->>Logger: WorkflowOutputEvent Workflow-->>App: 최종 결과
Advanced MAF Patterns
Sequential Orchestration
두 에이전트가 순차적으로 작업하는 패턴입니다. Front Desk Agent가 초기 추천을 제공하고, Concierge Agent가 이를 검토·평가합니다:
Process FlowchartMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR U["User Input"] --> FD["Front Desk Agent\n추천 제공"] FD --> C["Concierge Agent\n검토 및 평가"] C --> O["최종 출력\n추천 + 전문가 검토"]
순차 오케스트레이션의 주요 이점:
- Iterative Refinement: 두 번째 에이전트가 첫 번째 에이전트의 작업을 개선
- Specialization: 각 에이전트가 프로세스에서 특정 역할 담당
- Quality Control: 내장된 검토 및 검증 단계
Concurrent Orchestration
여러 에이전트를 병렬로 동시에 실행하는 패턴입니다. Fan-out/Fan-in 패턴을 사용합니다:
Process FlowchartMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR U["User Input\n도쿄 여행 추천"] --> D["InputDispatcher\n팬아웃 브로드캐스트"] D --> A["Attractions Agent\n관광 명소·활동"] D --> B["Dining Agent\n음식·식당"] D --> C["History Agent\n역사·문화"] A --> O["통합 출력\n포괄적 여행 가이드"] B --> O C --> O
Performance: 순차 실행 대비 동시 실행이 훨씬 빠릅니다. 3개 에이전트를 순차로 실행하면 각 응답 시간을 합산해야 하지만, 동시 실행은 가장 느린 에이전트 시간만 소요됩니다.
Handoff Orchestration
고객 요청의 종류에 따라 전문 에이전트에게 동적으로 작업을 인계하는 패턴입니다:
Process FlowchartMermaid%%{init: {'look': 'handDrawn'}}%% flowchart TD U["User Request"] --> CS["Customer Support Agent\n(Coordinator)"] CS -->|"항공권 예약 요청"| BA["Booking Agent\n✈️ 항공편 예약"] CS -->|"환불/분쟁 요청"| DA["Disputes Agent\n💰 환불 처리"] CS -->|"여행 확인 요청"| TA["Trip Check Agent\n🎯 일정 확인"] BA --> R["Resolution\n전문가 처리 완료"] DA --> R TA --> R
핸드오프 오케스트레이션의 핵심 이점:
- Dynamic Routing: Customer Support 에이전트가 요청 의도를 분석해 전문가에게 연결
- Context Preservation: 전환 시에도 전체 대화 이력 유지 (사용자가 정보를 반복할 필요 없음)
- Specialization: 각 에이전트가 자신의 전문 영역만 처리
Middleware Injection
미들웨어로 에이전트의 도구 함수 실행을 가로채고 결과를 수정하는 패턴입니다.
예시: 우선 회원은 호텔 가용성이 없더라도 자동으로 "이용 가능"으로 Override:
미들웨어는 에이전트 생성 시
middleware 매개변수로 주입합니다:Process FlowchartMermaid%%{init: {'look': 'handDrawn'}}%% flowchart LR subgraph Regular["일반 사용자"] direction LR R1["Paris 요청"] --> R2["hotel_booking\n파리 가용 없음"] --> R3["alternative_agent\n대안 제안"] end subgraph Priority["우선 회원"] direction LR P1["Paris 요청"] --> P2["hotel_booking\n파리 가용 없음"] --> MW["🌟 Middleware\nOverride!"] --> P3["booking_agent\n예약 진행"] end
Decorator vs Middleware:
| Feature | Decorator | Middleware |
|---|---|---|
| Scope | Single function | All functions in agent |
| Flexibility | Fixed at definition | Dynamic at runtime |
| Context | Limited | Full agent context |
| Agent-Aware | No | Yes |
Human-in-the-Loop
AI 에이전트가 실행을 일시 중지하고 인간의 입력을 요청한 후 계속 진행하는 패턴입니다. 중요한 결정, 모호한 상황, 규정 준수가 필요한 시나리오에 필수적입니다.
MAF는 3가지 핵심 컴포넌트를 제공합니다:
RequestInfoExecutor: 워크플로우를 일시 중지하고RequestInfoEvent발행RequestInfoMessage: 인간에게 보내는 요청 페이로드의 기본 클래스RequestResponse:request_id로 요청과 응답을 연결
워크플로우 구성:
Human-in-the-Loop 실행은 이벤트 기반으로 처리합니다:
Process FlowchartMermaid%%{init: {'look': 'handDrawn'}}%% flowchart TD Start["availability_agent\n가용성 확인"] -->|"가용 없음"| Conf["confirmation_agent\n확인 질문 생성"] Start -->|"가용 있음"| Book["booking_agent\n예약 권장"] Conf --> Prep["prepare_human_request\n타입 변환"] Prep --> RI["RequestInfoExecutor\n⏸️ PAUSE"] RI --> DM["DecisionManager\n인간 응답 처리"] DM -->|"yes"| Alt["alternative_agent\n대안 제안"] DM -->|"no"| Cancel["cancellation_agent\n취소 처리"] Alt --> End["display_result"] Cancel --> End Book --> End
Advanced MAF Patterns Summary
MAF를 활용한 복잡한 에이전트 구축 시 고려할 고급 패턴들:
- Middleware Composition: 함수·채팅 미들웨어를 체인으로 연결해 로깅, 인증, 속도 제한 등 여러 핸들러를 조합
- Workflow Checkpointing: 워크플로우 이벤트·직렬화를 활용해 장시간 실행되는 프로세스를 저장하고 재개
- Dynamic Tool Selection: 도구 설명에 대한 RAG와 MAF의 도구 등록을 결합해 쿼리당 관련 도구만 제시
- Multi-Agent Handoff: 워크플로우 에지·조건부 라우팅으로 전문화된 에이전트 간 핸드오프 오케스트레이션
Process FlowchartMermaid%%{init: {'look': 'handDrawn'}}%% flowchart TD MAF["Microsoft Agent\nFramework"] MAF --> Core["핵심 개념"] MAF --> WF["워크플로우"] MAF --> Pattern["고급 패턴"] Core --> Agent["에이전트\n생성·실행·도구·스레드"] Core --> MW["미들웨어\nFunction·Chat"] Core --> Mem["메모리\nIn-memory·지속·동적"] Core --> Obs["관찰 가능성\nOpenTelemetry"] WF --> Exec["Executor\nAI Agent or 커스텀 로직"] WF --> Edge["Edge\n직접·조건부·팬아웃·팬인"] WF --> Evt["Event\nStarted·Output·Error"] Pattern --> Seq["Sequential\n순차 개선"] Pattern --> Conc["Concurrent\n병렬 팬아웃"] Pattern --> HO["Handoff\n동적 라우팅"] Pattern --> MWP["Middleware\n결과 Override"] Pattern --> HITL["Human-in-the-Loop\n인간 승인 통합"]