Tool calling (function calling): app khai báo danh sách tool với JSON schema (tên, mô tả, parameters). LLM đọc câu hỏi, nếu cần dùng tool sẽ trả về structured output {"tool": "search", "args": {"query": "..."}}. App thực thi tool, trả kết quả vào context, LLM tiếp tục. OpenAI, Anthropic, Google đều support native.
Schema ví dụ:
{
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
"unit": {"type": "string", "enum": ["c", "f"]}
},
"required": ["city"]
}
}Design tool tốt:
1. Mô tả rõ ràng — name + description kể rõ WHEN to use, input/output format, edge case. Description là prompt chính cho LLM chọn tool.
2. Ít tool, scope rõ — >20 tool thì accuracy chọn tool giảm mạnh. Nhóm thành tool cha hoặc dùng tool routing.
3. Parameters hẹp — dùng enum, regex, min/max thay vì string tự do; output trả JSON chuẩn với status, data, error.
4. Idempotent & safe — action destructive (delete, send money) phải cần human confirm; error message giúp agent tự-fix ("city not found, did you mean: Hanoi?").
Tool calling (function calling): the app declares a list of tools with JSON schemas (name, description, parameters). The LLM reads the query and, when a tool is needed, returns structured output {"tool": "search", "args": {"query": "..."}}. The app runs the tool, returns the result into context, and the LLM continues. OpenAI, Anthropic, Google all support it natively.
Example schema:
{
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
"unit": {"type": "string", "enum": ["c", "f"]}
},
"required": ["city"]
}
}Good tool design:
1. Clear descriptions — name + description state WHEN to use, input/output format, edge cases. The description is the main prompt the LLM uses to choose.
2. Few tools, tight scope — >20 tools and selection accuracy tanks. Group into parent tools or use tool routing.
3. Narrow parameters — use enum, regex, min/max instead of free text; return JSON with status, data, error.
4. Idempotent & safe — destructive actions (delete, send money) require human confirmation; error messages should self-fix ("city not found, did you mean: Hanoi?").