返回 DeepSeek-Reasonix
turnruntime.go
根目录 / internal / agent / turnruntime.go
1 package agent
2
3 import (
4 "reasonix/internal/completion"
5 "reasonix/internal/runtimepolicy"
6 )
7
8 // turnRuntime is the host state for exactly one Agent.Run. beginRunTurn builds
9 // it in a single assignment, so a field added here starts the next turn zeroed.
10 // State an external caller arms before a Run lives in pendingTurn; state that
11 // outlives the Run lives in taskRuntime or sessionRuntime.
12 type turnRuntime struct {
13 runMaxSteps int
14 runMaxStepsKey string
15
16 terminal terminalProtocolState
17 usedAnyTool bool
18 graceRound bool
19
20 input string
21 workDurationMs func() int64
22
23 // budget is the turn's spend axis: tokens, money, wall clock.
24 budget runBudget
25 // landCause records why the grace round was armed, so the pause the Run
26 // ends with names the axis that actually stopped it.
27 landCause landCause
28
29 // turnInput is the owning task text for explicit constraints and recovery.
30 turnInput string
31 // completion is the report built as the turn ends; the host reads it while
32 // emitting TurnDone, before the next turn resets this state.
33 completion *completion.Report
34 deliveryScopeActive bool
35 // recoveryTaskSummary is the bounded task text for this Agent.Run. It lets
36 // a shared recovery gate review sub-agent mutations against the child
37 // task, rather than the root controller transcript.
38 recoveryTaskSummary string
39
40 repeatKey string
41 repeatCount int
42 loop turnLoopState
43
44 // constraints and engine are frozen at the start of the Run.
45 constraints runtimepolicy.Constraints
46 engine *runtimepolicy.Engine
47
48 // reviewWarnings are warn-level findings to surface in the final summary.
49 reviewWarnings []string
50
51 // lastReasoning is the previous executor round's reasoning-token spend,
52 // read by the governor trigger (live policy and fork capture alike).
53 lastReasoning int
54
55 phase phaseClock
56
57 // sessionContext is the content-free diagnostic for the snapshot selected
58 // before this real user turn. It is attached to Usage events only.
59 sessionContext turnContextDiagnostics
60 }
61
62 // terminalProtocolState groups the run's terminal-protocol bookkeeping: the
63 type terminalProtocolState struct {
64 // emptyFinalBlocks counts consecutive reasoning-only stops retried for a
65 // visible final answer.
66 emptyFinalBlocks int
67 }
68
69 // pendingTurn is what someone outside the Run arms for the next one: a
70 // sub-agent spawner, the turn that just failed readiness, or the fork capture.
71 // It is deliberately not in turnRuntime — beginRunTurn builds that fresh, and
72 // state armed before it exists would be wiped by the same assignment that makes
73 // turnRuntime safe.
74 type pendingTurn struct {
75 // forkRestore, when armed, swaps the frozen fork-bundle conversation in
76 // right after beginRunTurn — the counterfactual-continuation seam.
77 forkRestore func(*turnRuntime)
78 }
79
79 lines GO