Tool Use: Granting Claude Real Capabilities
How to teach Claude to use a calculator, database, email, Slack, code sandbox? Anatomy of tool use and production patterns.
Şükrü Yusuf KAYA
13 min read
IntermediateBu derste
Tool Use'un üç adımı: (1) tool tanımla, (2) Claude tool çağırsın, (3) sonucu döndür ve final cevap üret.
Tool Use Nedir?
Bir LLM'in metni çok iyi yazması, dünyada eylem yapabildiği anlamına gelmez. Tool Use Claude'a önceden tanımladığın fonksiyonları doğru zamanda çağırma yeteneği verir.
Tipik örnekler:
- Hesap makinesi
- Hava durumu API'si
- Veritabanı sorgusu
- E-posta gönderimi
- İç bilgi tabanı arama (RAG)
- Kod sandbox'ı
API Anatomisi#
python
import anthropicclient = anthropic.Anthropic() tools = [{ "name": "get_weather", "description": "Bir şehrin anlık hava durumunu getirir.", "input_schema": { "type": "object", "properties": { "city": {"type":"string", "description":"Şehir adı"} }, "required": ["city"] }}] resp = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, tools=tools, messages=[{"role":"user","content":"İstanbul'da bugün hava nasıl?"}],) # resp.stop_reason == "tool_use"# resp.content[0].type == "tool_use" → isim ve input içerir# Sen tool'u kendi kodunla çalıştır, sonucu role:"user", type:"tool_result" mesajıyla geri yolla Tool use temel çağrısı — Claude tool çağrısı yapar, sen koşturursun.
python
# Tool Use loop pseudo-code (yerel test)def get_weather(city: str): fake = {"İstanbul": {"temp_c": 18, "cond": "yağmurlu"}} return fake.get(city, {"temp_c": None, "cond": "bilinmiyor"}) # Claude bu adımı simüle ediyor diyelim:tool_call = {"name": "get_weather", "input": {"city": "İstanbul"}} # 1) tool çalıştırresult = get_weather(**tool_call["input"])# 2) sonucu Claude'a geri yolla (psödo)print("Tool sonucu:", result)print("Claude'un üreteceği final cevap:")print("- İstanbul'da bugün 18°C ve yağmurlu görünüyor; şemsiyeni unutma.")Tool use loop'unu sahte fonksiyonla simüle et.
json
{ "name": "search_orders", "description": "Sipariş veritabanında arama yapar. Sadece müşteri kendi sipariş kimliğini sorduğunda kullan.", "input_schema": { "type": "object", "properties": { "order_id": {"type":"string", "pattern":"^ORD-[0-9]{6}$"}, "include_items": {"type":"boolean", "default": true} }, "required": ["order_id"], "additionalProperties": false }}Üretim seviyesi tool tanımı — pattern + default + required.
Boşluk doldur · text
Tool use'da Claude tool _____ üretir, sen _____ , sonra sonucu role 'user' içinde tool_result olarak geri yollarsın. Tool tasarımının ilk kuralı _____ olmasıdır.Frequently Asked Questions
RAG is an architecture pattern often implemented with a single tool ('search_knowledge_base'). Tool use is the underlying capability.
Yorumlar & Soru-Cevap
(0)Yorum yazmak için giriş yap.
Yorumlar yükleniyor...
Related Content
Connected pillar topics