fix(#8): Hello-World 示例 — 统一为 script_id + $params.xxx 格式

This commit is contained in:
2026-07-13 10:34:55 +00:00
parent 2734367820
commit 6b058cf7ac
+39 -35
View File
@@ -1,61 +1,65 @@
# Hello World 套件 # Hello, World! 套件示例
## 完整代码 一个最简单的套件,演示 workflow.yaml 和脚本结构。
最小的可工作套件,接收一个文本参数并输出。 ## 文件结构
### workflow.yaml ```
hello-world/
├── workflow.yaml
└── scripts/
└── run.py
```
## workflow.yaml
```yaml ```yaml
name: hello-world name: Hello World
description: 输出用户输入的文本 description: 首个 AgentGIS 套件,接收一条消息并在容器中打印
version: 1.0.0 version: 1.0.0
category: utility author: SuiteForge
tags: [示例, 入门]
params: params:
type: object
required:
- message
properties:
message: message:
type: string type: string
description: 要输出的文本 required: true
desc: 要打印的消息
base_image: gis-base:latest
steps: steps:
- id: say-hello - id: hello
name: 输出信 name: 打印消
script: run script_id: run
params: params:
message: $params.message message: $params.message
``` ```
### scripts/run.py ## scripts/run.py
```python ```python
#!/usr/bin/env python3 #!/usr/bin/env python3
import json, os import sys, json
params_file = os.environ.get("PARAMS_FILE", "/tmp/params.json") def run(params):
with open(params_file) as f: message = params.get("message", "Hello, AgentGIS!")
params = json.load(f) print(f"📢 {message}")
return {
"status": "completed",
"message": message,
}
message = params.get("message", "Hello!") if __name__ == "__main__":
params = json.loads(sys.argv[1]) if len(sys.argv) > 1 else {}
result = { result = run(params)
"output": message, print(json.dumps(result, ensure_ascii=False))
"length": len(message)
}
print(json.dumps(result))
``` ```
## 测试 ## 执行
```bash ```bash
# 打包 agc run /tmp/hello-output \
tar czf hello-world.tgz workflow.yaml scripts/ --suite-id <your-suite-id> \
--input message="你好,AgentGIS!"
# 通过 API 发布后执行
agc run /tmp/output --suite-id <suite-id> --input message="Hello, AgentGIS!"
``` ```
完整代码参考:`SuiteHub/hello-world-suite`