Skip to content

Commit a6c0561

Browse files
Sodawyxclaude
andcommitted
docs(readme): add Prerequisites section and DingTalk contact
- README/docs index (en+zh): document the one-time AliyunAgentRunSuperAgentRole authorization link and the AliyunAgentRunFullAccess AccessKey requirement, plus a console pointer for users wanting more than the QuickStart flow - super-agent command pages (en+zh): add a heads-up linking to Prerequisites - README community section: surface the 函数计算 AgentRun 客户群 DingTalk group number 134570017218 - error handling: extend auth-error pattern matching (AccessDenied, NoPermission, AliyunAgentRunSuperAgentRole, EntityNotExist.Role) and emit a structured `hint` field pointing to the README Prerequisites anchor Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Sodawyx <sodawyx@126.com>
1 parent f05d4d2 commit a6c0561

10 files changed

Lines changed: 187 additions & 8 deletions

File tree

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ make build # standalone binary → dist/agentrun
7070
ar --version # or: agentrun --version
7171
```
7272

73+
## Prerequisites
74+
75+
Two one-time setup steps are required before `ar super-agent` will work:
76+
77+
### 1. Authorize the AliyunAgentRunSuperAgentRole
78+
79+
AgentRun uses a custom RAM service role — **`AliyunAgentRunSuperAgentRole`**
80+
to manage runtime resources on your behalf. Open the link below and confirm
81+
in the RAM console:
82+
83+
[**→ Create AliyunAgentRunSuperAgentRole**](https://ram.console.aliyun.com/authorize?hideTopbar=true&hideSidebar=true&request=%7B%22template%22%3A%22AgentRun%22%2C%22payloads%22%3A%5B%7B%22missionId%22%3A%22SuperAgentCustomRole%22%7D%5D%7D)
84+
85+
Without this role, `ar super-agent run` / `apply` will fail at creation time.
86+
87+
### 2. Grant `AliyunAgentRunFullAccess` to your AccessKey
88+
89+
The AccessKey you save with `ar config set access_key_id ...` must belong to a
90+
RAM user (or role) that has the **`AliyunAgentRunFullAccess`** system policy
91+
attached. If you see exit code `3` or `AccessDenied`, this is almost always
92+
the cause.
93+
94+
### Want more than QuickStart? Use the console
95+
96+
This CLI covers the QuickStart conversational flow end-to-end. For the full
97+
AgentRun experience, head to the Function Compute AgentRun console:
98+
<https://functionai.console.aliyun.com/cn-hangzhou/agent/>
99+
73100
## Quickstart
74101

75102
### Step 1 — Configure credentials
@@ -168,6 +195,14 @@ Multi-document YAMLs (`---` separated) let you deploy many agents in one call.
168195
Each page walks through installation, authentication, global options, output formats,
169196
exit codes and every command option with runnable examples.
170197
198+
## Community
199+
200+
Questions, bug reports and feature requests are welcome on
201+
[GitHub Issues](https://github.com/Serverless-Devs/agentrun-cli/issues).
202+
203+
For real-time discussion, join the **函数计算 AgentRun 客户群** on DingTalk —
204+
group number **`134570017218`**.
205+
171206
## License
172207
173208
Apache-2.0 — see [LICENSE](./LICENSE).

README_zh.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ make build # 本地打独立二进制 → dist/agentrun
6969
ar --version # 或者 agentrun --version
7070
```
7171

