- 11.4.2:三类节点首次真进图 —— memory.recall/memory.write(loop/memory.go 召回与写入点)、 guardrail.input/output(流式主路径两侧 + agent.RunStep 静音路径)、orchestration.spawn (scheduler 每次派发/收束);新增 trace.ChildSpan 让不持有 Tracer 的叶子包也能开子 span - 11.4.3(设计先行,规格先写进 design/19 §1.1):tool 节点参数摘要 —— 放行表 argValueKeys + trace.IsSecretKey 统一判据(密钥类键不给值)+ 单值 80 rune / ≤24 条 + 出图前再清洗; 前端 NodeDetail 新增「参数摘要」区,未放行键显示「值未展示」 - 13.4.1:流式主路径输出侧护栏改后台 goroutine(脱离 context、30s 兜底、不阻塞回合), 输入侧仍在模型调用前同步拦下;拦截闭环到 guardrail 节点 + 审计事件 - 拆文件:scheduler.go 加 span 后 546 行 → 编排 span 助手拆出 scheduler_spans.go(回到 492) - 契约:无帧名/事件形状变化;graph_update 节点 props 新增**可选**键(tool args_keys/args_summary、 guardrail action/allow/elapsed_ms、memory action/scope/hits/…、orchestration subagent/persona), 文档同步由主会话统一落
66 lines
2.4 KiB
Go
66 lines
2.4 KiB
Go
package orchestration
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
|
|
)
|
|
|
|
// 本文件是调度层的「编排 span」:把每次子代理派发与收束记成一个
|
|
// orchestration 节点(design/19 §1 旁路节点,裁决 11.4.2)。它从
|
|
// scheduler.go 拆出,因为该文件已接近 AGENTS §10 的 500 行上限,
|
|
// 而 span 的开启/收尾是一块独立职责。
|
|
|
|
// orchestration.dispatch 的 span 名与收尾事件类型:此前调度只发
|
|
// SpanKindSubagent,因此全仓没有任何 orchestration 节点。
|
|
const (
|
|
spanNameOrchestrationSpawn = "orchestration.spawn"
|
|
orchestrationEventDone = "orchestration.done"
|
|
)
|
|
|
|
// orchSpan 为一次子代理派发开一个 orchestration span。它是挂在主干上的
|
|
// 「派发标记」:与泳道根并列而不是它的父级 —— 若把它当作子代理 span 的父级,
|
|
// 泳道链会多出一节(图构建器把非 subagent 祖先一路穿透解析泳道),既有泳道
|
|
// 契约就被改写了。span 只带非敏感属性(被派发的子代理 id、目标角色 id),
|
|
// 声明了归属会话时同时发布一个「运行中」占位节点。未配置 tracer 时返回 nil。
|
|
func (s *Scheduler) orchSpan(ctx context.Context, sub *SubAgent) *trace.Span {
|
|
if s.tracer == nil || sub == nil {
|
|
return nil
|
|
}
|
|
_, span := s.tracer.StartSpan(ctx, spanNameOrchestrationSpawn, trace.SpanKindOrchestration)
|
|
if sub.ID != "" {
|
|
_ = span.SetProp("subagent", sub.ID)
|
|
}
|
|
if sub.PersonaID != "" {
|
|
_ = span.SetProp("persona", sub.PersonaID)
|
|
}
|
|
if sess := sub.ParentSession; sess != "" && s.flow != nil {
|
|
_ = span.SetProp("session", sess)
|
|
s.flow.SpanStarted(sess, span)
|
|
}
|
|
return span
|
|
}
|
|
|
|
// finishOrchSpan 收尾一次派发:记录耗时(失败另记原因)与一条脱敏事件,
|
|
// 失败时终态为 error,然后把已关闭的 span 折回所属会话的图。
|
|
func (s *Scheduler) finishOrchSpan(sub *SubAgent, span *trace.Span, err error) {
|
|
if span == nil {
|
|
return
|
|
}
|
|
props := map[string]any{"elapsed_ms": trace.ElapsedMS(span)}
|
|
if err != nil {
|
|
props["error"] = err.Error()
|
|
_ = span.SetProp("error", err.Error())
|
|
}
|
|
_ = span.Record(trace.Event{Type: orchestrationEventDone, Props: props})
|
|
status := trace.SpanStatusOK
|
|
if err != nil {
|
|
status = trace.SpanStatusError
|
|
}
|
|
span.Finish(status)
|
|
if s.flow == nil || sub == nil || sub.ParentSession == "" {
|
|
return
|
|
}
|
|
s.flow.SpanFinished(sub.ParentSession, span)
|
|
}
|