larry-zy commented on code in PR #1616:
URL: https://github.com/apache/dubbo-admin/pull/1616#discussion_r4514803051
##########
ai/component/hooks/component.go:
##########
@@ -149,6 +165,7 @@ func (c *Component) initTracing(rt *runtime.Runtime, spec
TracingSpec) error {
sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(spec.SampleRatio))),
)
registration :=
NewTracingRegistration(provider.Tracer("dubbo-admin-ai/hooks"),
spec.CaptureContent)
+ registration.CaptureReasoning = spec.captureReasoningPolicy()
Review Comment:
**[P1] 采集策略需要覆盖 Genkit 自身导出的 span**
这里将 `CaptureReasoning` 仅接到自定义 hook,但下面的 `otel.SetTracerProvider(provider)`
同时让 Genkit 使用同一个导出 provider。当前依赖 Genkit v1.2.0 的 `core/tracing` 会直接写入
`genkit:input` / `genkit:output`,这些属性不经过 Manager 的任何采集策略。
复现:启用 tracing、两个 capture 开关均设为 `none`,使用实际的 `buildPrompt` /
`ReActAgent.Interact` 执行 Genkit Prompt(模型用 `genkit.DefineModel` 返回固定结果,不使用绕过
Genkit 的 stubPrompt)。同一 provider 的 SpanRecorder 仍能在 `genkit-tracer` 的
prompt/model/generate span 中找到用户输入和系统提示词。模型返回 reasoning part 时,即使
`capture_content=full`、`capture_reasoning=none`,`genkit:output` 仍包含原始 reasoning。
全局 provider 接线在 base 中已存在,不是本 PR 新引入的回归;但新增 reasoning
开关也没有覆盖这条路径,因此文档中“关闭采集后不导出内容”的保证对完整 trace 不成立。建议在统一导出边界处理 Genkit 的内容属性,或隔离其
telemetry,并增加检查全部已导出 span 属性的回归测试。
##########
ai/component/agent/react/hook_content.go:
##########
@@ -63,6 +72,14 @@ func convertGenAIMessages(messages []*ai.Message,
finishReason string) []genAIMe
continue
case part.IsText():
parts = append(parts, genAIMessagePart{Type:
"text", Content: part.Text})
+ case part.IsReasoning():
Review Comment:
**[P1] 当前实际模型适配器没有产生这里需要的 reasoning part**
`component/models.createModelPlugin` 当前走 `compat_oai.OpenAICompatible`。依赖的
Genkit v1.2.0 `plugins/compat_oai/generate.go` 将回答正文和 tool calls 转成
`ai.Part`,没有把 OpenAI 兼容响应中的 `reasoning_content` 转成
`ai.NewReasoningPart`。因此对于返回该字段的思考模型,配置 `capture_reasoning: full` 仍然无法采到思考内容。
已使用自定义 HTTP RoundTripper 返回包含 `message.content="answer"` 和
`message.reasoning_content="REVIEW_REASONING_SENTINEL"` 的 chat completion,经过实际的
`compat_oai.NewModelGenerator(...).Generate(...)` 再调用
`genAIOutputMessages`,结果只有 `type:"text"`,reasoning 已在到达此处分支之前丢失。
建议补齐 provider 响应到 Genkit part 的适配,再添加“HTTP 响应 → 实际适配器 → hook 消息”的回归用例。现有直接构造
`NewReasoningPart` 的测试只能证明转换分支有效,不能证明当前模型接入能使用这项功能。
##########
ai/component/hooks/manager.go:
##########
@@ -196,8 +230,14 @@ func (m *Manager) Emit(ctx context.Context, state State)
context.Context {
hookState.inputContent = nil
hookState.outputContent = nil
} else if !reg.lazyContent {
- hookState.Input = state.snapshotInputContent()
- hookState.Output = state.snapshotOutputContent()
+ // The eager content is materialized before the hook
runs, so the
+ // reasoning policy is applied to it right away.
+ hookState.Input =
ApplyReasoningPolicy(state.snapshotInputContent(), reg.captureReasoning)
Review Comment:
**[P2] 将 reasoning 过滤限定在 GenAI 消息上,避免改写工具业务数据**
这里的策略会作用于通用 `State.Input/Output`,包括工具入参与返回值;lazy 路径也会在 snapshot
时执行相同过滤。`filterReasoningParts` 又会递归识别任意对象中的 `parts` /
`type:"reasoning"`,并没有确认它是模型消息。
已通过 `EventToolCallStart` + tracing
registration(`capture_content=full`、reasoning 默认 `none`)复现:输入业务 JSON
`{"parts":[{"type":"reasoning","content":"business
record"},{"type":"result","content":"keep"}]}`,导出的 `gen_ai.tool.call.arguments`
只剩 `result` 项。工具实际收到的入参没有被修改,但 trace 已不再忠实反映调用内容;接入使用同名字段的自定义工具就会触发。
建议在明确的 GenAI message/part 类型上应用 reasoning 策略,或给内容快照增加类型区分,只过滤
`gen_ai.input.messages` / `gen_ai.output.messages`,保留工具业务 JSON 的原始语义。
##########
ai/component/agent/react/steps.go:
##########
@@ -179,6 +182,7 @@ func (ra *ReActAgent) runIteration(ctx context.Context,
chans *agent.Channels, h
runtime.GetLogger().Warn("react: empty forced answer, using
fallback")
answer = fallbackAnswer
}
+ s.Answer = answer
Review Comment:
**[P2] 成功交付后再记录根 span 的最终回答**
`s.Answer` 在 `finish()` 之前赋值,而当前 `finish()`
先持久化答案,再写入用户输出通道。如果持久化失败,交互会返回错误,答案没有发送给用户,但 `EventInteractionEnd` 仍把这里的
`s.Answer` 写入根 span 的 `gen_ai.output.messages`,与新增字段“用户实际收到的最终回答”的语义不符。
已在合入最新 `ai` 的副本上注入第二次 `AddHistoryToTurn`(最终答案写入)失败:`UserRespChan`
没有任何答案,`ErrorChan` 返回 `failed to persist final answer`,根 span 却包含完整答案。根 span 的
Error 状态仍然正确,失真的是 output,排查漏答时会误导。
建议在 `finish()` 成功返回之后赋值;若需要保留已生成但未交付的内容,则明确区分生成结果和交付结果,并补一个持久化失败场景的根 span 断言。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]