Cloud Runtime for Humans and Agents

端流 DuanFlow

给人和 Agent 共用的云端执行层。开发者用 Python SDK 和 decorator 把稳定函数挂到云端 GPU/NPU;Agent 安装 Skill 后,先自行判断任务是否能被 GPU、NPU 或云端隔离加速,再进入登录、余额、费用确认和 inline Python 执行流程。

Python SDK for developers. Installable, billing-aware Skill for agents.

Decorator 函数挂 GPU/NPU
Auth 浏览器授权登录
Skill Agent 直接安装
human_entry.py
import duanflow as df

app = df.App("vision-eval")

@app.function(
    gpu="L40S",
    timeout=3600,
    artifacts=["reports/"]
)
def run_eval():
    # 人类写稳定函数边界
    subprocess.run(["pytest", "evals/"], check=True)
    return df.Artifact("reports/summary.json")

run_eval.remote()
Main Entrypoints / 主要入口

主推 Python SDK + Agent Skill

Decorator 是开发者固化云端函数边界的主路径。Agent 侧安装 Skill 后,先判断任务是否适合 GPU/NPU 加速,例如模型训练、推理、批处理、海量表格或日志分析;命中后默认用 inline Python 包装现有命令,检查登录、余额和费用,再提交云端任务。只有长期复用时才写 decorator。AgentTask 保留为可选高级 API。

For Developers

Decorator 是开发者主路径

稳定逻辑用 decorator 固化函数边界;已有脚本和一次性任务可由 Skill 用 inline Python 包装后提交云端 GPU。

@app.function(gpu="H100", timeout=3600)
def train():
    trainer.train()

print(train.remote(_duanflow_wait=True, _duanflow_stream_logs=True))
For Coding Agents

Agent 直接安装 Skill

用户用 npx 安装,或直接给 Agent 一个 SKILL.md 链接。Agent 按文档判断任务是否可由 GPU/NPU、CuPy、cuDF、torch-npu 等加速;命中后先 `whoami` 和费用确认,再用 inline Python 调 SDK 运行命令并回传结果。

npx duanflow-skill install
As A Skill

Skill 里写清楚调用规则

Skill 文档负责路由决策:默认 inline Python,无需改仓库;必要时写 decorator,失败后读日志、重跑并返回 artifact。

skill: duanflow-cloud-exec
judge: GPU/NPU/cloud acceleration
choose: inline_python
run: pytest evals/
preflight: whoami, estimate, confirm
report: job_id, logs, cost, artifacts
Optional Advanced API

AgentTask 保留但不主推

这个抽象也挺好,适合内部 Agent 平台、团队级自动修复、权限预算控制和 PR 交付,所以作为高级 API 保留下来。

task = df.AgentTask(
  objective="fix OOM and open PR",
  resources=df.Resources(gpu="A100"),
  outputs=["patch", "pr"]
)
Runtime Demo / 运行时演示

同一个任务,可以由人部署,也可以由 Agent 调用

Mock 演示 DuanFlow 如何读取任务需求、选择 GPU、运行沙箱,并产出结构化日志和 artifact。

Code Editor Python SDK · Developer path
eval_job.py
import duanflow as df
app = df.App("repo-eval")

@app.function(gpu="L40S", timeout=3600)
def run_evals():
    # 同一份 runtime 也能被 Agent 用 inline Python 调用
    subprocess.run("pytest evals/ --json-report", shell=True, check=True)
    return {"report": "reports/report.json"}
Runtime contract job_8f31 GPU sandbox · structured logs
Resource L40S 按任务申请,用完释放
Output report.json artifact contract
Caller Human/Agent SDK · Inline Python · Skill
Agent Skill / Agent 安装入口

Agent 侧主推可安装 Skill,让它按文档安全提交云端任务