72+
## 前置准备
73+
74+
使用 `ar super-agent` 相关命令前,需要完成两项**一次性**配置:
75+
76+
### 1. 授权 AliyunAgentRunSuperAgentRole
77+
78+
AgentRun 通过自定义 RAM 服务角色 **`AliyunAgentRunSuperAgentRole`** 代你管理
79+
运行时资源。点击下方链接,在 RAM 控制台完成授权:
80+
81+
[**→ 创建 AliyunAgentRunSuperAgentRole**](https://ram.console.aliyun.com/authorize?hideTopbar=true&hideSidebar=true&request=%7B%22template%22%3A%22AgentRun%22%2C%22payloads%22%3A%5B%7B%22missionId%22%3A%22SuperAgentCustomRole%22%7D%5D%7D)
82+
83+
未授权时 `ar super-agent run` / `apply` 在创建阶段会直接失败。
84+
85+
### 2. 给 AccessKey 授予 `AliyunAgentRunFullAccess`
86+
87+
`ar config set access_key_id ...` 配置的 AccessKey 所属 RAM 用户/角色需要挂载
88+
系统策略 **`AliyunAgentRunFullAccess`**。命令报 `AccessDenied` 或退出码 `3`
89+
时,多半就是少了这个权限。
90+
91+
### 想体验更完整的能力?请前往控制台
92+
93+
本 CLI 完整覆盖 QuickStart 快速对话流程。如需体验 AgentRun 的完整能力,请前往
94+
函数计算 AgentRun 控制台:<https://functionai.console.aliyun.com/cn-hangzhou/agent/>
95+
7296
## 快速开始
7397

7498
### 第 1 步 —— 配置凭证
@@ -166,6 +190,13 @@ ar sa invoke my-helper -m "帮我规划今天的事情" --text-only
166190
167191
每份文档涵盖安装、认证、全局选项、输出格式、退出码以及每个命令的全部选项,附可运行示例。
168192
193+
## 社区
194+
195+
问题反馈、Bug 报告与功能建议,请走
196+
[GitHub Issues](https://github.com/Serverless-Devs/agentrun-cli/issues)。
197+
198+
实时交流可加入**函数计算 AgentRun 客户群**,钉钉群号 **`134570017218`**
199+
169200
## License
170201
171202
Apache-2.0 — 详见 [LICENSE](./LICENSE)。

docs/en/index.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ option tables and examples.
1010
## Contents
1111

1212
- [Installation](#installation)
13+
- [Prerequisites](#prerequisites)
1314
- [Authentication](#authentication)
1415
- [Global options](#global-options)
1516
- [Output formats](#output-formats)
@@ -69,6 +70,34 @@ make build # local binary → dist/agentrun
6970
After installation, both `ar` and `agentrun` are available as entry points and behave
7071
identically. `ar` is shorter; the examples in this manual use it.
7172

73+
## Prerequisites
74+
75+
Two one-time setup steps are required before `ar super-agent` will work.
76+
77+
### 1. Authorize the AliyunAgentRunSuperAgentRole
78+
79+
AgentRun uses a custom RAM service role — **`AliyunAgentRunSuperAgentRole`**
80+
to manage runtime resources on your behalf. Open the link below and confirm
81+
in the RAM console:
82+
83+
[**→ Create AliyunAgentRunSuperAgentRole**](https://ram.console.aliyun.com/authorize?hideTopbar=true&hideSidebar=true&request=%7B%22template%22%3A%22AgentRun%22%2C%22payloads%22%3A%5B%7B%22missionId%22%3A%22SuperAgentCustomRole%22%7D%5D%7D)
84+
85+
Without this role, `ar super-agent run` / `apply` will fail at creation time.
86+
87+
### 2. Grant `AliyunAgentRunFullAccess` to your AccessKey
88+
89+
The AccessKey configured below (see [Authentication](#authentication)) must
90+
belong to a RAM user (or role) that has the **`AliyunAgentRunFullAccess`**
91+
system policy attached. If a command exits with code `3` or returns
92+
`AccessDenied`, this is almost always the cause.
93+
94+
### Want more than QuickStart? Use the console
95+
96+
This CLI covers the QuickStart conversational flow end-to-end. For the full
97+
AgentRun experience (visual designer, observability, knowledge bases, agent
98+
marketplace, …), head to the Function Compute AgentRun console:
99+
<https://functionai.console.aliyun.com/cn-hangzhou/agent/>
100+
72101
## Authentication
73102

74103
The CLI resolves credentials from three sources, in this order:

docs/en/super-agent.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ You declare intent; the platform hosts the runtime.
99
Also available as the alias `ar sa`. The conversation sub-group can be reached
1010
as `ar sa conv` or `ar sa conversation`.
1111

12+
> **Heads up:** before running any command on this page, complete the two
13+
> one-time setup steps in [Prerequisites](./index.md#prerequisites) — the
14+
> `AliyunAgentRunSuperAgentRole` authorization and the
15+
> `AliyunAgentRunFullAccess` policy on your AccessKey. Missing either one
16+
> surfaces as exit code `3` (`AccessDenied`).
17+
1218
## Commands
1319

1420
Quickstart & chat:

docs/zh/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
## 目录
1010

1111
- [安装](#安装)
12+
- [前置准备](#前置准备)
1213
- [认证](#认证)
1314
- [全局选项](#全局选项)
1415
- [输出格式](#输出格式)
@@ -68,6 +69,31 @@ make build # 本地打独立二进制 → dist/agentrun
6869
安装完成后 `ar``agentrun` 都是入口点,行为完全一致。`ar` 更短,文档里的示例
6970
默认用 `ar`
7071

72+
## 前置准备
73+
74+
使用 `ar super-agent` 相关命令前,需要完成两项**一次性**配置。
75+
76+
### 1. 授权 AliyunAgentRunSuperAgentRole
77+
78+
AgentRun 通过自定义 RAM 服务角色 **`AliyunAgentRunSuperAgentRole`** 代你管理
79+
运行时资源。点击下方链接,在 RAM 控制台完成授权:
80+
81+
[**→ 创建 AliyunAgentRunSuperAgentRole**](https://ram.console.aliyun.com/authorize?hideTopbar=true&hideSidebar=true&request=%7B%22template%22%3A%22AgentRun%22%2C%22payloads%22%3A%5B%7B%22missionId%22%3A%22SuperAgentCustomRole%22%7D%5D%7D)
82+
83+
未授权时 `ar super-agent run` / `apply` 在创建阶段会直接失败。
84+
85+
### 2. 给 AccessKey 授予 `AliyunAgentRunFullAccess`
86+
87+
下文 [认证](#认证) 章节中配置的 AccessKey,所属 RAM 用户/角色需要挂载系统策略
88+
**`AliyunAgentRunFullAccess`**。命令报 `AccessDenied` 或退出码 `3` 时,多半就是
89+
少了这一项权限。
90+
91+
### 想体验更完整的能力?请前往控制台
92+
93+
本 CLI 完整覆盖 QuickStart 快速对话流程。如需可视化编排、Observability、
94+
知识库、Agent 市场等更完整的能力,请前往函数计算 AgentRun 控制台:
95+
<https://functionai.console.aliyun.com/cn-hangzhou/agent/>
96+
7197
## 认证
7298

7399
CLI 按以下顺序解析凭证(上面优先):

docs/zh/super-agent.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
该命令组还提供短别名 `ar sa`。会话子组既可用 `ar sa conv` 也可用
1010
`ar sa conversation`,行为一致。
1111

12+
> **使用前提:** 执行本页任何命令前,请先完成
13+
> [前置准备](./index.md#前置准备) 中的两项一次性配置 ——
14+
> 授权 `AliyunAgentRunSuperAgentRole` 角色,并给 AccessKey 挂载
15+
> `AliyunAgentRunFullAccess` 系统策略。任一项缺失都会以退出码 `3`
16+
> `AccessDenied`)失败。
17+
1218
## 子命令
1319

1420
一键拉起与对话:

src/agentrun_cli/_utils/error.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727
EXIT_AUTH_ERROR = 3
2828
EXIT_SERVER_ERROR = 4
2929

30+
PREREQUISITES_HINT = (
31+
"Complete the one-time setup at "
32+
"https://github.com/Serverless-Devs/agentrun-cli#prerequisites — "
33+
"authorize the AliyunAgentRunSuperAgentRole and grant "
34+
"AliyunAgentRunFullAccess to your AccessKey."
35+
)
36+
37+
_AUTH_PATTERNS = (
38+
"Forbidden",
39+
"InvalidAccessKey",
40+
"SignatureDoesNotMatch",
41+
"AccessDenied",
42+
"NoPermission",
43+
"AliyunAgentRunSuperAgentRole",
44+
"EntityNotExist.Role",
45+
)
46+
3047

3148
def handle_errors(func: Callable) -> Callable:
3249
"""Decorator that catches common SDK / HTTP errors and exits cleanly."""
@@ -52,8 +69,8 @@ def wrapper(*args, **kwargs):
5269
if "ResourceAlreadyExistError" in exc_type or "AlreadyExist" in exc_type:
5370
echo_error("ResourceAlreadyExists", msg)
5471
sys.exit(EXIT_BAD_INPUT)
55-
if "Forbidden" in msg or "InvalidAccessKey" in msg or "SignatureDoesNotMatch" in msg:
56-
echo_error("AuthenticationFailed", msg)
72+
if any(pattern in msg for pattern in _AUTH_PATTERNS):
73+
echo_error("AuthenticationFailed", msg, hint=PREREQUISITES_HINT)
5774
sys.exit(EXIT_AUTH_ERROR)
5875

5976
# Generic fallback

src/agentrun_cli/_utils/output.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ def format_output(ctx: click.Context, data: Any, quiet_field: Optional[str] = No
9292
echo_json(data)
9393

9494

95-
def echo_error(error_type: str, message: str) -> None:
96-
"""Write a structured JSON error to stderr."""
97-
click.echo(
98-
json.dumps({"error": error_type, "message": message}, ensure_ascii=False),
99-
err=True,
100-
)
95+
def echo_error(error_type: str, message: str, hint: Optional[str] = None) -> None:
96+
"""Write a structured JSON error to stderr.
97+
98+
When *hint* is provided it is included as a ``hint`` field in the JSON
99+
payload — used to surface Prerequisites links on permission failures.
100+
"""
101+
payload: dict = {"error": error_type, "message": message}
102+
if hint:
103+
payload["hint"] = hint
104+
click.echo(json.dumps(payload, ensure_ascii=False), err=True)

tests/unit/test_error.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for agentrun_cli._utils.error — the handle_errors decorator."""
22

3+
import json
34
import sys
45
from unittest.mock import patch
56

@@ -11,6 +12,7 @@
1112
EXIT_BAD_INPUT,
1213
EXIT_NOT_FOUND,
1314
EXIT_SERVER_ERROR,
15+
PREREQUISITES_HINT,
1416
handle_errors,
1517
)
1618

@@ -82,6 +84,23 @@ def test_signature_mismatch_auth_error(self):
8284
_make_raising_func(exc)()
8385
assert exc_info.value.code == EXIT_AUTH_ERROR
8486

87+
@pytest.mark.parametrize(
88+
"message",
89+
[
90+
"AccessDenied: user has no permission",
91+
"NoPermission to call CreateSuperAgent",
92+
"Role AliyunAgentRunSuperAgentRole not authorized",
93+
"EntityNotExist.Role: role not found",
94+
],
95+
)
96+
def test_prerequisite_patterns_emit_hint(self, message, capsys):
97+
with pytest.raises(SystemExit) as exc_info:
98+
_make_raising_func(Exception(message))()
99+
assert exc_info.value.code == EXIT_AUTH_ERROR
100+
payload = json.loads(capsys.readouterr().err)
101+
assert payload["error"] == "AuthenticationFailed"
102+
assert payload["hint"] == PREREQUISITES_HINT
103+
85104
def test_generic_exception(self):
86105
exc = Exception("something unexpected")
87106
with pytest.raises(SystemExit) as exc_info:

tests/unit/test_output.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,9 @@ def test_writes_to_stderr(self, capsys):
155155
parsed = json.loads(err)
156156
assert parsed["error"] == "TestError"
157157
assert parsed["message"] == "something went wrong"
158+
assert "hint" not in parsed
159+
160+
def test_includes_hint_when_provided(self, capsys):
161+
echo_error("AuthError", "denied", hint="see prerequisites")
162+
parsed = json.loads(capsys.readouterr().err)
163+
assert parsed["hint"] == "see prerequisites"

0 commit comments

Comments
 (0)