diff --git a/plugins/example/intents/demo.json b/plugins/example/intents/demo.json index 370d3852..eccf1cc7 100644 --- a/plugins/example/intents/demo.json +++ b/plugins/example/intents/demo.json @@ -6,5 +6,20 @@ "description": "示例意图:命中『示例/演示』关键词(slots 声明即 HITL 该问什么;本示例无必填槽位)", "matcher": { "includes_any": ["示例", "演示"] }, "slots": [] + }, + { + "id": "demo.brief", + "domain": "demo", + "version": 1, + "description": "写一份简报。必填槽位 topic,没写就问「主题是什么?」。", + "matcher": { "includes_any": ["简报"] }, + "slots": [ + { + "key": "topic", + "required": true, + "pattern": "主题[::]\\s*(\\S+)", + "question": "主题是什么?" + } + ] } ] diff --git a/plugins/example/plugin.json b/plugins/example/plugin.json index 6b040d15..df19a2f1 100644 --- a/plugins/example/plugin.json +++ b/plugins/example/plugin.json @@ -32,6 +32,10 @@ ], "commands": [ "demo" + ], + "workflows": [ + "demo-brief", + "demo-script" ] } } diff --git a/plugins/example/workflows/demo-brief.json b/plugins/example/workflows/demo-brief.json new file mode 100644 index 00000000..acdb61d1 --- /dev/null +++ b/plugins/example/workflows/demo-brief.json @@ -0,0 +1,57 @@ +{ + "id": "demo.brief", + "title": "示例简报", + "description": "命中 demo.brief 后:选篇幅、起草、落成工件、发一张结果卡,再请用户确认。", + "intentId": "demo.brief", + "steps": [ + { + "id": "length", + "title": "篇幅", + "kind": "hitl", + "hitl": { + "question": "要多长?", + "kind": "choice", + "allowFreeInput": false, + "choices": [ + {"id": "short", "label": "短", "description": "一段", "impact": "只写一段"}, + {"id": "long", "label": "长", "description": "几段", "impact": "会写得更长"} + ] + } + }, + { + "id": "draft", + "title": "起草", + "kind": "prompt", + "agent": "research", + "prompt": "写一份关于「{{slots.topic}}」的简报,篇幅:{{steps.length.output}}。", + "critic": {"criteria": "必须提到主题,并且是一段能读完的简报", "maxRetries": 1} + }, + { + "id": "save", + "title": "成稿", + "kind": "artifact", + "artifact": "demo-brief.md", + "prompt": "{{steps.draft.output}}" + }, + { + "id": "note", + "title": "收件", + "kind": "card", + "card": {"kind": "result", "title": "简报好了", "tone": "ok"} + }, + { + "id": "confirm", + "title": "确认", + "kind": "hitl", + "hitl": { + "question": "这份简报可以用吗?", + "kind": "confirm", + "allowFreeInput": false, + "choices": [ + {"id": "yes", "label": "可以用", "description": "结束", "impact": "不会再改"}, + {"id": "no", "label": "先不用", "description": "结束", "impact": "不会再改"} + ] + } + } + ] +} diff --git a/plugins/example/workflows/demo-script.json b/plugins/example/workflows/demo-script.json new file mode 100644 index 00000000..1dba4a73 --- /dev/null +++ b/plugins/example/workflows/demo-script.json @@ -0,0 +1,13 @@ +{ + "id": "demo.script", + "title": "示例脚本", + "description": "插件自带脚本。需要打开 runtime.workflowScripts。不绑定意图,用 run_workflow 启动。", + "steps": [ + { + "id": "run", + "title": "跑脚本", + "kind": "script", + "script": "workflows/scripts/demo.py" + } + ] +} diff --git a/plugins/example/workflows/scripts/demo.py b/plugins/example/workflows/scripts/demo.py new file mode 100644 index 00000000..ce23392f --- /dev/null +++ b/plugins/example/workflows/scripts/demo.py @@ -0,0 +1,6 @@ +import agentwf as wf + +now = wf.tool("time_now", {}) +answer = wf.ask("要记下来吗?", [{"id": "yes", "label": "记下", "impact": "会写入一份备忘"}]) +wf.artifact("demo-script.md", "时间 " + now + "\n选择 " + answer) +wf.step("run", "跑脚本", "done")