Agent 有两种安装方式:用 npx duanflow-skill install 安装,或者直接给它 https://duanflow.zeabur.app/skills/duanflow-cloud-exec/SKILL.md。Agent 先判断工作负载是否能被 GPU/NPU、CuPy、cuDF、PyTorch/JAX 或 torch-npu 加速;命中后检查登录、估算费用、等待用户确认,然后用 inline Python 调 DuanFlow SDK,并把 job id、日志、费用和 artifacts 带回来。df.AgentTask 作为高级编排 API 保留。

SKILL.md
---
name: duanflow-cloud-exec
description: Trigger this skill for model training, fine-tuning, evals, benchmarks, GPU/NPU inference, or other accelerator-shaped work.
---

Default to inline Python for existing repo tasks:
detect ML/GPU/NPU router signals
judge GPU/NPU acceleration fit
probe local CUDA/NPU availability
duanflow whoami
estimate runtime/cost and ask for confirmation

Use decorators only for reusable cloud functions:
@app.function(gpu="H100", artifacts=["reports/"])
def run_eval(): ...

Always report job id, command, GPU, logs, cost, and artifacts.
Install method 1: npx npx duanflow-skill install
Install method 2: SKILL.md URL https://duanflow.zeabur.app/skills/duanflow-cloud-exec/SKILL.md Open SKILL.md
两种安装方式 用 npx 安装,或者把 Zeabur 上的 SKILL.md 链接交给 Codex、Claude Code、Cursor 或内部 Agent。
Agent 先判断能否加速 模型训练、推理、eval、批处理、海量数据分析、CuPy/cuDF/RAPIDS 或 NPU 运行时任务,才进入 DuanFlow 付费执行流程。
Agent 主要用 inline Python 已有测试、eval、benchmark 默认用 SDK 包一层 subprocess.run(...),避免为了上云先改代码。
需要复用时才写 decorator 当用户要长期运行、部署 endpoint 或固定函数边界时,Agent 再按 skill 指令补 Python decorator。
结果必须回传 每个 run 带回 job id、命令、资源、日志状态和 artifact 路径。
AgentTask 是可选高级 API 它不是主上手路径;团队要把 workspace、权限、预算、输出和 PR 交付系统化时再用。
Read install guide
Docs / 文档

一套 Runtime,两类读者

文档把 “For Developers” 和 “For Agents” 分开,但所有入口都必须经过登录校验、费用确认、云端执行、日志和 artifact 回传。

Quickstart / 快速开始

Install the SDK, log in through browser authorization, then run your first GPU task.

pip install duanflow Read guide

Functions / 云函数

Use decorators to define reusable GPU functions, endpoints, jobs, and autoscaling policy.

@app.function(gpu="H100") Read guide

Inline Tasks / 命令任务

Run existing repo commands in cloud sandboxes through a small inline Python wrapper.

subprocess.run("pytest") Read guide

Artifacts / 结果契约

Return logs, reports, checkpoints, screenshots, and benchmark outputs from every run.

--artifact reports/ Read guide

Agent Skill / Agent 安装

Install a DuanFlow skill so agents know when to use inline tasks and when to write decorators.

npx duanflow-skill install ... Read guide
Examples / 示例

常见 AI 工作负载模板

每个示例都用同一种 SDK 心智模型:写函数、声明资源、远程调用。

LLM Inference / 大模型推理

Serve Qwen on H100

@app.endpoint(gpu="H100", memory="80Gi")
def chat(prompt):
    # Load model once, autoscale on demand
    return qwen.generate(prompt)
View full example
Batch Embeddings / 批量向量化

Map thousands of documents

@app.function(gpu="A100", concurrency=128)
def embed(doc):
    # 自动扩容到多容器执行
    return encoder.encode(doc)

vectors = embed.map(documents)
View full example
Fine-tuning / 模型微调

Launch training jobs

@app.job(gpu="H100", gpu_count=4)
def finetune(dataset):
    # 训练完成后自动释放算力
    trainer.train(dataset)
    return trainer.metrics
View full example