Skip to content

[Performance] Add reusable compiled workflow plans for interactive requests #1529

Description

@ShuhaoZhangTony

背景

Sage Mate 的复杂请求会动态构建并验证 SAGE workflow。真实验收中,完整请求约 149 秒,而直接模型请求通常约 0.5–7 秒。SAGE 需要把“声明 workflow”和“每次执行 workflow”分离,避免对结构等价的交互请求反复完成规划、编译、验证和资源绑定。

目标

为交互式 AI 请求提供可复用、可版本化、可观测的 compiled workflow plan,并支持仅对请求相关部分做增量绑定。

范围

  • 定义稳定的 plan fingerprint:operator DAG、schema、策略版本、插件/模型 capability、知识检索契约和资源类别;不得包含会导致每个用户请求都 miss 的瞬态字段。
  • 将 workflow construction 拆成 declaration、static validation、compile、runtime bind、execute 五个阶段。
  • 缓存不可变 compiled plan;每次请求只绑定 trace、deadline、身份、输入、证据和取消 token。
  • 支持 single-flight:并发 miss 只编译一次,其余请求等待同一结果。
  • 定义失效条件、容量上限、LRU/TTL、版本升级和失败编译的负缓存策略。
  • 暴露 build/compile/bind/execute 耗时与 hit/miss/eviction 指标。
  • 保留动态 planner 的能力;仅在结构或 capability 真正变化时重规划。

与现有 issue 的关系

非目标

  • 不为某个 Sage Mate 问题硬编码 DAG。
  • 不缓存用户数据、引用结果或取消 token。
  • 不用跳过 validation 的方式制造 cache hit。

验收标准

  • 提供 cold compile、warm hit、并发 single-flight、版本失效和失败恢复测试。
  • 结构相同的 warm workflow:plan lookup + bind p95 ≤250ms;cold build + compile p95 ≤2s(不含 operator 执行与模型推理)。
  • 20 个并发相同 fingerprint 请求最多触发一次 compile。
  • 缓存命中与未命中产生语义等价的 operator 顺序、输出和错误传播。
  • 完成/取消/超时后 plan 中不存在 request-scoped 引用,生命周期测试无残留。
  • 提供 Sage Mate 集成基准,证明端到端阶段账本中 workflow construction 明显下降。

交付物

  • typed plan/fingerprint/cache API。
  • 指标、trace 字段和调试命令。
  • 单元、并发、生命周期和 Sage Mate 集成测试。
  • 迁移文档与一个不含业务硬编码的示例。

Metadata

Metadata

Labels

enhancementEnhancement to existing feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions