返回 DeepSeek-Reasonix
vision_summary.go
根目录 / internal / control / vision_summary.go
1 package control
2
3 import (
4 "context"
5
6 "reasonix/internal/agent"
7 "reasonix/internal/imageinput"
8 "reasonix/internal/provider"
9 )
10
11 // prepareVisionTurn shares the same per-session processor as tool results.
12 func (c *Controller) prepareVisionTurn(ctx context.Context, input string, images []string) (string, context.Context, error) {
13 prepared, _ := ctx.Value(preparedImageReferencesContextKey{}).(preparedImageReferences)
14 if c == nil || (len(images) == 0 && len(prepared.inputs) == 0) || c.imageInputEnabled() {
15 return input, ctx, nil
16 }
17 if c.visionModel == "" && !prepared.requiresImageUnderstanding {
18 // Keep the frozen bytes available to vision-capable child agents while
19 // withholding them from the text-only parent provider request.
20 return input, agent.WithUserImageInputs(ctx, nil), nil
21 }
22 var svc *imageinput.Service
23 var history func() []provider.Message
24 if c.executor != nil {
25 svc = c.executor.ImageInput()
26 history = c.executor.Session().Snapshot
27 }
28 if svc == nil {
29 svc = imageinput.New(imageinput.Config{Model: c.visionModel, Resolve: c.visionProviderResolver, Select: c.visionModelSelector})
30 }
31 target, err := svc.SelectModel(c.selection.ref, images)
32 if err != nil {
33 return input, ctx, imageRequestFailure(ctx, err)
34 }
35 if len(prepared.inputs) > 0 {
36 route, routeErr := c.imageRequestRoute(target)
37 if routeErr != nil {
38 return input, ctx, imageRequestFailure(ctx, routeErr)
39 }
40 images, err = c.resolveImageInputsForRoute(ctx, prepared.inputs, route)
41 if err != nil {
42 return input, ctx, imageRequestFailure(ctx, err)
43 }
44 }
45 summary, err := svc.UnderstandSelected(ctx, target, images, history, c.sink)
46 if err != nil {
47 return input, ctx, imageRequestFailure(ctx, err)
48 }
49 return imageinput.AppendSummary(input, summary), agent.WithVisionSummary(ctx, summary), nil
50 }
51
51 lines GO