AI Agents for Beginners - 4. Tool Use Design Pattern
How AI agents use tools via function calling — building blocks, tool schemas, approval modes, and practical examples with Microsoft Agent Framework and Azure AI Agent Service.
June 8, 2026
AI Agents for Beginners - 4. Tool Use Design Pattern
이 글은 Microsoft의 AI Agents for Beginners 강좌 Lesson 04를 기반으로 정리한 내용입니다.
What is the Tool Use Design Pattern?
Tool Use Design Pattern은 LLM이 외부 tool과 상호작용해 특정 목표를 달성할 수 있도록 하는 패턴입니다.
Tool은 에이전트가 실행할 수 있는 코드로, 간단한 함수(계산기)부터 서드파티 API 호출(주가 조회, 날씨 예보)까지 다양합니다.
Tool은 에이전트가 실행할 수 있는 코드로, 간단한 함수(계산기)부터 서드파티 API 호출(주가 조회, 날씨 예보)까지 다양합니다.
Tool이 없는 LLM은 텍스트 생성만 합니다. Tool을 추가하면 에이전트는 model-generated function call에 응답해 실제 세계에서 행동할 수 있습니다.
Use Cases
Tool Use Design Pattern은 외부 시스템과의 동적 상호작용이 필요한 다양한 시나리오에 적용됩니다:
| Use Case | 설명 | 예시 |
|---|---|---|
| Dynamic Information Retrieval | 외부 API·DB에서 최신 데이터 조회 | SQLite 데이터 분석, 주가·날씨 정보 |
| Code Execution | 코드·스크립트 실행으로 수학 문제 해결, 보고서 생성 | Python 코드 실행, 시뮬레이션 |
| Workflow Automation | 반복적·멀티스텝 워크플로우 자동화 | 이메일 서비스, 데이터 파이프라인 |
| Customer Support | CRM·티켓 플랫폼·지식 베이스 연동 | 사용자 문의 자동 해결 |
| Content Generation | 문법 검사기, 텍스트 요약기 등 연동 | 콘텐츠 생성·편집 지원 |
Building Blocks
Tool Use Design Pattern을 구현하는 데 필요한 핵심 빌딩 블록:
| Building Block | 설명 |
|---|---|
| Function/Tool Schemas | tool 이름·목적·파라미터·출력을 정의한 상세 스키마. LLM이 사용 가능한 tool을 이해하고 올바른 요청을 생성하도록 지원 |
| Function Execution Logic | 사용자 의도와 대화 컨텍스트에 따라 tool 호출 여부·방법을 결정하는 로직 |
| Message Handling System | 사용자 입력·LLM 응답·tool call·tool 출력 간 대화 흐름을 관리하는 컴포넌트 |
| Tool Integration Framework | 에이전트를 단순 함수부터 복잡한 외부 서비스까지 연결하는 인프라 |
| Error Handling & Validation | tool 실행 실패 처리, 파라미터 검증, 예상치 못한 응답 관리 |
| State Management | 대화 컨텍스트·이전 tool 상호작용·지속 데이터를 추적해 멀티턴 일관성 보장 |
Function/Tool Calling
Function Calling은 LLM이 tool과 상호작용하는 핵심 메커니즘입니다.
구현에는 세 가지 요소가 필요합니다:
구현에는 세 가지 요소가 필요합니다:
1. Initialize an LLM
Function calling을 지원하는 LLM을 초기화합니다. Azure OpenAI가 이를 지원합니다:
init_llm.pypython
2. Create a Function Schema
LLM에게 전달할 JSON schema를 정의합니다. LLM은 이 schema를 보고 적절한 함수를 선택하고 인자를 생성합니다:
function_schema.pypython
LLM은 최종 답이 아니라 어떤 함수를 어떤 인자로 호출할지를 반환합니다.
3. Execute the Function
선택된 함수를 실행하고 결과를 LLM에게 다시 전달해 최종 응답을 생성합니다:
function_execute.pypython
zenuml title Function Calling Flow User->LLM: What time is it in San Francisco? LLM->LLM: select get_current_time from schema LLM->App: tool_call: get_current_time(location=San Francisco) App->Function: get_current_time("San Francisco") Function->App: {"current_time": "09:24 AM"} App->LLM: tool result added to messages LLM->User: The current time in San Francisco is 09:24 AM
Tool Use with Microsoft Agent Framework
MAF는
Docstring이 tool 설명, type annotation이 파라미터 schema가 되어 LLM에 자동 전달됩니다.
@tool 데코레이터로 tool 정의를 대폭 단순화합니다.Docstring이 tool 설명, type annotation이 파라미터 schema가 되어 LLM에 자동 전달됩니다.
Defining Tools
maf_tools.pypython
Using Multiple Tools
여러 tool을 agent에 등록하면 LLM이 필요에 따라 자율적으로 선택해 호출합니다:
maf_multi_tools.pypython
Structured Output with Tools
response_format에 Pydantic model을 지정하면 tool 결과를 구조화된 JSON으로 반환받을 수 있습니다:maf_structured_tools.pypython
Tool Approval Patterns
approval_mode 파라미터로 각 tool 호출에 사람의 승인이 필요한지 제어합니다:| Mode | 동작 | 사용 시나리오 |
|---|---|---|
"never_require" | 자동 실행 — 사용자 확인 불필요 | 읽기 전용 조회, 부작용 없는 함수 |
"always_require" | 매 호출마다 사용자 승인 필요 | 결제, 예약 등 부작용이 있는 함수 |
부작용이 있는 tool에는 반드시
"always_require"를 사용해 Human-in-the-loop을 유지해야 합니다:maf_approval.pypython
Tool Approval FlowMermaidflowchart TD Agent["Agent\ntool 호출 결정"] Agent --> Check{approval_mode?} Check -->|"never_require"| AutoRun["자동 실행\n(조회, 계산 등)"] Check -->|"always_require"| HumanApproval["사용자 승인 요청"] HumanApproval --> Approved{승인?} Approved -->|Yes| Execute["tool 실행"] Approved -->|No| Cancel["호출 취소"] AutoRun --> Result["결과 → LLM"] Execute --> Result
Tool Use with Azure AI Agent Service
Azure AI Agent Service는 tool을 서버 사이드에서 자동으로 처리합니다.
ToolSet으로 여러 tool을 조합하고, FunctionTool·CodeInterpreterTool 등 pre-built tool을 활용할 수 있습니다.제공되는 tool은 두 가지 카테고리로 나뉩니다:
| Category | Tools |
|---|---|
| Knowledge Tools | Grounding with Bing Search, File Search, Azure AI Search |
| Action Tools | Function Calling, Code Interpreter, OpenAPI tools, Azure Functions |
azure_ai_toolset.pypython
LLM은
toolset을 보고 사용자 요청에 따라 커스텀 함수(fetch_sales_data_using_sqlite_query)와 CodeInterpreterTool 중 적절한 것을 자율 선택합니다.Security Considerations
LLM이 동적으로 SQL을 생성할 경우 SQL injection 등 보안 위험이 있습니다.
다음 원칙으로 효과적으로 완화할 수 있습니다:
다음 원칙으로 효과적으로 완화할 수 있습니다:
- Read-only 접근 — DB에 SELECT 권한만 부여 (INSERT/UPDATE/DELETE 차단)
- 격리된 환경 — 운영 시스템과 분리된 read-only 데이터 웨어하우스 사용
- 파라미터 검증 — tool 실행 전 입력값 검증 및 sanitization
Summary
Lesson 04 SummaryMermaidflowchart LR Root["Tool Use\nDesign Pattern"] Root --> How["How It Works"] Root --> MAF["Microsoft Agent\nFramework"] Root --> AAAS["Azure AI\nAgent Service"] Root --> Safety["Safety"] How --> H1["Function Schema"] How --> H2["LLM selects tool"] How --> H3["Execute & return"] MAF --> M1["@tool decorator"] MAF --> M2["Multiple tools"] MAF --> M3["approval_mode"] AAAS --> A1["ToolSet"] AAAS --> A2["Knowledge Tools"] AAAS --> A3["Action Tools"] Safety --> S1["Read-only DB"] Safety --> S2["Human-in-the-loop"]
- Tool Use Design Pattern은 LLM에게 외부 tool을 통한 실제 행동 능력을 부여합니다
- Function Calling의 핵심은 Schema 정의 → LLM이 함수 선택 → 실행 → 결과를 LLM에 반환 사이클입니다
- @tool decorator로 Python 함수를 tool로 쉽게 변환하고,
approval_mode로 인간 감독을 유지합니다 - 부작용이 있는 tool에는 반드시
"always_require"를 사용해 Human-in-the-loop을 보장해야 합니다