Appearance
Appearance
跑 orchestrator + 隔离 subagent 的最小系统:任务契约、key 级合并(冲突显式记录)、委派循环被 depth limit 拦截、超时输出丢弃与跨 agent 有序 trace。
你可以在免安装的浏览器 WebAssembly 环境中手写并验证子智能体上下文隔离派发与最大递归深度拦截:
# 实验 21 · 动手挑战:手写多智能体上下文隔离派发器 def dispatch_subtasks(subtasks, current_depth=0, max_depth=2): results = {} # TODO: 1. 深度安全检查:若 current_depth >= max_depth,抛出 RecursionError # TODO: 2. 遍历 subtasks,隔离执行 worker_fn(task["context"]) # TODO: 3. 规约聚合各子任务返回值并返回 results 字典 pass tasks = [ {"id": "t1", "worker": lambda ctx: ctx["x"] * 2, "context": {"x": 21}}, {"id": "t2", "worker": lambda ctx: ctx["y"].upper(), "context": {"y": "llm"}}, ] res = dispatch_subtasks(tasks, current_depth=0, max_depth=2) print("Subagents 聚合执行结果:", res) assert res is not None, "dispatch_subtasks 尚未实现" assert res["t1"] == 42 and res["t2"] == "LLM", "子智能体隔离执行结果异常" print("🎉 Subagent 上下文边界隔离与结果规约断言 100% 通过!")
点击右上角「▶ 运行」或按 ⌘/Ctrl+Enter 在浏览器端直接执行