{"product_id":"tạo-custom-skills-cho-claude-hướng-dẫn-từ-a-dến-z","title":"Tạo Custom Skills cho Claude — Hướng dẫn từ A đến Z","description":"\n\u003cp\u003eCustom Skills cho phép bạn mở rộng khả năng của Claude với domain knowledge và tool access riêng của tổ chức bạn. Thay vì viết prompt dài và phức tạp mỗi lần, bạn đóng gói logic đó thành một Skill có thể tái sử dụng — giống như tạo một \"chuyên gia ảo\" trong lĩnh vực cụ thể.\u003c\/p\u003e\n\n\u003ch2\u003eKiến trúc Custom Skill\u003c\/h2\u003e\n\n\u003cp\u003eMột Custom Skill gồm ba thành phần chính:\u003c\/p\u003e\n\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSKILL.md\u003c\/strong\u003e — Mô tả skill: mục đích, capabilities, và hướng dẫn sử dụng\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCONNECTORS.md\u003c\/strong\u003e — Định nghĩa API connections và external tools\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eImplementation Code\u003c\/strong\u003e — Logic xử lý thực tế (Python\/Node.js\/etc.)\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch2\u003eBước 1: Thiết kế SKILL.md\u003c\/h2\u003e\n\n\u003cp\u003eSKILL.md là \"contract\" mô tả skill của bạn. Claude đọc file này để hiểu mình đang làm gì:\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003e# SKILL: Vietnamese Market Analyzer\n\n## Purpose\nAnalyze Vietnamese stock market data, provide investment insights,\nand generate reports in Vietnamese for retail investors.\n\n## Capabilities\n- Fetch real-time stock prices from HOSE, HNX, UPCOM\n- Calculate technical indicators (RSI, MACD, Bollinger Bands)\n- Analyze fundamental ratios (P\/E, P\/B, ROE, debt ratios)\n- Generate buy\/hold\/sell recommendations\n- Create Excel reports and charts\n- Translate financial jargon to plain Vietnamese\n\n## Invocation\nUsers can invoke this skill by asking about:\n- \"Phân tích cổ phiếu [TICKER]\"\n- \"Khuyến nghị đầu tư tháng này\"\n- \"So sánh [TICKER1] và [TICKER2]\"\n- \"Tạo báo cáo portfolio\"\n\n## Constraints\n- Only analyze publicly traded Vietnamese companies\n- Always include risk disclaimers\n- Data freshness: max 15 minutes delay\n- Cannot execute actual trades\n\n## Output Formats\n- Quick analysis: 3-5 bullet points\n- Full report: structured markdown with tables\n- Excel file: when user requests downloadable report\n\n## Example Interaction\nUser: \"Phân tích nhanh VNM\"\nSkill: Fetches VNM data, calculates key metrics, provides\n       structured analysis with buy\/hold\/sell recommendation\n\n## Version\n1.0.0\n\n## Author\nYour Name \/ Organization\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eBước 2: Định nghĩa CONNECTORS.md\u003c\/h2\u003e\n\n\u003cp\u003eCONNECTORS.md mô tả các external services skill của bạn sử dụng:\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003e# CONNECTORS: Vietnamese Market Analyzer\n\n## Connector: HOSE Market Data API\n- Type: REST API\n- Base URL: https:\/\/api.example-vn-market.com\/v1\n- Auth: Bearer token (env: VN_MARKET_API_KEY)\n- Endpoints used:\n  - GET \/stocks\/{ticker}\/price — current price + OHLCV\n  - GET \/stocks\/{ticker}\/history?days=365 — historical data\n  - GET \/stocks\/{ticker}\/fundamentals — P\/E, P\/B, EPS, etc.\n  - GET \/market\/indices — VN-Index, HNX-Index, UPCOM-Index\n\n## Connector: Financial Calendar\n- Type: REST API\n- Base URL: https:\/\/api.example-calendar.com\n- Auth: API Key header (env: CALENDAR_API_KEY)\n- Endpoints used:\n  - GET \/events?market=VN\u0026amp;days=30 — upcoming earnings, dividends\n  - GET \/dividends\/{ticker} — dividend history\n\n## Connector: News Feed\n- Type: RSS \/ REST\n- Source: CafeF, VnExpress Finance, VietStock\n- Rate limit: 100 req\/hour\n\n## Environment Variables Required\n- VN_MARKET_API_KEY: Market data API authentication\n- CALENDAR_API_KEY: Financial calendar API\n- ANTHROPIC_API_KEY: For Claude API calls\n- REDIS_URL: For caching market data (optional)\n\n## Data Caching Strategy\n- Stock prices: 15-minute cache (Redis)\n- Fundamentals: 24-hour cache\n- Historical data: 1-hour cache\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eBước 3: Implementation — Skill Core\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003eimport anthropic\nimport os\nimport json\nfrom dataclasses import dataclass\nfrom typing import Optional\n\nclass VietnameseMarketSkill:\n    \"\"\"Main skill class — handles all market analysis\"\"\"\n\n    SKILL_DESCRIPTION = \"\"\"\nYou are a Vietnamese stock market analyst. You have access to real-time\nmarket data tools and can analyze stocks listed on HOSE, HNX, and UPCOM.\nAlways respond in Vietnamese unless asked otherwise.\nProvide clear, actionable analysis with appropriate risk disclaimers.\n\"\"\"\n\n    def __init__(self):\n        self.client = anthropic.Anthropic()\n        self.tools = self._define_tools()\n        self.data_fetcher = MarketDataFetcher()\n\n    def _define_tools(self) -\u0026gt; list:\n        return [\n            {\n                \"name\": \"get_stock_data\",\n                \"description\": \"Lấy dữ liệu cổ phiếu: giá hiện tại, OHLCV, và thông tin cơ bản. Dùng khi phân tích cổ phiếu cụ thể.\",\n                \"input_schema\": {\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"ticker\": {\n                            \"type\": \"string\",\n                            \"description\": \"Mã cổ phiếu, ví dụ: VNM, VIC, HPG\"\n                        },\n                        \"include_history\": {\n                            \"type\": \"boolean\",\n                            \"default\": False,\n                            \"description\": \"Có lấy dữ liệu lịch sử 1 năm không\"\n                        }\n                    },\n                    \"required\": [\"ticker\"]\n                }\n            },\n            {\n                \"name\": \"calculate_technical_indicators\",\n                \"description\": \"Tính toán các chỉ số kỹ thuật: RSI, MACD, Bollinger Bands. Cần có historical data trước.\",\n                \"input_schema\": {\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"ticker\": {\"type\": \"string\"},\n                        \"indicators\": {\n                            \"type\": \"array\",\n                            \"items\": {\"type\": \"string\", \"enum\": [\"RSI\", \"MACD\", \"BB\", \"MA20\", \"MA50\"]},\n                            \"description\": \"Danh sách indicators cần tính\"\n                        }\n                    },\n                    \"required\": [\"ticker\", \"indicators\"]\n                }\n            },\n            {\n                \"name\": \"get_market_overview\",\n                \"description\": \"Lấy tổng quan thị trường: VN-Index, HNX-Index, top gainers\/losers, market breadth.\",\n                \"input_schema\": {\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"include_sectors\": {\n                            \"type\": \"boolean\",\n                            \"default\": False,\n                            \"description\": \"Có bao gồm phân tích theo ngành không\"\n                        }\n                    }\n                }\n            },\n            {\n                \"name\": \"generate_excel_report\",\n                \"description\": \"Tạo file Excel báo cáo phân tích. Dùng khi user yêu cầu báo cáo tải về.\",\n                \"input_schema\": {\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"tickers\": {\n                            \"type\": \"array\",\n                            \"items\": {\"type\": \"string\"},\n                            \"description\": \"Danh sách mã cổ phiếu cần báo cáo\"\n                        },\n                        \"report_type\": {\n                            \"type\": \"string\",\n                            \"enum\": [\"quick_scan\", \"full_analysis\", \"comparison\"],\n                            \"default\": \"quick_scan\"\n                        }\n                    },\n                    \"required\": [\"tickers\"]\n                }\n            }\n        ]\n\n    def process(self, user_message: str, conversation_history: list = None) -\u0026gt; dict:\n        \"\"\"Main entry point cho skill\"\"\"\n        messages = conversation_history or []\n        messages.append({\"role\": \"user\", \"content\": user_message})\n\n        response = self.client.messages.create(\n            model=\"claude-opus-4-5\",\n            max_tokens=4000,\n            system=self.SKILL_DESCRIPTION,\n            tools=self.tools,\n            messages=messages\n        )\n\n        # Xử lý tool calls\n        while response.stop_reason == \"tool_use\":\n            tool_results = []\n\n            for block in response.content:\n                if block.type == \"tool_use\":\n                    result = self._execute_tool(block.name, block.input)\n                    tool_results.append({\n                        \"type\": \"tool_result\",\n                        \"tool_use_id\": block.id,\n                        \"content\": json.dumps(result, ensure_ascii=False)\n                    })\n\n            messages.append({\"role\": \"assistant\", \"content\": response.content})\n            messages.append({\"role\": \"user\", \"content\": tool_results})\n\n            response = self.client.messages.create(\n                model=\"claude-opus-4-5\",\n                max_tokens=4000,\n                system=self.SKILL_DESCRIPTION,\n                tools=self.tools,\n                messages=messages\n            )\n\n        final_text = next((b.text for b in response.content if b.type == \"text\"), \"\")\n        messages.append({\"role\": \"assistant\", \"content\": final_text})\n\n        return {\n            \"response\": final_text,\n            \"conversation\": messages\n        }\n\n    def _execute_tool(self, tool_name: str, tool_input: dict) -\u0026gt; dict:\n        \"\"\"Route tool calls đến implementations\"\"\"\n        tool_map = {\n            \"get_stock_data\": self.data_fetcher.get_stock_data,\n            \"calculate_technical_indicators\": self.data_fetcher.calculate_technicals,\n            \"get_market_overview\": self.data_fetcher.get_market_overview,\n            \"generate_excel_report\": self.data_fetcher.generate_report\n        }\n\n        handler = tool_map.get(tool_name)\n        if handler:\n            return handler(**tool_input)\n        return {\"error\": f\"Unknown tool: {tool_name}\"}\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eBước 4: Data Fetcher Implementation\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003eclass MarketDataFetcher:\n    \"\"\"Handles all data fetching and calculations\"\"\"\n\n    def get_stock_data(self, ticker: str, include_history: bool = False) -\u0026gt; dict:\n        \"\"\"Fetch stock data — mock implementation, replace with real API\"\"\"\n        # Trong production: call VN market API\n        return {\n            \"ticker\": ticker,\n            \"price\": 89500,  # VND\n            \"change\": 1500,\n            \"change_pct\": 1.71,\n            \"volume\": 2_450_000,\n            \"pe_ratio\": 18.5,\n            \"pb_ratio\": 3.2,\n            \"eps\": 4838,\n            \"market_cap\": \"176,400 tỷ VND\",\n            \"52w_high\": 98000,\n            \"52w_low\": 72000,\n            \"sector\": \"Hàng tiêu dùng thiết yếu\",\n            \"exchange\": \"HOSE\"\n        }\n\n    def calculate_technicals(self, ticker: str, indicators: list) -\u0026gt; dict:\n        \"\"\"Calculate technical indicators\"\"\"\n        # Trong production: fetch prices và compute\n        results = {}\n        if \"RSI\" in indicators:\n            results[\"RSI\"] = {\n                \"value\": 58.4,\n                \"signal\": \"Neutral\",  # Oversold \u0026lt; 30, Overbought \u0026gt; 70\n                \"interpretation\": \"Cổ phiếu đang ở vùng trung tính\"\n            }\n        if \"MACD\" in indicators:\n            results[\"MACD\"] = {\n                \"macd_line\": 245,\n                \"signal_line\": 198,\n                \"histogram\": 47,\n                \"signal\": \"Bullish\",  # MACD \u0026gt; Signal = Bullish\n                \"interpretation\": \"MACD cắt lên đường Signal — xu hướng tăng ngắn hạn\"\n            }\n        if \"BB\" in indicators:\n            results[\"Bollinger_Bands\"] = {\n                \"upper\": 94500,\n                \"middle\": 87800,\n                \"lower\": 81100,\n                \"position\": \"Middle\",\n                \"interpretation\": \"Giá đang giao dịch gần band giữa, biến động bình thường\"\n            }\n        return results\n\n    def get_market_overview(self, include_sectors: bool = False) -\u0026gt; dict:\n        return {\n            \"vn_index\": {\"value\": 1285.42, \"change\": +12.35, \"change_pct\": +0.97},\n            \"hnx_index\": {\"value\": 228.15, \"change\": -1.82, \"change_pct\": -0.79},\n            \"upcom_index\": {\"value\": 92.34, \"change\": +0.45, \"change_pct\": +0.49},\n            \"market_breadth\": {\"advancing\": 312, \"declining\": 198, \"unchanged\": 45},\n            \"top_gainers\": [{\"ticker\": \"VIC\", \"change_pct\": 4.5}, {\"ticker\": \"VHM\", \"change_pct\": 3.2}],\n            \"top_losers\": [{\"ticker\": \"MSN\", \"change_pct\": -2.8}, {\"ticker\": \"MWG\", \"change_pct\": -2.1}]\n        }\n\n    def generate_report(self, tickers: list, report_type: str = \"quick_scan\") -\u0026gt; dict:\n        return {\n            \"status\": \"generated\",\n            \"file_path\": f\"\/tmp\/report_{'-'.join(tickers)}.xlsx\",\n            \"download_url\": f\"https:\/\/example.com\/reports\/...\"\n        }\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eBước 5: Testing Skill\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003edef test_skill():\n    skill = VietnameseMarketSkill()\n\n    test_cases = [\n        \"Phân tích nhanh cổ phiếu VNM cho tôi\",\n        \"Hôm nay thị trường thế nào?\",\n        \"So sánh VIC và VHM, nên mua cái nào?\",\n        \"Tạo báo cáo Excel cho VNM, HPG, và VIC\"\n    ]\n\n    for i, question in enumerate(test_cases, 1):\n        print(f\"\n=== Test {i}: {question} ===\")\n        result = skill.process(question)\n        print(f\"Response ({len(result['response'])} chars):\")\n        print(result['response'][:300] + \"...\" if len(result['response']) \u0026gt; 300 else result['response'])\n\n    print(\"\nAll tests passed!\")\n\ntest_skill()\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eBước 6: Đóng gói và Publish\u003c\/h2\u003e\n\n\u003cpre\u003e\u003ccode\u003e\"\"\"\nCấu trúc thư mục để publish skill:\n\nmy-vn-market-skill\/\n├── SKILL.md              # Skill description\n├── CONNECTORS.md         # API connections\n├── requirements.txt      # Dependencies\n├── skill.py              # Main implementation\n├── data_fetcher.py       # Data layer\n├── tests\/\n│   ├── test_skill.py\n│   └── test_data.py\n└── README.md             # Setup instructions\n\"\"\"\n\n# requirements.txt\nREQUIREMENTS = \"\"\"\nanthropic\u0026gt;=0.40.0\npandas\u0026gt;=2.0.0\nnumpy\u0026gt;=1.24.0\nopenpyxl\u0026gt;=3.1.0\nredis\u0026gt;=5.0.0\nhttpx\u0026gt;=0.27.0\n\"\"\"\n\n# Packaging cho internal use\ndef create_skill_package(output_dir: str):\n    \"\"\"Tạo distribution package\"\"\"\n    import os\n    os.makedirs(output_dir, exist_ok=True)\n\n    # Write all files\n    files_to_create = {\n        \"requirements.txt\": REQUIREMENTS,\n        \"SKILL.md\": \"# SKILL: ...\",  # content from above\n        \"CONNECTORS.md\": \"# CONNECTORS: ...\",  # content from above\n    }\n\n    for filename, content in files_to_create.items():\n        with open(os.path.join(output_dir, filename), 'w') as f:\n            f.write(content)\n\n    print(f\"Skill package created at: {output_dir}\")\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eBest Practices khi tạo Custom Skills\u003c\/h2\u003e\n\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSKILL.md phải cực kỳ cụ thể\u003c\/strong\u003e — càng cụ thể, Claude càng invoke đúng lúc. Tránh mơ hồ về khi nào dùng tool nào.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTool descriptions là critical\u003c\/strong\u003e — Claude dùng descriptions để quyết định gọi tool nào. Đầu tư thời gian viết thật rõ ràng.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eError handling phải robust\u003c\/strong\u003e — Skill chạy autonomous, cần xử lý mọi failure gracefully.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCache aggressive\u003c\/strong\u003e — API calls tốn tiền và thời gian. Cache mọi thứ có thể cache được.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTest với diverse inputs\u003c\/strong\u003e — Users sẽ hỏi theo cách bạn không ngờ tới. Test edge cases nhiều.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eVersion và changelog\u003c\/strong\u003e — Khi update skill, bump version và document changes trong SKILL.md.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch2\u003eTổng kết\u003c\/h2\u003e\n\n\u003cp\u003eCustom Skills biến Claude từ general assistant thành domain expert trong tổ chức của bạn. Với SKILL.md + CONNECTORS.md + implementation code rõ ràng, bạn có thể xây dựng skills cho bất kỳ use case nào — từ phân tích thị trường tài chính đến quản lý inventory hay customer support.\u003c\/p\u003e\n\n\u003cp\u003eĐọc thêm: \u003ca href=\"\/en\/collections\/nang-cao\"\u003eOrchestrator-Workers Pattern\u003c\/a\u003e để kết hợp nhiều skills trong một multi-agent system phức tạp.\u003c\/p\u003e\n","brand":"Minh Tuấn","offers":[{"title":"Default Title","offer_id":47721898606804,"sku":null,"price":0.0,"currency_code":"VND","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0821\/0264\/9044\/files\/t_o-custom-skills-cho-claude-h_ng-d_n-t_-a-d_n-z.jpg?v=1774513978","url":"https:\/\/claude.vn\/en\/products\/t%e1%ba%a1o-custom-skills-cho-claude-h%c6%b0%e1%bb%9bng-d%e1%ba%abn-t%e1%bb%ab-a-d%e1%ba%bfn-z","provider":"CLAUDE.VN","version":"1.0","type":"link"}