You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Sink块中分别获取TypeA与TypeB代理的平均时间?

分类型统计代理平均停留时间的解决方案

方法一:自定义属性+独立统计变量

  • 在你的代理类型中添加double类型属性,命名为entryTime
  • 在代理进入流程的首个块(如Source或起始处理块)的on enter动作中,写入代码:entryTime = time();
  • 新增两个Statistics > Mean类型变量,命名为avgStayTime_TypeA和avgStayTime_TypeB
  • 在Sink块的on enter动作中,按类型计算并更新统计:
    double stayDuration = time() - entryTime;
    if (this.type.equals("TypeA")) { // 替换为你实际判断TypeA的逻辑
        avgStayTime_TypeA.add(stayDuration);
    } else if (this.type.equals("TypeB")) {
        avgStayTime_TypeB.add(stayDuration);
    }
    
  • 后续可通过avgStayTime_TypeA.getMean()或avgStayTime_TypeB.getMean()直接获取对应类型的平均停留时间

方法二:按类型绑定Time Measure组件

  • 添加两个Time Measure组件,分别命名为timeMeasure_TypeA和timeMeasure_TypeB
  • 在代理进入流程起点的on enter动作中,按类型启动对应计时:
    if (this.type.equals("TypeA")) {
        timeMeasure_TypeA.start(this);
    } else if (this.type.equals("TypeB")) {
        timeMeasure_TypeB.start(this);
    }
    
  • 在Sink块的on enter动作中,按类型结束对应计时:
    if (this.type.equals("TypeA")) {
        timeMeasure_TypeA.end(this);
    } else if (this.type.equals("TypeB")) {
        timeMeasure_TypeB.end(this);
    }
    
  • 每个Time Measure组件的mean属性即为对应类型代理的平均停留时间

注意事项

  • 确保代理类型的判断逻辑与你实际的代理字段匹配(比如是枚举、字符串还是其他标识)
  • 若代理存在流程分流,需保证每个代理的计时启动与结束操作对应同一个Time Measure组件

内容的提问来源于stack exchange,提问作者Rob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 13:32:33