95 lines
1.6 KiB
Markdown
95 lines
1.6 KiB
Markdown
# 快速开始 — 开发第一个套件
|
||
|
||
## 什么是套件
|
||
|
||
套件(Suite)是平台的可执行单元。一个套件包含:
|
||
- **workflow.yaml**:步骤定义(核心)
|
||
- **scripts/run.py**:执行脚本
|
||
|
||
## 第一步:创建套件目录
|
||
|
||
```bash
|
||
mkdir my-first-suite
|
||
cd my-first-suite
|
||
```
|
||
|
||
## 第二步:编写 workflow.yaml
|
||
|
||
```yaml
|
||
name: hello-world
|
||
description: 最小示例套件 — 输出用户输入的文本
|
||
version: 1.0.0
|
||
category: utility
|
||
|
||
params:
|
||
type: object
|
||
required:
|
||
- message
|
||
properties:
|
||
message:
|
||
type: string
|
||
description: 要输出的文本
|
||
|
||
steps:
|
||
- id: say-hello
|
||
name: 输出信息
|
||
script_id: run
|
||
params:
|
||
message: "${{inputs.message}}"
|
||
|
||
resolved_params:
|
||
- step_index: 0
|
||
step_name: 输出信息
|
||
params:
|
||
message: "Hello, AgentGIS!"
|
||
```
|
||
|
||
## 第三步:编写脚本
|
||
|
||
```bash
|
||
mkdir scripts
|
||
```
|
||
|
||
`scripts/run.py`:
|
||
|
||
```python
|
||
#!/usr/bin/env python3
|
||
import json, os
|
||
|
||
params_file = os.environ.get("PARAMS_FILE", "/tmp/params.json")
|
||
with open(params_file) as f:
|
||
params = json.load(f)
|
||
|
||
message = params.get("message", "Hello!")
|
||
result = {"output": message, "length": len(message)}
|
||
print(json.dumps(result))
|
||
```
|
||
|
||
## 第四步:测试
|
||
|
||
```bash
|
||
agc run <suite-id> --inputs '{"message": "测试"}'
|
||
```
|
||
|
||
或直接提交任务到 API:
|
||
|
||
```bash
|
||
curl -X POST https://suites.mercator.cn/api/v1/task \
|
||
-H "Authorization: Bearer mk_xxxx" \
|
||
-d '{"suite_id": "...", "inputs": {"message": "测试"}}'
|
||
```
|
||
|
||
## 第五步:发布
|
||
|
||
```bash
|
||
agc publish ./my-first-suite
|
||
```
|
||
|
||
发布后套件会在市场中展示,其他用户可以搜索和使用。
|
||
|
||
## 查看已发布的套件
|
||
|
||
```bash
|
||
agc suites list
|
||
```
|