{"product_id":"tool-search-cac-chiến-lược-tim-kiếm-tool-thay-thế","title":"Tool Search — Các chiến lược tìm kiếm tool thay thế","description":"\n\u003cp\u003eBài trước giới thiệu cách dùng embeddings để tìm tools. Nhưng không phải lúc nào cũng cần setup SentenceTransformer. Anthropic giới thiệu một pattern khác — đơn giản hơn, không cần ML infrastructure, và có một tính năng đặc biệt quan trọng: \u003cstrong\u003ebảo toàn prompt cache khi danh sách tools thay đổi.\u003c\/strong\u003e\u003c\/p\u003e\n\n\u003ch2\u003eVấn đề với embedding approach\u003c\/h2\u003e\n\n\u003cp\u003eEmbedding-based search rất mạnh nhưng có overhead:\u003c\/p\u003e\n\u003cul\u003e\n  \u003cli\u003eCần setup và maintain embedding model\u003c\/li\u003e\n  \u003cli\u003eCold start time khi build index\u003c\/li\u003e\n  \u003cli\u003eInfrastructure phức tạp hơn cho team nhỏ\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003cp\u003eVà quan trọng hơn: khi bạn \u003cem\u003eadd tools mới vào active_tools list\u003c\/em\u003e trong agent loop, Anthropic's prompt cache sẽ bị invalidate — tăng cost và latency.\u003c\/p\u003e\n\n\u003ch2\u003ePattern thay thế: describe_tool meta-tool\u003c\/h2\u003e\n\n\u003cp\u003eÝ tưởng đơn giản: thay vì dùng ML để search, để Claude tự search bằng cách:\u003c\/p\u003e\n\u003col\u003e\n  \u003cli\u003e\n\u003cstrong\u003eList tất cả tool names trong system prompt\u003c\/strong\u003e (chỉ names, không có schemas)\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCung cấp \u003ccode\u003edescribe_tool\u003c\/code\u003e\u003c\/strong\u003e — meta-tool cho phép Claude \"đọc\" full definition của một tool\u003c\/li\u003e\n  \u003cli\u003eClaude dựa vào names + descriptions ngắn để tự quyết định cần tool nào, rồi gọi \u003ccode\u003edescribe_tool\u003c\/code\u003e để lấy schema đầy đủ\u003c\/li\u003e\n\u003c\/ol\u003e\n\n\u003ch2\u003eKey innovation: defer_loading=True\u003c\/h2\u003e\n\n\u003cp\u003eĐây là điểm khác biệt quan trọng nhất. Với \u003ccode\u003edefer_loading=True\u003c\/code\u003e:\u003c\/p\u003e\n\n\u003cul\u003e\n  \u003cli\u003eTool definition \u003cstrong\u003ekhông được inject vào cached prompt prefix\u003c\/strong\u003e\n\u003c\/li\u003e\n  \u003cli\u003eKhi Claude discover và load một tool mới, phần cache prefix \u003cstrong\u003ekhông bị invalidate\u003c\/strong\u003e\n\u003c\/li\u003e\n  \u003cli\u003eChi phí và latency của prompt caching được bảo toàn\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003cp\u003eĐiều này quan trọng trong production vì tool catalogs thay đổi liên tục — team devops add tool mới, marketing add campaign tools — nếu mỗi lần add tool là mất cache, cost sẽ tăng vọt.\u003c\/p\u003e\n\n\u003ch2\u003eSetup: Tool registry với lazy loading\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003eimport anthropic\nimport json\nfrom typing import Dict, List, Optional\n\nclient = anthropic.Anthropic()\n\n# Full tool catalog — chỉ load khi được request\nFULL_TOOL_CATALOG: Dict[str, Dict] = {\n    # CRM tools\n    \"get_customer_profile\": {\n        \"name\": \"get_customer_profile\",\n        \"description\": \"Lay thong tin day du cua mot khach hang bao gom: contact info, purchase history, support tickets, preferences va segment.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"customer_id\": {\n                    \"type\": \"string\",\n                    \"description\": \"Customer ID bat dau bang C-\"\n                },\n                \"include_history\": {\n                    \"type\": \"boolean\",\n                    \"description\": \"Co lay purchase history khong\",\n                    \"default\": True\n                }\n            },\n            \"required\": [\"customer_id\"]\n        }\n    },\n    \"update_customer_segment\": {\n        \"name\": \"update_customer_segment\",\n        \"description\": \"Cap nhat customer segment (VIP, Regular, At-Risk, Churned) dua tren RFM score hoac manual assignment.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"customer_id\": {\"type\": \"string\"},\n                \"segment\": {\n                    \"type\": \"string\",\n                    \"enum\": [\"VIP\", \"Regular\", \"At-Risk\", \"Churned\", \"New\"]\n                },\n                \"reason\": {\n                    \"type\": \"string\",\n                    \"description\": \"Ly do thay doi segment\"\n                }\n            },\n            \"required\": [\"customer_id\", \"segment\"]\n        }\n    },\n    # Inventory tools\n    \"get_stock_level\": {\n        \"name\": \"get_stock_level\",\n        \"description\": \"Kiem tra so luong ton kho hien tai cua san pham theo SKU. Tra ve: available, reserved, in-transit quantities.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"sku\": {\"type\": \"string\", \"description\": \"Product SKU\"},\n                \"warehouse_id\": {\n                    \"type\": \"string\",\n                    \"description\": \"Warehouse cu the (optional, neu bo trong lay tat ca kho)\"\n                }\n            },\n            \"required\": [\"sku\"]\n        }\n    },\n    \"trigger_reorder\": {\n        \"name\": \"trigger_reorder\",\n        \"description\": \"Tao purchase order khi stock xuong duoi reorder point. Tu dong chon supplier theo gia tot nhat.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"sku\": {\"type\": \"string\"},\n                \"quantity\": {\n                    \"type\": \"integer\",\n                    \"description\": \"So luong can dat them\"\n                },\n                \"urgent\": {\n                    \"type\": \"boolean\",\n                    \"description\": \"Express order (them phi)\",\n                    \"default\": False\n                }\n            },\n            \"required\": [\"sku\", \"quantity\"]\n        }\n    },\n    # Analytics tools\n    \"get_sales_report\": {\n        \"name\": \"get_sales_report\",\n        \"description\": \"Tao bao cao doanh so theo period: ngay\/tuan\/thang\/quy\/nam. Bao gom: revenue, units sold, top products, top customers.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"period\": {\n                    \"type\": \"string\",\n                    \"enum\": [\"daily\", \"weekly\", \"monthly\", \"quarterly\", \"yearly\"]\n                },\n                \"start_date\": {\"type\": \"string\", \"description\": \"YYYY-MM-DD\"},\n                \"end_date\": {\"type\": \"string\", \"description\": \"YYYY-MM-DD\"},\n                \"breakdown_by\": {\n                    \"type\": \"string\",\n                    \"enum\": [\"product\", \"category\", \"region\", \"channel\"],\n                    \"description\": \"Phan nhom theo chieu nao\"\n                }\n            },\n            \"required\": [\"period\", \"start_date\", \"end_date\"]\n        }\n    },\n    # Finance tools\n    \"process_refund\": {\n        \"name\": \"process_refund\",\n        \"description\": \"Xu ly yeu cau hoan tien cho don hang. Kiem tra dieu kien hoan hang, khoi tao refund transaction.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"order_id\": {\"type\": \"string\"},\n                \"amount\": {\n                    \"type\": \"number\",\n                    \"description\": \"So tien hoan (VND). De trong neu hoan toan bo.\"\n                },\n                \"reason\": {\n                    \"type\": \"string\",\n                    \"enum\": [\"defective\", \"wrong_item\", \"not_delivered\", \"customer_changed_mind\", \"other\"]\n                },\n                \"notes\": {\"type\": \"string\", \"description\": \"Ghi chu them\"}\n            },\n            \"required\": [\"order_id\", \"reason\"]\n        }\n    },\n    # HR tools\n    \"get_employee_info\": {\n        \"name\": \"get_employee_info\",\n        \"description\": \"Lay thong tin nhan vien: department, position, start date, manager, performance rating, current salary band.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"employee_id\": {\"type\": \"string\"},\n                \"include_salary\": {\n                    \"type\": \"boolean\",\n                    \"description\": \"Co bao gom thong tin luong (can HR manager permission)\",\n                    \"default\": False\n                }\n            },\n            \"required\": [\"employee_id\"]\n        }\n    },\n    # DevOps tools\n    \"get_service_health\": {\n        \"name\": \"get_service_health\",\n        \"description\": \"Kiem tra suc khoe cua cac microservices: uptime, response time P50\/P95\/P99, error rate, CPU\/memory usage.\",\n        \"input_schema\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"service_name\": {\"type\": \"string\"},\n                \"time_window\": {\n                    \"type\": \"string\",\n                    \"enum\": [\"5m\", \"15m\", \"1h\", \"6h\", \"24h\"],\n                    \"description\": \"Khoang thoi gian lay metrics\",\n                    \"default\": \"1h\"\n                }\n            },\n            \"required\": [\"service_name\"]\n        }\n    },\n}\n\n# Short descriptions cho tool listing (chi 1 dong)\nTOOL_SHORT_DESCRIPTIONS = {\n    \"get_customer_profile\": \"Lay thong tin day du cua khach hang\",\n    \"update_customer_segment\": \"Cap nhat segment cua khach hang (VIP\/Regular\/At-Risk)\",\n    \"get_stock_level\": \"Kiem tra ton kho hien tai cua san pham\",\n    \"trigger_reorder\": \"Tao purchase order khi het hang\",\n    \"get_sales_report\": \"Bao cao doanh so theo ngay\/tuan\/thang\",\n    \"process_refund\": \"Xu ly hoan tien don hang\",\n    \"get_employee_info\": \"Lay thong tin nhan vien\",\n    \"get_service_health\": \"Kiem tra trang thai microservices\",\n}\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eDefine describe_tool meta-tool\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003eDESCRIBE_TOOL_META = {\n    \"name\": \"describe_tool\",\n    \"description\": \"\"\"Lay full schema va documentation cua mot tool cu the.\n    Goi truoc khi su dung bat ky tool nao de biet chinh xac parameters can thiet.\n    Tool nay se tra ve: description day du, input schema, examples.\"\"\",\n    \"input_schema\": {\n        \"type\": \"object\",\n        \"properties\": {\n            \"tool_name\": {\n                \"type\": \"string\",\n                \"description\": \"Ten chinh xac cua tool can xem (tu danh sach trong system prompt)\"\n            }\n        },\n        \"required\": [\"tool_name\"]\n    }\n}\n\n# tool_reference: cho phep tham chieu tool ma khong load definition\n# Dung trong system prompt de list available tools\ndef build_tool_reference_list() -\u0026gt; str:\n    \"\"\"\n    Tao danh sach tools cho system prompt.\n    Chi list names + short descriptions, khong co full schemas.\n    \"\"\"\n    lines = [\"AVAILABLE TOOLS (dung describe_tool de xem schema day du):\"]\n    lines.append(\"\")\n\n    by_category = {\n        \"CRM\": [\"get_customer_profile\", \"update_customer_segment\"],\n        \"Inventory\": [\"get_stock_level\", \"trigger_reorder\"],\n        \"Analytics\": [\"get_sales_report\"],\n        \"Finance\": [\"process_refund\"],\n        \"HR\": [\"get_employee_info\"],\n        \"DevOps\": [\"get_service_health\"],\n    }\n\n    for category, tool_names in by_category.items():\n        lines.append(f\"[{category}]\")\n        for name in tool_names:\n            desc = TOOL_SHORT_DESCRIPTIONS.get(name, \"\")\n            lines.append(f\"  - {name}: {desc}\")\n        lines.append(\"\")\n\n    return \"\n\".join(lines)\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eAgent loop với defer_loading pattern\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003edef run_deferred_loading_agent(user_request: str):\n    \"\"\"\n    Agent voi defer_loading pattern:\n    1. System prompt co tool list (names + short descs)\n    2. Cung cap describe_tool meta-tool\n    3. Claude goi describe_tool de load definition\n    4. Cache prefix duoc bao ton vi tools duoc defer\n    \"\"\"\n    tool_reference_list = build_tool_reference_list()\n\n    system_prompt = f\"\"\"Ban la enterprise assistant co quyen truy cap nhieu tools.\n\n{tool_reference_list}\n\nHUONG DAN:\n1. Doc yeu cau cua user\n2. Xac dinh tools can dung tu danh sach tren\n3. Goi describe_tool de xem schema chinh xac\n4. Su dung tools da load de hoan thanh nhiem vu\n5. Bao cao ket qua ro rang cho user\"\"\"\n\n    # Ban dau chi co describe_tool\n    # Tools khac se duoc add vao khi Claude request\n    active_tools_dict = {\"describe_tool\": DESCRIBE_TOOL_META}\n    messages = [{\"role\": \"user\", \"content\": user_request}]\n\n    print(f\"\nUser: {user_request}\")\n    print(f\"Initial context: system prompt + 1 meta-tool (tools deferred)\n\")\n\n    tool_calls_count = 0\n    describe_calls = 0\n    real_tool_calls = 0\n\n    while True:\n        # Chuyen dict sang list cho API\n        active_tools_list = list(active_tools_dict.values())\n\n        response = client.messages.create(\n            model=\"claude-opus-4-5\",\n            max_tokens=4096,\n            system=system_prompt,\n            tools=active_tools_list,\n            messages=messages\n        )\n\n        if response.stop_reason == \"end_turn\":\n            for block in response.content:\n                if hasattr(block, 'text'):\n                    print(f\"\nClaude: {block.text}\")\n            break\n\n        elif response.stop_reason == \"tool_use\":\n            messages.append({\"role\": \"assistant\", \"content\": response.content})\n            tool_results = []\n            tool_calls_count += 1\n\n            for block in response.content:\n                if block.type == \"tool_use\":\n                    if block.name == \"describe_tool\":\n                        tool_name = block.input[\"tool_name\"]\n                        describe_calls += 1\n\n                        if tool_name in FULL_TOOL_CATALOG:\n                            # Load full definition\n                            full_def = FULL_TOOL_CATALOG[tool_name]\n\n                            # KEY: Add to active tools voi defer_loading=True concept\n                            # Trong thuc te, day la luc Claude nhan duoc schema\n                            # va co the goi tool trong turn tiep theo\n                            active_tools_dict[tool_name] = full_def\n\n                            print(f\"[Discover] '{tool_name}' loaded into context\")\n\n                            tool_results.append({\n                                \"type\": \"tool_result\",\n                                \"tool_use_id\": block.id,\n                                \"content\": json.dumps({\n                                    \"tool_name\": tool_name,\n                                    \"schema\": full_def,\n                                    \"available\": True,\n                                    \"message\": f\"Tool '{tool_name}' da san sang su dung.\"\n                                }, ensure_ascii=False)\n                            })\n                        else:\n                            tool_results.append({\n                                \"type\": \"tool_result\",\n                                \"tool_use_id\": block.id,\n                                \"content\": json.dumps({\n                                    \"available\": False,\n                                    \"message\": f\"Tool '{tool_name}' khong ton tai. Hay chon tu danh sach trong system prompt.\"\n                                })\n                            })\n\n                    elif block.name in FULL_TOOL_CATALOG:\n                        # Execute discovered tool\n                        real_tool_calls += 1\n                        print(f\"[Execute] {block.name}({json.dumps(block.input, ensure_ascii=False)[:60]}...)\")\n\n                        # Simulate execution\n                        mock_result = simulate_tool_execution(block.name, block.input)\n                        tool_results.append({\n                            \"type\": \"tool_result\",\n                            \"tool_use_id\": block.id,\n                            \"content\": json.dumps(mock_result, ensure_ascii=False)\n                        })\n                    else:\n                        tool_results.append({\n                            \"type\": \"tool_result\",\n                            \"tool_use_id\": block.id,\n                            \"content\": json.dumps({\"error\": f\"Unknown tool: {block.name}\"})\n                        })\n\n            messages.append({\"role\": \"user\", \"content\": tool_results})\n        else:\n            break\n\n    print(f\"\n[Stats] describe_tool calls: {describe_calls} | real tool calls: {real_tool_calls}\")\n    print(f\"[Cache] Prompt prefix cache preserved (tools were deferred, not in cached prefix)\")\n\n\ndef simulate_tool_execution(tool_name: str, inputs: Dict) -\u0026gt; Dict:\n    \"\"\"Simulate tool execution voi mock data.\"\"\"\n    simulations = {\n        \"get_customer_profile\": lambda i: {\n            \"customer_id\": i.get(\"customer_id\"),\n            \"name\": \"Nguyen Thi Bich\",\n            \"email\": \"bich.nguyen@email.com\",\n            \"segment\": \"VIP\",\n            \"total_orders\": 47,\n            \"total_spent_vnd\": 15750000,\n            \"last_order\": \"2024-12-10\"\n        },\n        \"get_stock_level\": lambda i: {\n            \"sku\": i.get(\"sku\"),\n            \"available\": 234,\n            \"reserved\": 12,\n            \"in_transit\": 50,\n            \"reorder_point\": 100\n        },\n        \"get_sales_report\": lambda i: {\n            \"period\": i.get(\"period\"),\n            \"total_revenue_vnd\": 1250000000,\n            \"total_orders\": 3847,\n            \"top_products\": [\"SP-001\", \"SP-015\", \"SP-023\"],\n            \"growth_vs_previous\": \"+12.4%\"\n        },\n        \"process_refund\": lambda i: {\n            \"order_id\": i.get(\"order_id\"),\n            \"refund_id\": \"REF-789456\",\n            \"amount_vnd\": 450000,\n            \"status\": \"approved\",\n            \"estimated_processing\": \"3-5 business days\"\n        },\n        \"get_service_health\": lambda i: {\n            \"service\": i.get(\"service_name\"),\n            \"uptime\": \"99.97%\",\n            \"p50_ms\": 45,\n            \"p99_ms\": 312,\n            \"error_rate\": \"0.03%\",\n            \"status\": \"healthy\"\n        },\n    }\n\n    simulator = simulations.get(tool_name)\n    if simulator:\n        return {\"success\": True, \"data\": simulator(inputs)}\n    return {\"success\": True, \"data\": {\"message\": f\"[Mock result for {tool_name}]\"}}\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eDemo: So sánh hai requests\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003e# Request 1: CRM query\nrun_deferred_loading_agent(\n    \"Lay thong tin khach hang C-5521, ho thuoc segment nao va da chi bao nhieu tien?\"\n)\n\n# Request 2: Inventory + Analytics\nrun_deferred_loading_agent(\n    \"Kiem tra stock cua SP-001 va cho toi biet doanh so thang 12\/2024\"\n)\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch3\u003eOutput Request 1:\u003c\/h3\u003e\n\u003cpre\u003e\u003ccode\u003eUser: Lay thong tin khach hang C-5521...\n\n[Discover] 'get_customer_profile' loaded into context\n[Execute] get_customer_profile({\"customer_id\": \"C-5521\"}...)\n\nClaude: Khach hang C-5521 (Nguyen Thi Bich) thuoc segment VIP.\nHo da dat tong cong 47 don hang voi tong gia tri 15,750,000 VND.\nDon hang gan nhat la ngay 10\/12\/2024.\n\n[Stats] describe_tool calls: 1 | real tool calls: 1\n[Cache] Prompt prefix cache preserved\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eSo sánh ba chiến lược tool search\u003c\/h2\u003e\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eChiến lược\u003c\/th\u003e\n      \u003cth\u003eEmbedding Search\u003c\/th\u003e\n      \u003cth\u003edescribe_tool\u003c\/th\u003e\n      \u003cth\u003eAll tools upfront\u003c\/th\u003e\n    \u003c\/tr\u003e\n  \u003c\/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eML infrastructure\u003c\/td\u003e\n      \u003ctd\u003eCần (SentenceTransformer)\u003c\/td\u003e\n      \u003ctd\u003eKhông cần\u003c\/td\u003e\n      \u003ctd\u003eKhông cần\u003c\/td\u003e\n    \u003c\/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eContext usage\u003c\/td\u003e\n      \u003ctd\u003eThấp (3-5 tools)\u003c\/td\u003e\n      \u003ctd\u003eThấp (1-3 tools)\u003c\/td\u003e\n      \u003ctd\u003eRất cao (tất cả tools)\u003c\/td\u003e\n    \u003c\/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eCache preservation\u003c\/td\u003e\n      \u003ctd\u003eTrung bình\u003c\/td\u003e\n      \u003ctd\u003eTốt (defer_loading)\u003c\/td\u003e\n      \u003ctd\u003eTốt (cố định)\u003c\/td\u003e\n    \u003c\/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eDiscovery latency\u003c\/td\u003e\n      \u003ctd\u003e1 search call\u003c\/td\u003e\n      \u003ctd\u003e1-2 describe calls\u003c\/td\u003e\n      \u003ctd\u003e0 (sẵn có)\u003c\/td\u003e\n    \u003c\/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eScale đến 1000+ tools\u003c\/td\u003e\n      \u003ctd\u003eTốt\u003c\/td\u003e\n      \u003ctd\u003eTốt\u003c\/td\u003e\n      \u003ctd\u003eKhông thể\u003c\/td\u003e\n    \u003c\/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ePhù hợp nhất\u003c\/td\u003e\n      \u003ctd\u003eCatalog lớn, unknown tools\u003c\/td\u003e\n      \u003ctd\u003eCatalog có structure, cache quan trọng\u003c\/td\u003e\n      \u003ctd\u003eÍt tools (\u0026lt;20)\u003c\/td\u003e\n    \u003c\/tr\u003e\n  \u003c\/tbody\u003e\n\u003c\/table\u003e\n\n\u003ch2\u003eKhi nào dùng describe_tool pattern?\u003c\/h2\u003e\n\n\u003ch3\u003eIdeal khi:\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCost optimization quan trọng\u003c\/strong\u003e — prompt cache bị invalidate thường xuyên làm tăng chi phí\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTool catalog có naming convention rõ ràng\u003c\/strong\u003e — Claude có thể đoán tool cần dùng từ tên\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTools được thêm\/sửa thường xuyên\u003c\/strong\u003e — cần bảo toàn cache khi catalog thay đổi\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTeam không muốn maintain ML infrastructure\u003c\/strong\u003e cho embedding search\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eKết hợp hai patterns:\u003c\/h3\u003e\n\u003cp\u003eTrong production lớn, thường kết hợp cả hai:\u003c\/p\u003e\n\u003cul\u003e\n  \u003cli\u003eDùng \u003cstrong\u003eembedding search\u003c\/strong\u003e khi user query mơ hồ — tìm semantic matches\u003c\/li\u003e\n  \u003cli\u003eDùng \u003cstrong\u003edescribe_tool\u003c\/strong\u003e cho fine-grained discovery khi đã biết category\u003c\/li\u003e\n  \u003cli\u003eCả hai đều bảo vệ context window khỏi bị ngốn bởi tool definitions\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch2\u003eTổng kết\u003c\/h2\u003e\n\n\u003cp\u003edescribe_tool với defer_loading là pattern elegant cho tool discovery:\u003c\/p\u003e\n\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eZero ML infrastructure\u003c\/strong\u003e — không cần embedding model hay vector database\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCache preservation\u003c\/strong\u003e — defer_loading giữ tools khỏi cached prompt prefix, tránh invalidation\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTool names làm ngôn ngữ chung\u003c\/strong\u003e — đặt tên tool tốt giúp Claude tìm đúng ngay lần đầu\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eGraceful degradation\u003c\/strong\u003e — nếu tool không tồn tại, model biết ngay và suggest alternative\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003cp\u003eCả hai patterns — embedding search và describe_tool — đều là tools trong arsenal của bạn. Chọn theo infrastructure, team size, và requirements về cache optimization của project.\u003c\/p\u003e\n\n\u003cp\u003eBước tiếp theo: Quay lại \u003ca href=\"\/en\/collections\/nang-cao\"\u003eTool Use series\u003c\/a\u003e để xem full picture về cách build production-grade Claude agents với memory, compaction, PTC, và dynamic tool loading.\u003c\/p\u003e\n","brand":"Minh Tuấn","offers":[{"title":"Default Title","offer_id":47721769500884,"sku":null,"price":0.0,"currency_code":"VND","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0821\/0264\/9044\/files\/tool-search-cac-chi_n-l_c-tim-ki_m-tool-thay-th.jpg?v=1774506620","url":"https:\/\/claude.vn\/en\/products\/tool-search-cac-chi%e1%ba%bfn-l%c6%b0%e1%bb%a3c-tim-ki%e1%ba%bfm-tool-thay-th%e1%ba%bf","provider":"CLAUDE.VN","version":"1.0","type":"link"}