DAS Agent Chat
Send natural language questions to the Alibaba Cloud DAS (Database Autonomy Service) Agent and receive diagnostic results.
Pricing and Free Tier
This is a paid service with a free tier for trial usage.
- - Free Tier: When
ALIBABA_CLOUD_DAS_AGENT_ID is not set, the script omits the AgentId parameter and the API will use a default Agent ID which comes with a limited free quota for trial purposes. - Paid Usage: For production workloads or higher usage volumes, purchase a DAS Agent subscription and set your own
ALIBABA_CLOUD_DAS_AGENT_ID to bind your dedicated agent and quota.
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.
Environment Variables
The script requires Alibaba Cloud credentials resolvable via the default credential chain. The DAS Agent ID is optional — if not provided, the AgentId parameter will be omitted and the API will use a default Agent ID with limited free quota.
CODEBLOCK0
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 for setup instructions.
If you have purchased a DAS Agent subscription, create and manage your Agent ID at: 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:
~/.aliyun/config.json or INLINECODE5 - 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
~/.aliyun/config.json or INLINECODE7
The 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.
- - Errors mentioning INLINECODE8
The SDK attempted ECS metadata. This is expected on ECS, but usually a local-machine misconfiguration elsewhere.
For local development, if you are not using ECS RAM Role credentials, you can explicitly disable ECS metadata lookup:
CODEBLOCK1
This avoids confusing 100.100.100.200 metadata connection errors on non-ECS machines and makes missing-credential failures easier to read.
Invocation
Run from the scripts/ directory of this skill:
CODEBLOCK2
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.
Behavioral Notes
DAS Agent internally orchestrates multiple API calls and tool invocations to answer a single question. This has important implications:
- 1. 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.
- 2. Instance enrollment: The target database instance must be enrolled under the DAS Agent. If you see error code
-1810006, it means the agent is not associated with any instance — guide the user to the DAS console settings to associate instances.
- 3. Include instance ID in questions: DAS Agent resolves instances by ID (e.g.,
rm-bp1xxx, pc-2zeyyy). 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.
- 4. Parallel execution: When diagnosing multiple instances, launch multiple script processes in parallel — each invocation is independent and stateless (unless sharing a session ID).
- 5. 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 pass
--session <session_id> on 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.
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 every --pipe invocation:
SESSION: <uuid>
Extract it immediately after each call and carry it forward. In
--json mode it appears as
{"type": "session", "session_id": "..."} on the first line.
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.
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.
DAS Agent 聊天
向阿里云DAS(数据库自治服务)Agent发送自然语言问题,并接收诊断结果。
定价与免费套餐
这是一项付费服务,提供免费套餐供试用。
- - 免费套餐:当未设置 ALIBABACLOUDDASAGENTID 时,脚本会省略 AgentId 参数,API 将使用一个默认的 Agent ID,该 ID 附带有限的免费配额供试用。
- 付费使用:对于生产工作负载或更高的使用量,请购买 DAS Agent 订阅,并设置您自己的 ALIBABACLOUDDASAGENTID 来绑定您的专属 Agent 和配额。
建议:从免费套餐(默认 Agent ID)开始评估服务。一旦决定将其用于生产环境,请购买订阅并配置您自己的 Agent ID。
环境变量
该脚本需要通过默认凭证链解析的阿里云凭证。DAS Agent ID 是可选的——如果未提供,AgentId 参数将被省略,API 将使用具有有限免费配额的默认 Agent ID。
bash
可选:购买 DAS Agent 服务后设置您自己的 Agent ID
export ALIBABA
CLOUDDAS
AGENTID=
# 从 DAS 控制台获取(可选)
阿里云凭证 SDK 会自动从多个来源(环境变量、配置文件、ECS RAM 角色等)解析凭证。有关设置说明,请参考官方凭证配置文档。
如果您已购买 DAS Agent 订阅,请在以下地址创建和管理您的 Agent ID:https://das.console.aliyun.com/
故障排除
凭证解析失败
如果脚本因凭证相关错误退出,说明阿里云凭证 SDK 无法从其默认提供程序链中解析出可用的凭证。
支持的凭证来源:
- - 环境变量(参见官方文档)
- 本地配置文件:~/.aliyun/config.json 或 ~/.alibabacloud/credentials.ini
- 在阿里云 ECS 实例上运行时使用 ECS RAM 角色元数据
常见情况:
- - 凭证环境变量为空或缺失——请根据官方文档进行配置。
- 错误提及 ~/.aliyun/config.json 或 ~/.alibabacloud/credentials.ini
SDK 尝试使用本地配置文件凭证,但文件缺失或无效。如果您想使用本地配置文件,请创建/修复默认配置文件。
SDK 尝试了 ECS 元数据。这在 ECS 上是预期的,但在其他机器上通常是本地配置错误。
对于本地开发,如果您不使用 ECS RAM 角色凭证,可以显式禁用 ECS 元数据查找:
bash
export ALIBABACLOUDECSMETADATADISABLED=true
这可以避免在非 ECS 机器上出现令人困惑的 100.100.100.200 元数据连接错误,并使凭证缺失的失败信息更易于阅读。
调用
从该技能的 scripts/ 目录运行:
bash
cd scripts
管道模式(推荐用于 Agent)——干净的输出:进度信息输出到 stderr,答案清晰分隔在 stdout
uv run calldasagent.py --question <用户的问题> --pipe
默认模式(CLI 聊天界面)——实时流式输出,包含工具详情
uv run calldasagent.py --question <用户的问题>
JSON 模式——机器可读的 JSONL,每行一个 JSON 对象输出到 stdout
uv run calldasagent.py --question <用户的问题> --json
多轮对话——重用服务器分配的会话 ID 以保持上下文
uv run calldasagent.py --question 列出我的实例 --pipe # 第一行返回 session_id
提取 session_id(以 SESSION: 开头的行),然后重用它:
uv run calldasagent.py --question 检查第一个 --session <上面的sessionid> --pipe
作为 Agent 调用时,始终使用 --pipe。 它会将所有进度/工具调用噪音路由到 stderr,并仅将 DAS 答案写入 stdout,并用清晰的分隔符包裹——确保真正的响应不会被遗漏。
当需要以编程方式解析响应时,优先使用 --json。有关 JSON 事件类型和输出模式详情,请参见 references/api-reference.md。
行为说明
DAS Agent 内部会协调多个 API 调用和工具调用来回答单个问题。这有重要影响:
- 1. 长时间运行的任务:复杂的诊断(多实例检查、全面健康检查、批量 SQL 分析)可能需要几分钟到 30 分钟,因为 DAS Agent 会顺序调用监控 API、运行诊断并综合结果。在开始前告知用户,并提供定期进度更新。
- 2. 实例注册:目标数据库实例必须在 DAS Agent 下注册。如果您看到错误代码 -1810006,说明 Agent 未与任何实例关联——请引导用户到 DAS 控制台设置 关联实例。
- 3. 在问题中包含实例 ID:DAS Agent 通过 ID(例如 rm-bp1xxx、pc-2zeyyy)解析实例。请始终在问题中包含具体的实例 ID 以获得准确结果。如果用户未提供,请询问用户或先查询实例列表。
- 4. 并行执行:诊断多个实例时,并行启动多个脚本进程——每次调用都是独立且无状态的(除非共享会话 ID)。
- 5. 多轮对话——当问题相关时始终重用会话 ID:如果用户的问题是连续的或上下文相关的(后续诊断、深入分析、引用先前结果、比较发现),您必须在每次后续调用中传递 --session 。在对话中途启动新会话会迫使 DAS Agent 从头重新运行所有先前的上下文,浪费时间并产生质量较低的答案。
决策规则:默认重用会话 ID。仅当用户明确切换到完全不相关的主题或要求重新开始时,才启动新会话。
会话 ID 是服务器分配的,并在每次 --pipe 调用的第一行返回:
SESSION:
每次调用后立即提取并向前传递。在 --json 模式下,它会在第一行显示为 {type: session, session_id: ...}。
必须重用的示例:
- 列出我的实例 → 检查第一个的 CPU → 为什么这么高?
- 对 rm-bp1xxx 运行健康检查 → 显示最慢的查询
- 持有哪些锁? → 终止那个会话
DAS Agent 会在服务端保留完整的对话历史,因此后续问题可以简短自然——无需重复实例 ID 或先前的上下文。
输出
有关输出模式比较和格式详情,请参见 references/api-reference.md。
运行脚本后,将完整的 stdout 逐字传达给用户。 不要总结、转述或省略脚本 stdout 的任何部分。DAS Agent 的实际诊断答案嵌入在输出中——用户必须看到完整内容。
有关详细的 API 签名和 SSE 事件文档,请参见 references/api-reference.md。