Skip to content

执行生命周期与结果

TriggerFlow 的执行结果由 end()set_result() 决定;start() 会先 emit START 事件启动信号链。

start 与结果规则

关键规则:

  1. start(wait_for_result=True) 会等待结果。
  2. end() 会把当前链路值作为默认结果。
  3. when() 分支不会自动产出结果。
python
from agently import TriggerFlow, TriggerFlowEventData

flow = TriggerFlow()

@flow.chunk
async def work(data: TriggerFlowEventData):
  return f"work({data.value})"

flow.to(work).end()
result = flow.start("task")
print(result)

手动设置结果

当流程主要由事件驱动时,可以手动设置结果:

python
from agently import TriggerFlow, TriggerFlowEventData

flow = TriggerFlow()

@flow.chunk
def passthrough(data: TriggerFlowEventData):
  return data.value

flow.to(passthrough).end()

execution = flow.start_execution("ignored", wait_for_result=False)
execution.set_result("manual result")
print(execution.get_result())

超时与警告

start()get_runtime_stream() 支持 timeout,超时会返回 None 并输出警告。