איך Claude מדבר עם העולם האמיתי
מה הופך צ'אטבוט לסוכן AI? כלים. למדו איך Claude מבקש להפעיל כלים, stop_reason, ולמה התיאור חשוב מהשם.
כלים. אפשר לצרף רשימת כלים לכל קריאה ל-Claude API. כל כלי מוגדר עם שם (name), תיאור (description), וסכמת קלט (input_schema).
Claude לא ניגש לאינטרנט, לא מריץ קוד, ולא שולח מיילים. הוא מחזיר בלוק tool_use שאומר "אני רוצה להריץ את הכלי הזה עם הפרמטרים האלה." הקוד שלכם מריץ את הכלי, מחזיר tool_result, ו-Claude בונה את התשובה הסופית.
import anthropic
client = anthropic.Anthropic()
# Define a tool
tools = [{
"name": "get_weather",
"description": "Get current weather for a city. Use when the user asks about weather conditions.",
"input_schema": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}]
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in Tel Aviv?"}]
)
# Check if Claude wants to use a tool
if response.stop_reason == "tool_use":
tool_block = next(b for b in response.content if b.type == "tool_use")
print(f"Claude wants to call: {tool_block.name}")
print(f"With params: {tool_block.input}")
# → Your code runs the actual API call hereClaude מחזיר tool_use — הקוד שלכם מריץ את הכלי בפועל
💡 טיפ: התיאור של הכלי חשוב יותר מהשם. Claude מחליט אם להשתמש בכלי בעיקר לפי ה-description. תכתבו תיאורים מפורטים — ככל שיותר ברור, ככה Claude ישתמש נכון.
💡 טיפ: בפרק הבא (יום 9) נלמד מה קורה כשכלי נכשל — Error Responses.