跳转至

Result 控制

显式 set_result 控制输出。

源码

from agently import TriggerFlow, TriggerFlowEventData


## TriggerFlow Result: set_result to control output
def triggerflow_set_result_demo():
    # Idea: control the final output explicitly with set_result().
    # Flow: start_execution -> async work -> set_result -> await result
    # Expect: prints "final answer: done".
    flow = TriggerFlow()

    async def worker(data: TriggerFlowEventData):
        return f"work({data.value})"

    flow.to(worker).end()

    execution = flow.start_execution("task-1", wait_for_result=False)
    execution.set_result("final answer: done")
    result = execution.get_result()
    print(result)


# triggerflow_set_result_demo()

讲解

  • 事件流需要明确结果输出。

注释解读

  • Idea 表示案例思路
  • Flow 表示执行编排路径
  • Expect 表示预期输出或行为

你学会了什么

  • 理解 set_result 与 end 的差异

练习任务

  • 移除 end 后手动 set_result