הכלי הנכון למשימה הנכונה
מי מחליט מתי ואיזה כלי להפעיל? למדו על tool_choice — ארבע אופציות שקובעות את כל ההתנהגות של הסוכן.
Claude יכול להשתמש בכלים לבד. אבל מי מחליט מתי, באיזה, וכמה? אתם. עם פרמטר אחד: tool_choice.
import anthropic
client = anthropic.Anthropic()
# auto — Claude decides (default)
response = client.messages.create(
model="claude-sonnet-4-20250514",
tools=tools,
tool_choice={"type": "auto"}, # default
messages=messages,
)
# any — must use at least one tool
response = client.messages.create(
model="claude-sonnet-4-20250514",
tools=tools,
tool_choice={"type": "any"},
messages=messages,
)
# tool — must use a specific tool
response = client.messages.create(
model="claude-sonnet-4-20250514",
tools=tools,
tool_choice={"type": "tool", "name": "search_database"},
messages=messages,
)
# none — no tools allowed
response = client.messages.create(
model="claude-sonnet-4-20250514",
tools=tools,
tool_choice={"type": "none"},
messages=messages,
)ארבע אופציות — מ-auto (גמיש) עד none (חסום)
כברירת מחדל Claude יכול לקרוא למספר כלים במקביל. הגדרו disable_parallel_tool_use: true כדי לאלץ מקסימום כלי אחד לכל תשובה. שימושי כשקריאות כלים חייבות להיות סדרתיות.
💡 טיפ: ככל שצריכים יותר שליטה — עוברים מ-auto ל-tool. ככל שצריכים יותר גמישות — נשארים על auto. בבחינה ישאלו מתי להשתמש בכל אחד.
💡 טיפ: בפרק הבא (יום 11) נלמד על שרתי MCP — הפרוטוקול שמחבר כלים לסוכנים בצורה סטנדרטית.