Tool Use + Function Calling: LLM's Doors to External World — From OpenAI Tools to MCP
Tool Use anatomy: LLM reading JSON schema tool definitions, choosing right tool with right parameters. OpenAI function calling (June 2023), Anthropic MCP (Model Context Protocol, Nov 2024), Llama-3 tool tokens. Production agent patterns: ReAct, Plan-and-Execute, Reflexion. Turkish agent practice.
Şükrü Yusuf KAYA
75 min read
Advanced🔧 Tool Use — LLM'in 'eylem yapma' yeteneği
Yalıtılmış LLM: 'Bugün hava nasıl?' Cevap: 'Bilmiyorum, gerçek-zamanlı veriye erişimim yok.' Tool-equipped LLM: aynı soruyu weather API'a query, sonuç döndür. Function calling (OpenAI Haziran 2023) ve sonra MCP (Anthropic Kasım 2024) LLM ajanları'nın temel taşı oldu. ChatGPT plugins, Claude Code, AutoGen, LangChain agents — hepsi tool use. 75 dakika sonra: function calling matematik, JSON schema patterns, ReAct/Plan-Execute/Reflexion agent design pattern'leri, MCP standard'ı, Türkçe agent uygulamasını kavramış olacaksın.
Ders Haritası (10 Bölüm)#
- Tool Use motivasyonu — LLM'in 'eylemsizlik' problemi
- OpenAI function calling — Haziran 2023 lansman
- JSON schema tool definitions — name, description, parameters
- Tool selection logic — model nasıl karar veriyor
- Anthropic MCP — open standard Kasım 2024
- Llama-3 tool tokens — open-source tool use
- ReAct pattern — Reasoning + Acting iteratif
- Plan-and-Execute — first plan, then execute
- Reflexion — self-critique loop
- Türkçe agent — production deployment
2-4. OpenAI Function Calling#
2.1 Function calling basic#
OpenAI API'ye tool tanımları ver:
from openai import OpenAI client = OpenAI() tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Belirtilen şehir için hava durumunu döndürür", "parameters": { "type": "object", "properties": { "city": {"type": "string", "description": "Şehir adı (örn: İstanbul, Ankara)"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, }, "required": ["city"], }, }, } ] response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "İstanbul'da hava nasıl?"}], tools=tools, tool_choice="auto", ) # Response.tool_calls içerir: # {'function': {'name': 'get_weather', 'arguments': '{"city": "İstanbul"}'}}
2.2 Tool call cycle#
[1] User query → LLM [2] LLM decides: tool needed? Yes → output tool_call (JSON with name + arguments) No → output text response [3] Application executes tool, gets result [4] Result sent back to LLM as tool message [5] LLM combines: final response to user
2.3 Multi-tool, parallel tool calls#
GPT-4o supports multiple tool calls in single response:
User: 'İstanbul ve Ankara'da hava nasıl?' LLM: [get_weather('İstanbul'), get_weather('Ankara')] # parallel
2.4 Tool selection math#
LLM'in mekanizması: prompt + tool descriptions → next token distribution. Eğer tool tokens (e.g., <function_call>) yüksek probability → tool call. Else text.
RL training: model 'tool kullanmak gerektiğinde' learn eder.
5-9. MCP + Agent Patterns#
5.1 Anthropic MCP (Model Context Protocol, Kasım 2024)#
Problem: her LLM provider farklı tool format. MCP open standard: tool definitions, context sharing, cross-provider compatibility.
{ "name": "github_search", "description": "Search GitHub repositories", "inputSchema": { "type": "object", "properties": { "query": {"type": "string"}, "language": {"type": "string"} } } }
MCP server: provides tools. MCP client: LLM (Claude, ChatGPT, Llama via adapter).
5.2 MCP ecosystem 2025#
MCP servers: GitHub, Slack, Google Drive, Notion, databases, file systems.
Adoption: Claude Desktop, Cursor, Continue.dev — all MCP-compatible.
Future: cross-platform AI agent standard.
5.3 Llama-3 tool use#
Llama-3-8B-Instruct supports tools:
<|python_tag|>{"name": "get_weather", "parameters": {"city": "İstanbul"}}<|eom_id|>
Python-tag indicates function call. Different from ChatML but same logic.
5.4 ReAct pattern (Yao 2022)#
'Reasoning + Acting' iteratif:
Thought: 'Need weather info for trip planning' Action: get_weather('İstanbul') Observation: '22°C, sunny' Thought: 'Good weather. Now check Ankara.' Action: get_weather('Ankara') Observation: '15°C, cloudy' Thought: 'Have data for both. Final response.' Answer: 'İstanbul 22°C güneşli, Ankara 15°C bulutlu.'
Multi-step reasoning + action loop.
5.5 Plan-and-Execute#
First create full plan, then execute:
Plan: 1. Get weather for İstanbul 2. Get weather for Ankara 3. Compare and summarize Execute step 1... Execute step 2... Execute step 3... Final answer.
More deliberate, less back-and-forth.
5.6 Reflexion (Shinn 2023)#
Self-critique after action:
Attempt 1: Output X Critic: 'Output doesn't address user's question fully.' Reflect: 'Need to include source information.' Attempt 2: Output Y (improved)
Iterative refinement. Used in coding agents (Cursor, Claude Code).
5.7 Production agent: Türkçe assistant#
Example: 'Bugün İstanbul'da hangi etkinlikler var?'
Tools:
- search_events(city, date)
- get_weather(city)
- send_email(to, subject, body)
Agent: weather check → event search → optional email recommendation.
🎉 Modül 20 Tamamlandı — AI Agents
Tool Use: LLM'in dış dünyaya açılan kapısı. OpenAI function calling (Haziran 2023) foundation. MCP (Anthropic Kasım 2024) open standard cross-provider. Agent patterns: ReAct (iteratif), Plan-Execute (deliberate), Reflexion (self-critique). Llama-3 `<|python_tag|>` tool tokens. Production: LangChain, AutoGen, Claude Desktop, Cursor — hepsi tool use. Türkçe agent practical. Modül 20 envanteri: 1 ders, 75 dk. Genel müfredat: 21 modül, 92 ders, ~101 saat.
Modül 20 Envanteri (Tamamlandı)#
| # | Ders | Süre |
|---|---|---|
| 20.1 | Tool Use + Function Calling + MCP | 75 dk |
| Toplam | 1 ders | 75 dk |
Frequently Asked Questions
OpenAI function calling provider-specific. MCP open standard cross-provider. MCP becoming industry standard in 2025. Even OpenAI has MCP-compatible roadmap.
Yorumlar & Soru-Cevap
(0)Yorum yazmak için giriş yap.
Yorumlar yükleniyor...
Related Content
Module 0: Course Framework & Workshop Setup
Who Is an LLM Engineer? The AI Engineering Career Ladder from Junior to Staff
Start LearningModule 0: Course Framework & Workshop Setup
Course Philosophy: Why This Path, Why This Order — The Skeleton of an 8-Month Curriculum
Start LearningModule 0: Course Framework & Workshop Setup
Workshop Setup: uv, PyTorch 2.5+, CUDA, WSL2, Mac MPS, Triton, FlashAttention, Nsight
Start LearningConnected pillar topics