alibabacloud-das-agent
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDAS Agent Chat
DAS Agent Chat
Send natural language questions to the Alibaba Cloud DAS (Database Autonomy Service) Agent and receive diagnostic results.
向阿里云DAS(数据库自治服务)Agent发送自然语言问题,即可获得诊断结果。
Pricing and Free Tier
定价与免费额度
This is a paid service with a free tier for trial usage.
- Free Tier: When is not set, the script omits the
ALIBABA_CLOUD_DAS_AGENT_IDparameter and the API will use a default Agent ID which comes with a limited free quota for trial purposes.AgentId - Paid Usage: For production workloads or higher usage volumes, purchase a DAS Agent subscription and set your own to bind your dedicated agent and quota.
ALIBABA_CLOUD_DAS_AGENT_ID
Recommendation: Start with the free tier (default Agent ID) to evaluate the service. Once you decide to adopt it for production, purchase a subscription and configure your own Agent ID.
这是一项付费服务,提供免费额度供试用。
- 免费额度:当未设置时,脚本会省略
ALIBABA_CLOUD_DAS_AGENT_ID参数,API将使用默认Agent ID,该ID附带有限的免费试用额度。AgentId - 付费使用:对于生产工作负载或更高使用量,请购买DAS Agent订阅,设置您自己的来绑定专属的Agent和额度。
ALIBABA_CLOUD_DAS_AGENT_ID
建议:先使用免费额度(默认Agent ID)评估服务。一旦您决定在生产环境中使用,请购买订阅并配置您自己的Agent ID。
Environment Variables
环境变量
The script requires Alibaba Cloud credentials resolvable via the default credential chain. The DAS Agent ID is optional — if not provided, the parameter will be omitted and the API will use a default Agent ID with limited free quota.
AgentIdbash
undefined脚本需要可通过默认凭证链解析的阿里云凭证。DAS Agent ID是可选的——如果未提供,参数将被省略,API会使用带有有限免费额度的默认Agent ID。
AgentIdbash
undefinedOptional: Set your own Agent ID after purchasing DAS Agent service
可选:购买DAS Agent服务后设置您自己的Agent ID
export ALIBABA_CLOUD_DAS_AGENT_ID="<agent_id>" # Obtain from DAS console (optional)
The Alibaba Cloud Credentials SDK automatically resolves credentials from multiple sources (environment variables, configuration files, ECS RAM roles, etc.). Refer to the [official credential configuration documentation](https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-python-access-credentials) for setup instructions.
If you have purchased a DAS Agent subscription, create and manage your Agent ID at: https://das.console.aliyun.com/export ALIBABA_CLOUD_DAS_AGENT_ID="<agent_id>" # 从DAS控制台获取(可选)
阿里云凭证SDK会自动从多个来源解析凭证(环境变量、配置文件、ECS RAM角色等)。请参考[官方凭证配置文档](https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-python-access-credentials)了解设置说明。
如果您已经购买了DAS Agent订阅,请在以下地址创建和管理您的Agent ID:https://das.console.aliyun.com/Troubleshooting
故障排查
Credential Resolution Failed
凭证解析失败
If the script exits with a credential-related error, it means the Alibaba Cloud Credentials SDK could not resolve a usable credential from its default provider chain.
Supported credential sources:
- Environment variables (see official documentation)
- Local profile files: or
~/.aliyun/config.json~/.alibabacloud/credentials.ini - ECS RAM Role metadata when running on an Alibaba Cloud ECS instance
Common cases:
- Credential environment variables are empty or missing — configure them according to the official documentation.
- Errors mentioning or
~/.aliyun/config.jsonThe SDK attempted local profile-based credentials, but the files were missing or invalid. Create/fix the default profile if you want to use local profiles.~/.alibabacloud/credentials.ini - Errors mentioning The SDK attempted ECS metadata. This is expected on ECS, but usually a local-machine misconfiguration elsewhere.
100.100.100.200
For local development, if you are not using ECS RAM Role credentials, you can explicitly disable ECS metadata lookup:
bash
export ALIBABA_CLOUD_ECS_METADATA_DISABLED=trueThis avoids confusing metadata connection errors on non-ECS machines and makes missing-credential failures easier to read.
100.100.100.200如果脚本因凭证相关错误退出,意味着阿里云凭证SDK无法从其默认提供链中解析出可用凭证。
支持的凭证来源:
- 环境变量(参见官方文档)
- 本地配置文件:或
~/.aliyun/config.json~/.alibabacloud/credentials.ini - 运行在阿里云ECS实例上时的ECS RAM角色元数据
常见场景:
- 凭证环境变量为空或缺失——请根据官方文档进行配置。
- 提及或
~/.aliyun/config.json的错误 SDK尝试使用本地配置文件凭证,但文件缺失或无效。如果您想使用本地配置文件,请创建/修复默认配置。~/.alibabacloud/credentials.ini - 提及的错误 SDK尝试获取ECS元数据。在ECS上这是正常的,但在其他环境中通常是本地机器配置错误。
100.100.100.200
对于本地开发,如果您不使用ECS RAM角色凭证,可以显式禁用ECS元数据查找:
bash
export ALIBABA_CLOUD_ECS_METADATA_DISABLED=true这可以避免在非ECS机器上出现令人困惑的元数据连接错误,让缺失凭证的失败原因更易读。
100.100.100.200Invocation
调用方式
Run from the directory of this skill:
scripts/bash
cd scripts在此技能的目录下运行:
scripts/bash
cd scriptsPipe mode (RECOMMENDED for agents) — clean output: progress to stderr, answer clearly delimited on stdout
管道模式(Agent推荐使用)—— 干净输出:进度输出到stderr,回答在stdout中清晰分隔
uv run call_das_agent.py --question "<user's question>" --pipe
uv run call_das_agent.py --question "<user's question>" --pipe
Default mode (CLI chat UI) — real-time streaming with tool details
默认模式(CLI聊天UI)—— 带工具详情的实时流式输出
uv run call_das_agent.py --question "<user's question>"
uv run call_das_agent.py --question "<user's question>"
JSON mode — machine-readable JSONL, one JSON object per line on stdout
JSON模式—— 机器可读的JSONL,stdout每行一个JSON对象
uv run call_das_agent.py --question "<user's question>" --json
uv run call_das_agent.py --question "<user's question>" --json
Multi-turn conversation — reuse the server-assigned session ID to maintain context
多轮会话—— 复用服务器分配的会话ID以保留上下文
uv run call_das_agent.py --question "List my instances" --pipe # Returns session_id on first line
uv run call_das_agent.py --question "List my instances" --pipe # 第一行返回session_id
Extract session_id (line starting with "SESSION:"), then reuse it:
提取session_id(以"SESSION:"开头的行),然后复用它:
uv run call_das_agent.py --question "Check the first one" --session "<session_id_from_above>" --pipe
**Always use `--pipe` when invoking as an agent.** It routes all progress/tool-call noise to stderr and writes only the DAS answer to stdout, wrapped in clear delimiters — making the real response impossible to miss.
Prefer `--json` when you need to parse the response programmatically. For JSON event types and output mode details, see [references/api-reference.md](references/api-reference.md).uv run call_das_agent.py --question "Check the first one" --session "<session_id_from_above>" --pipe
**作为Agent调用时请始终使用`--pipe`参数。** 它会将所有进度/工具调用的杂项信息输出到stderr,仅将DAS的回答输出到stdout,并用清晰的分隔符包裹——确保不会错过真实响应。
如果需要以编程方式解析响应,请优先使用`--json`参数。如需了解JSON事件类型和输出模式详情,请参考[references/api-reference.md](references/api-reference.md)。Behavioral Notes
行为说明
DAS Agent internally orchestrates multiple API calls and tool invocations to answer a single question. This has important implications:
-
Long-running tasks: Complex diagnostics (multi-instance inspection, comprehensive health checks, batch SQL analysis) can take several minutes up to 30 minutes, because DAS Agent sequentially calls monitoring APIs, runs diagnostics, and synthesizes results. Inform the user before starting and provide periodic progress updates.
-
Instance enrollment: The target database instance must be enrolled under the DAS Agent. If you see error code, it means the agent is not associated with any instance — guide the user to the DAS console settings to associate instances.
-1810006 -
Include instance ID in questions: DAS Agent resolves instances by ID (e.g.,,
rm-bp1xxx). Always include the specific instance ID in the question for accurate results. If the user hasn't provided one, ask them or first query the instance list.pc-2zeyyy -
Parallel execution: When diagnosing multiple instances, launch multiple script processes in parallel — each invocation is independent and stateless (unless sharing a session ID).
-
Multi-turn conversations — always reuse the session ID when questions are related: If the user's questions are sequential or contextually connected (follow-up diagnostics, drill-down analysis, referencing a previous result, comparing findings), you must passon every subsequent call. Starting a new session mid-conversation forces the DAS Agent to re-run all prior context from scratch, wastes time, and produces lower-quality answers.
--session <session_id>Decision rule: Default to reusing the session ID. Only start a new session when the user explicitly switches to a completely unrelated topic or asks to "start over".The session ID is server-assigned and returned as the very first line of everyinvocation:--pipeSESSION: <uuid>Extract it immediately after each call and carry it forward. Inmode it appears as--jsonon the first line.{"type": "session", "session_id": "..."}Examples of when reuse is mandatory:- "List my instances" → "Check CPU on the first one" → "Why is it high?"
- "Run a health check on rm-bp1xxx" → "Show me the top slow queries"
- "What locks are held?" → "Kill that session"
The DAS Agent retains the full conversation history server-side, so follow-up questions can be short and natural — no need to repeat instance IDs or prior context.
DAS Agent内部会编排多个API调用和工具调用,来回答单个问题。这会带来以下重要影响:
-
长时运行任务:复杂诊断(多实例巡检、全面健康检查、批量SQL分析)可能需要数分钟到30分钟,因为DAS Agent会依次调用监控API、运行诊断并合成结果。请在开始前告知用户,并定期提供进度更新。
-
实例接入:目标数据库实例必须接入DAS Agent。如果您看到错误码,意味着Agent没有关联任何实例——请引导用户前往DAS控制台设置关联实例。
-1810006 -
问题中包含实例ID:DAS Agent通过ID解析实例(例如、
rm-bp1xxx)。请始终在问题中包含具体的实例ID以获得准确结果。如果用户没有提供,可以询问用户或者先查询实例列表。pc-2zeyyy -
并行执行:诊断多个实例时,可以并行启动多个脚本进程——每次调用都是独立无状态的(除非共享会话ID)。
-
多轮会话——问题相关时始终复用会话ID:如果用户的问题是连续的或上下文相关的(跟进诊断、下钻分析、引用之前的结果、对比发现),您必须在后续每次调用中传递参数。在会话中途启动新会话会强制DAS Agent重新运行所有之前的上下文步骤,浪费时间,并且生成的回答质量更低。
--session <session_id>决策规则:默认复用会话ID。仅当用户明确切换到完全不相关的主题或者要求“重新开始”时,才启动新会话。会话ID是服务器分配的,在每次调用的第一行返回:--pipeSESSION: <uuid>每次调用后请立即提取它并继续传递。在模式下,它会在第一行以--json的形式出现。{"type": "session", "session_id": "..."}必须复用会话ID的示例:- "列出我的实例" → "检查第一个实例的CPU" → "为什么CPU这么高?"
- "对rm-bp1xxx运行健康检查" → "给我看排名靠前的慢查询"
- "持有哪些锁?" → "杀掉那个会话"
DAS Agent会在服务端保留完整的会话历史,因此跟进问题可以简短自然——无需重复实例ID或之前的上下文。
Output
输出
For output mode comparison and format details, see references/api-reference.md.
After running the script, relay the complete stdout to the user verbatim. Do not summarize, paraphrase, or omit any part of the script's stdout. The DAS Agent's actual diagnostic answer is embedded in the output — the user must see it in full.
For detailed API signature and SSE event documentation, see references/api-reference.md.
如需了解输出模式对比和格式详情,请参考references/api-reference.md。
运行脚本后,请将完整的stdout原封不动地转发给用户。 不要总结、改写或省略脚本stdout的任何部分。DAS Agent的实际诊断回答嵌入在输出中——用户必须看到完整内容。
如需了解详细的API签名和SSE事件文档,请参考references/api-reference.md。