Install
openclaw skills install @sdk-team/alibabacloud-bailian-rag-knowledgebaseAlibaba Cloud Bailian Knowledge Base Retrieval Tool. Use HTTPS API to query and retrieve knowledge base content. Use when: User needs to query knowledge base, retrieve document content, or answer questions based on knowledge base. Prerequisites: (1) Configure DashScope API Key (2) Activate Bailian Knowledge Base service.
openclaw skills install @sdk-team/alibabacloud-bailian-rag-knowledgebaseThis Skill provides query and retrieval capabilities for Alibaba Cloud Bailian Knowledge Base via HTTPS API.
Scripts automatically handle key retrieval via api_key.py. The Agent does not need to and should not manually extract, set, or pass API Key values.
api_key.py to automatically obtain keys from config files/environment variables. The Agent only needs to run the script command.api_key = "sk-...", export DASHSCOPE_API_KEY="sk-...", and assigning keys in shell scripts.sk-.cat, jq, python -c, or other commands to read and output API Key values.grep -rn "sk-" <output_directory>/ to check all output files; if any strings starting with sk- are found (excluding sk-xxx placeholders), delete the affected files and regenerate.API Keys are managed by the unified scripts/api_key.py module, with the following retrieval priority:
~/.aliyun/config.json current profile's dashscope.api_keyDASHSCOPE_API_KEYgenerate_api_key())# All scripts use this unified approach
from api_key import get_api_key
api_key = get_api_key() # Returns str, raises ValueError if not found
Manual environment variable configuration:
export DASHSCOPE_API_KEY=sk-xxx
| Item | Description |
|---|---|
| Key Format | sk-xxx (standard DashScope API Key) |
| Not Supported | sk-sp-xxx (Coding Plan Key, does not support knowledge base services) |
| Get Key | https://bailian.console.aliyun.com/cn-beijing/?tab=app#/api-key |
The scripts/api_key.py module creates and deletes API Keys via aliyun modelstudio commands. Complete the following setup before use:
1. Update Plugins
# Update plugins to latest version
aliyun plugin update
2. Install ModelStudio Plugin (if not already installed)
aliyun plugin install --names aliyun-cli-modelstudio --enable-pre
CLI Commands Used:
| Command | Purpose | Called From |
|---|---|---|
aliyun modelstudio list-workspaces | Get Bailian Workspace ID | api_key.py: _get_workspace_id() |
aliyun modelstudio create-api-key | Create DashScope API Key | api_key.py: generate_api_key() |
aliyun modelstudio delete-api-key | Delete cloud API Key | api_key.py: _delete_cloud_api_key() |
Before using this skill, you must first activate the knowledge base service in the Alibaba Cloud Bailian console!
Upon loading this skill, generate a random session ID (32-char lowercase hex string) and export it as SKILL_SESSION_ID. This value must remain constant for the entire skill session.
Every aliyun CLI command and HTTPS API call must include a User-Agent identifier for traceability.
AlibabaCloud-Agent-Skills/alibabacloud-bailian-rag-knowledgebase/{session-id}
{session-id} = value of SKILL_SESSION_ID environment variable (32-char lowercase hex string)os.environ.get("SKILL_SESSION_ID", ""); if empty, generate one with secrets.token_hex(16)Every aliyun modelstudio business command MUST carry --user-agent on the command line:
aliyun modelstudio list-workspaces --region cn-beijing \
--user-agent "AlibabaCloud-Agent-Skills/alibabacloud-bailian-rag-knowledgebase/{session-id}"
Prohibited: Do NOT set User-Agent via global configuration commands. Only per-command
--user-agentis allowed.
All HTTPS API requests set the User-Agent HTTP header:
"User-Agent": f"AlibabaCloud-Agent-Skills/alibabacloud-bailian-rag-knowledgebase/{session_id}"
| Location | Mechanism |
|---|---|
scripts/list_indices.py | HTTPS User-Agent header via _get_user_agent() |
scripts/retrieve.py | HTTPS User-Agent header via _get_user_agent() |
scripts/api_key.py → _get_workspace_id() | aliyun modelstudio list-workspaces --user-agent ... |
scripts/api_key.py → generate_api_key() | aliyun modelstudio create-api-key --user-agent ... |
scripts/api_key.py → _delete_cloud_api_key() | aliyun modelstudio delete-api-key --user-agent ... |
All scripts are located in the scripts/ directory:
| Script | Purpose | Parameters |
|---|---|---|
api_key.py | API Key management (get, create, delete) | - |
list_indices.py | Query knowledge base list | [page_number] [page_size] |
retrieve.py | Retrieve from specified knowledge base | index_id query [top_n] |
Run scripts/list_indices.py to get all available knowledge bases:
python3 scripts/list_indices.py
Return format:
[
{
"id": "qf91w6402d",
"name": "Product Documentation",
"description": "Contains product user manuals, API documentation, etc."
},
{
"id": "ip93d2pyvz",
"name": "Customer Service Q&A",
"description": "FAQ, customer service scripts"
}
]
Pagination: page_number starts from 1 (default), page_size defaults to 10. If current page is not fully retrieved, continue to retrieve next page:
python3 scripts/list_indices.py 2 10
Based on the user's question and knowledge base descriptions, select 1-3 most relevant knowledge bases for retrieval.
Selection Strategy:
For each selected knowledge base, run scripts/retrieve.py index_id query [top_n]:
python3 scripts/retrieve.py lj3hgbq60t "java" 5
Parameters:
index_id (required): Knowledge base IDquery (required): Search query texttop_n (optional): Number of top results to return, default 5, max 20The retrieve API uses the following configuration:
dense_similarity_top_k: 100sparse_similarity_top_k: 100enable_reranking: truererank: qwen3-rerank-hybrid with similar modeReturn format, content inside each chunk represents chunk content, doc_name represents source document, score represents match score, title represents chunk section title:
{
"indexId": "lj3hgbq60t",
"chunks": [
{
"content": "Document chunk content...",
"score": 0.6040189862251282,
"doc_name": "example-doc.pdf",
"title": "Section Title"
}
]
}
Based on retrieval results:
{"code": "InvalidApiKey", "message": "Invalid API-KEY"}
API Key is incorrect or not configured. Guide user to check their API Key configuration.
{"code": "Forbidden", "message": "Service not activated"}
User has not activated the Bailian Knowledge Base service. Guide user to activate it.
User: "What authentication methods does our product support?"
Flow:
API Key Auto-Retrieval Flow:
~/.aliyun/config.json current profile's dashscope.api_key → Return if foundDASHSCOPE_API_KEY → Return if foundgenerate_api_key() and save to config