iii-architecture-patterns
它能做什么
展示如何把 iii 的构建模块组合成更大的后端设计,例如分步工作流、响应式后端和事件驱动系统。适合设计比单个函数更大系统的开发者。
适用场景
- ✓当你需要一个带有重试机制、并能跟踪每个步骤的多步任务时。
- ✓当你希望视图和缓存随着数据变化保持同步时。
- ✓当多个 AI 智能体需要相互交接工作时。
技能链接
https://github.com/iii-hq/iii/blob/main/skills/iii-architecture-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我为订单处理设计一个持久工作流,包含重试机制,并为失败的任务设置死信队列。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能会根据需求选择合适的模式,例如用于重试的持久工作流,或用于响应另一个函数结果的观察者。然后用函数、触发器、队列和状态来搭建设计。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Architecture Patterns
Use this skill when the task is larger than one function or trigger. Pick the pattern from the
requirement, then implement it with Function, Trigger, Worker, observers, state, queues,
streams, and pub/sub.
Pattern Map
| Requirement | Pattern | iii shape |
|---|---|---|
| Sequential work with retries, DLQ, step tracking | Durable workflow | Functions chained through named queues, progress in state |
| Keep views, metrics, cache, or clients in sync | Reactive backend | State triggers plus stream/pubsub side effects |
| React to another function's calls, results, or failures without changing it | Observer side effect | iii.observe({ function_id, on, filters }, target) (iii-observe) |
| Specialized AI agents hand work to each other | Agentic backend | One function per agent, queue handoffs, shared state |
| Commands publish events and projections update independently | Event-driven CQRS | Command functions, event log in state, subscribe triggers |
| Pure, traceable composition | Effect pipeline | Small functions composed synchronously with trigger() |
| Webhook/cron automation chains | Low-code automation | Trigger, transform, action nodes chained by enqueue |
Durable Workflow
Use named queues when steps need different retry, FIFO, or concurrency policy.
TypeScript
import { registerWorker, TriggerAction } from "iii-sdk";
const iii = registerWorker("ws://localhost:49134", { workerName: "order-workflow" });
async function track(orderId: string, step: string, status: string) {
await iii.trigger({
function_id: "state::update",
payload: { scope: "orders", key: orderId, ops: [{ type: "merge", path: ["steps"], value: { [step]: status } }] },
});
}
iii.registerFunction("orders::validate", async (order) => {
await track(order.id, "validate", "done");
return iii.trigger({
function_id: "orders::charge",
payload: order,
action: TriggerAction.Enqueue({ queue: "order-payment" }),
});
});
iii.registerFunction("orders::charge", async (order) => {
await track(order.id, "payment", "done");
return iii.trigger({
function_id: "orders::ship",
payload: order,
action: TriggerAction.Enqueue({ queue: "order-ship" }),
});
});
Python
from iii import register_worker
iii = register_worker("ws://localhost:49134")
def track(order_id, step, status):
iii.trigger({
"function_id": "state::update",
"payload": {
"scope": "orders",
"key": order_id,
"ops": [{"type": "merge", "path": ["steps"], "value": {step: status}}],
},
})
def validate(order):
track(order["id"], "validate", "done")
return iii.trigger({
"function_id": "orders::charge",
"payload": order,
"action": {"type": "enqueue", "queue": "order-payment"},
})
iii.register_function("orders::validate", validate)
Rust
use iii_sdk::TriggerAction;
use iii_sdk::protocol::TriggerRequest;
use serde_json::json;
async fn enqueue_charge(iii: iii_sdk::IIIClient, order: serde_json::Value) -> Result<serde_json::Value, iii_sdk::Error> {
iii.trigger(TriggerRequest {
function_id: "state::update".into(),
payload: json!({
"scope": "orders",
"key": order["id"],
"ops": [{ "type": "merge", "path": ["steps"], "value": { "validate": "done" } }]
}),
action: None,
timeout_ms: None,
}).await?;
iii.trigger(TriggerRequest {
function_id: "orders::charge".into(),
payload: order,
action: Some(TriggerAction::Enqueue { queue: "order-payment".into() }),
timeout_ms: None,
}).await
}
Reactive Backend
Use state triggers when the requirement says "after create/update, do this", "avoid polling", or "push live updates".
iii.registerFunction("todos::on-change", async (event) => {
await iii.trigger({
function_id: "stream::send",
payload: { stream_name: "todos-live", group_id: "default", data: event.new_value },
action: TriggerAction.Void(),
});
});
iii.registerTrigger({
type: "state",
function_id: "todos::on-change",
config: { scope: "todos" },
});
Observer Side Effects
Use an observer when "after X runs (or fails), also do Y" and X should not know about Y: audit logs, alerts, projections, cache invalidation. Every function is observable since 0.25, and an observer failure never affects the observed cal
常见问题
这里的死信队列是什么?
它是一个存放在重试后仍然失败的任务的队列,方便之后进行检查。
它会修改现有函数吗?
有些模式,例如观察者,不需要修改另一个函数,就能对它的调用做出响应。
涵盖哪些模式?
持久工作流、响应式后端、观察者、智能体流水线、事件驱动设计、效果流水线和自动化链。
详情
作者的原始描述
Use when composing iii primitives into backend architectures: durable workflows, reactive backends, observer side effects, agentic pipelines, event-driven CQRS, effect pipelines, and trigger-transform-action automation.
repo: iii-hq/iii
热度
- GitHub 星标
- 19k
- 排名
- #10491
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
iii-sandbox
19k帮你的智能体在临时隔离的虚拟机中安全运行不可信或由 AI 生成的代码,完成后将其丢弃。
configuration
19k让你的智能体设置一个共享的命名配置值注册表,并按模式进行检查,使工作进程可以读取并响应变化。
iii
19k教你的智能体了解 iii 工作进程如何运作,使其可以先检查已有的功能,再构建新的工作进程来添加能力。
iii-observability
19k帮你的智能体使用 OpenTelemetry 为 iii 引擎添加追踪、结构化日志、指标和告警,让你看清系统正在发生什么。