返回 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 graceRound bool
18
19 input string
20 workDurationMs func() int64
21
22 // budget is the turn's spend axis: tokens, money, wall clock.
23 budget runBudget
24 // landCause records why the grace round was armed, so the pause the Run
25 // ends with names the axis that actually stopped it.
26 landCause landCause
27
28 // turnInput is the owning task text for explicit constraints and recovery.
29 turnInput string
30 // completion is the report built as the turn ends; the host reads it while
31 // emitting TurnDone, before the next turn resets this state.
32 completion *completion.Report
33 deliveryScopeActive bool
34 // recoveryTaskSummary is the bounded task text for this Agent.Run. It lets
35 // a shared recovery gate review sub-agent mutations against the child
36 // task, rather than the root controller transcript.
37 recoveryTaskSummary string
38
39 repeatKey string
40 repeatCount int
41 loop turnLoopState
42
43 // constraints and engine are frozen at the start of the Run.
44 constraints runtimepolicy.Constraints
45 engine *runtimepolicy.Engine
46
47 // reviewWarnings are warn-level findings to surface in the final summary.
48 reviewWarnings []string
49
50 // lastReasoning is the previous executor round's reasoning-token spend,
51 // read by the governor trigger (live policy and fork capture alike).
52 lastReasoning int
53
54 phase phaseClock
55
56 // sessionContext is the content-free diagnostic for the snapshot selected
57 // before this real user turn. It is attached to Usage events only.
58 sessionContext turnContextDiagnostics
59 }
60
61 // terminalProtocolState groups the run's terminal-protocol bookkeeping: the
62 type terminalProtocolState struct {
63 // emptyFinalBlocks counts no-answer stops across the entire Run, including
64 // intervening tool rounds. Tool progress must not replenish recovery.
65 emptyFinalBlocks int
66 // answeringRecovery marks the next committed response as the reply to a
67 // synthetic no-answer recovery, so diagnostics attribute only that one.
68 answeringRecovery bool
69 }
70
71 // pendingTurn is what someone outside the Run arms for the next one: a
72 // sub-agent spawner, the turn that just failed readiness, or the fork capture.
73 // It is deliberately not in turnRuntime — beginRunTurn builds that fresh, and
74 // state armed before it exists would be wiped by the same assignment that makes
75 // turnRuntime safe.
76 type pendingTurn struct {
77 // forkRestore, when armed, swaps the frozen fork-bundle conversation in
78 // right after beginRunTurn — the counterfactual-continuation seam.
79 forkRestore func(*turnRuntime)
80 }
81
81 lines GO