feat(dingtalk): enable secure multimodal image QA

This commit is contained in:
姚章浩
2026-07-16 00:17:16 +08:00
parent 4022040e98
commit c9c4f0aaa5
59 changed files with 3279 additions and 429 deletions
+10 -6
View File
@@ -2,6 +2,7 @@ package agent
import (
"context"
"errors"
"fmt"
"strings"
"time"
@@ -60,7 +61,7 @@ func (e *AgentEngine) streamLLMToEventBus(
// as if they were part of the LLM answer.
if chunk.ResponseType == types.ResponseTypeError {
result.StreamError = chunk.Content
continue
break
}
if chunk.Content != "" {
@@ -89,6 +90,9 @@ func (e *AgentEngine) streamLLMToEventBus(
if emitFunc != nil {
emitFunc(&chunk, result.Content)
}
if chunk.Done && chunk.ResponseType == types.ResponseTypeAnswer {
break
}
}
// Stream diagnostic summary: helps identify non-streaming patterns
@@ -101,10 +105,10 @@ func (e *AgentEngine) streamLLMToEventBus(
chunkCount, len(result.Content), len(result.ToolCalls),
streamDuration.Milliseconds(), responseTypeCounts)
// If the stream produced an error and no usable content/tool calls,
// surface it as a Go error so the caller can retry or degrade gracefully.
if result.StreamError != "" && result.Content == "" && len(result.ToolCalls) == 0 {
return result, fmt.Errorf("LLM stream error: %s", result.StreamError)
// A provider error invalidates the entire stream, even if partial content or
// tool calls arrived first. The caller must replace/discard that partial data.
if result.StreamError != "" {
return result, errors.New("LLM stream failed")
}
return result, nil
@@ -406,7 +410,7 @@ func (e *AgentEngine) callLLMWithRetry(
"steps": len(state.RoundSteps),
"tool_calls": totalTC,
})
if synthErr := e.streamFinalAnswerToEventBus(ctx, query, state, sessionID); synthErr != nil {
if synthErr := e.streamFinalAnswerToEventBus(ctx, query, state, sessionID, collectAgentImageURLs(messages)); synthErr != nil {
logger.Errorf(ctx, "[Agent] Final answer synthesis also failed: %v", synthErr)
return nil, fmt.Errorf("LLM call failed: %w (synthesis also failed: %v)", err, synthErr)
}