返回 DeepSeek-Reasonix
task_options.go
根目录 / internal / agent / task_options.go
1 package agent
2
3 import (
4 "context"
5
6 "reasonix/internal/checkpoint"
7 "reasonix/internal/event"
8 "reasonix/internal/imageinput"
9 "reasonix/internal/provider"
10 "reasonix/internal/runtimepolicy"
11 "reasonix/internal/tool"
12 )
13
14 // NewTaskToolWithOptions is the internal standard constructor for TaskTool.
15 // An empty SysPrompt still resolves to DefaultTaskSystemPrompt. No extra
16 // validation or default overrides are applied beyond the historical NewTaskTool
17 // behavior.
18 func NewTaskToolWithOptions(opts TaskToolOptions) *TaskTool {
19 sysPrompt := opts.SysPrompt
20 if sysPrompt == "" {
21 sysPrompt = DefaultTaskSystemPrompt
22 }
23 return &TaskTool{
24 imageInput: opts.ImageInput,
25 prov: opts.Provider,
26 pricing: opts.Pricing,
27 quoteContext: opts.QuoteContext,
28 parentReg: opts.ParentRegistry,
29 maxSteps: opts.MaxSteps,
30 contextWindow: opts.ContextWindow,
31 recentKeep: opts.RecentKeep,
32 compactRatio: opts.CompactRatio,
33 temperature: opts.Temperature,
34 archiveDir: opts.ArchiveDir,
35 keepPolicy: opts.KeepPolicy,
36 sysPrompt: sysPrompt,
37 gate: opts.Gate,
38 subagentModel: opts.SubagentModel,
39 subagentEffort: opts.SubagentEffort,
40 resolveProvider: opts.ResolveProvider,
41 maxSubagentDepth: DefaultMaxSubagentDepth,
42 imageResolver: opts.ImageRequestResolver,
43 hooksForSession: opts.HooksForSession,
44 }
45 }
46
47 // subagentOptions is the single construction point for the run options every
48 // sub-agent spawned through this tool shares (task, read_only_task, and
49 // parallel_tasks children). Compaction, language preferences, and depth limits
50 // must stay uniform across those paths — add new fields here, not at call sites.
51 func (t *TaskTool) subagentOptions(ctx context.Context, maxSteps int, pricing *provider.Pricing, ctxWin, childDepth int, recoveryTaskID string, mutationObserver *checkpoint.MutationObserver) Options {
52 opts := Options{
53 ImageInput: t.imageInput,
54 MaxSteps: maxSteps,
55 MaxOutputTokens: childOutputBudgetFrom(ctx),
56 Temperature: t.temperature,
57 Pricing: pricing,
58 QuoteContext: t.quoteContext,
59 UsageSource: event.UsageSourceSubagent,
60 Gate: t.gate,
61 ContextWindow: ctxWin,
62 RecentKeep: t.recentKeep,
63 CompactRatio: t.compactRatio,
64 ArchiveDir: t.archiveDir,
65 KeepPolicy: t.keepPolicy,
66 ResponseLanguage: ResponseLanguageFromContext(ctx),
67 ReasoningLanguage: ReasoningLanguageFromContext(ctx),
68 SubagentDepth: childDepth,
69 MaxSubagentDepth: t.maxDepth(),
70 Ablation: t.ablation,
71 WorkspaceLease: t.workspaceLease,
72 MutationObserver: mutationObserver,
73 WriteRoots: t.writeRoots,
74 DisableWriteAccessExpand: true,
75 WriteWorkspaceRoot: t.workspaceRoot,
76 ImageRequestResolver: t.imageResolver,
77 }
78 if t.hooksForSession != nil {
79 opts.Hooks = t.hooksForSession(recoveryTaskID)
80 }
81 // Writer children inherit the parent turn's frozen risk and closure floors.
82 // The parent publishes its policy into the run context; a child that never
83 // received it (direct unit construction) keeps its own derived policy.
84 if inherited, ok := runtimepolicy.InheritedFromContext(ctx); ok {
85 copy := inherited
86 opts.InheritedExecution = &copy
87 } else if constraints, ok := runtimepolicy.FromContext(ctx); ok {
88 opts.InheritedExecution = &runtimepolicy.InheritedExecutionContext{Constraints: constraints}
89 }
90 return opts
91 }
92
93 func (t *TaskTool) WithImageRequestResolver(resolver ImageRequestResolver) *TaskTool {
94 if t == nil {
95 return nil
96 }
97 t.imageResolver = resolver
98 return t
99 }
100
101 // TaskToolOptions holds the construction parameters for a TaskTool.
102 // Prefer NewTaskToolWithOptions for new call sites; the positional NewTaskTool
103 // remains as a compatibility wrapper for one full iteration cycle.
104 type TaskToolOptions struct {
105 ImageInput *imageinput.Config
106 ImageRequestResolver ImageRequestResolver
107 HooksForSession func(string) ToolHooks
108 Provider provider.Provider
109 Pricing *provider.Pricing
110 QuoteContext *event.QuoteContext
111 ParentRegistry *tool.Registry
112 MaxSteps int
113 ContextWindow int
114 RecentKeep int
115 SoftCompactRatio float64
116 ToolResultSnipRatio float64
117 CompactRatio float64
118 CompactForceRatio float64
119 Temperature float64
120 ContextEditing, ArchiveDir, SysPrompt string
121 Gate Gate
122 KeepPolicy KeepPolicy
123 SubagentModel string
124 SubagentEffort string
125 ResolveProvider func(string, string) (provider.Provider, *provider.Pricing, int, error)
126 }
127
127 lines GO