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?").