מתי להשתמש
"Function calling", "Tool use", "AI calling APIs", "Structured tool invocation".
הוראות עבודה
1. What is Tool Use
LLM decides when to call a function/API and with what parameters. You define tools, LLM picks + calls them.
2. Common Tools
- search (web, internal).
- calculator.
- database queries.
- email/Slack send.
- calendar booking.
- file operations.
- payment/transaction (with safeguards).
- custom APIs.
3. Tool Definition (Anthropic)
tools = [
{
"name": "get_weather",
"description": "Get current weather for a location.",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name, e.g., 'Tel Aviv'"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"default": "celsius"
}
},
"required": ["location"]
}
}
]
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "Weather in Tel Aviv?"}]
)
4. Tool Execution Loop
while True:
response = client.messages.create(...)
if response.stop_reason == "tool_use":
for block in response.content:
if block.type == "tool_use":
# Execute tool
result = my_function(block.name, block.input)
# Send result back
messages.append(...)
elif response.stop_reason == "end_turn":
break
5. Parallel Tool Calls
Feature
- LLM can call multiple tools in one turn.
- Faster than sequential.
Example
# User asks: "Weather in Tel Aviv and Jerusalem?"
# LLM responds with 2 tool_use blocks (parallel).
# You execute both, send back both results.
6. Tool Schema Best Practices
Description
- Clear — what the tool does.
- When to use — guide LLM.
- Examples — in description.
Parameters
- Specific names —
customer_idnotid. - Types correct.
- Required vs Optional clear.
- Enums for finite choices.
Example: Good
{
"name": "send_invoice",
"description": "Send invoice to customer via email. Use only after customer confirms purchase.",
"input_schema": {
"type": "object",
"properties": {
"customer_id": {"type": "string", "description": "Internal customer ID, e.g., 'cust_123'"},
"amount": {"type": "number", "description": "Invoice amount in USD"},
"due_date": {"type": "string", "format": "date", "description": "ISO date YYYY-MM-DD"}
},
"required": ["customer_id", "amount", "due_date"]
}
}
7. Error Handling
Tool Errors
- Return error info to LLM.
- LLM can retry / handle gracefully.
tool_result = {
"type": "tool_result",
"tool_use_id": tool_use.id,
"content": "Error: Customer not found",
"is_error": True
}
8. Safety
Approval Gates
- Destructive tools (delete, send_money) → human approval.
- Show preview before execution.
Rate Limiting
- Limit tool calls per task.
- Prevent runaway loops.
Validation
- Validate tool inputs before execution.
- Sanitize for SQL injection, XSS.
9. Streaming with Tools
- Stream LLM response.
- Once tool_use detected, execute.
- Continue stream.
10. Cost
- Tools add tokens (description + result).
- Each round-trip = 1 LLM call.
- 3-tool agent task ≈ 3-5 LLM calls.
11. Common Pitfalls
❌ Bad descriptions — LLM picks wrong tool. ❌ No safety — agent does damage. ❌ Loops — LLM keeps calling same tool. ❌ No error handling — silent failures. ❌ Over-permissive — too many tools = confusion.
12. Israel Specifics
- Hebrew tool descriptions — work fine.
- Israeli APIs can be tools (HiBob, monday).
13. אסיים בהמלצה.
פרומפט לדוגמה
Define tools for sales agent (lookup, send email, schedule).
Parallel tool use — when to use?
Tool description templates.
© 2026 AI Expert Pro | גרסה 1.0.0