返回 DeepSeek-Reasonix
AGENT_CORE_SIMPLIFICATION.md
根目录 / docs / AGENT_CORE_SIMPLIFICATION.md
1 # Agent Core Simplification
2
3 This document tracks the agent-core simplification effort: the behavioral
4 contract of the simplified loop, the metrics used to compare before/after, and
5 where each contract item is tested. The Chinese version lives in
6 `AGENT_CORE_SIMPLIFICATION.zh-CN.md`.
7
8 ## Target loop
9
10 ```text
11 build request
12 -> provider stream
13 -> clean final: done
14 -> tool call: execute, next step
15 -> reasoning-only terminal: one continuation; fail if no answer follows
16 -> transport/service/empty-response failure: return error, user may retry
17 -> unhandled error: explicit failure
18 ```
19
20 ## Product decisions
21
22 - Connection failures, HTTP errors (including 429/5xx), interrupted streams and
23 empty responses stop the current attempt. There is no automatic backoff,
24 minute-long recovery wait, or unchanged-request replay, including auxiliary
25 search/summary requests. Keep the original error, partial display output and
26 actual request usage; another user submission can try again. Targeted
27 protocol/context repairs remain bounded and separate from transport retries.
28
29 - Normal requests are executor-only; the planner is opt-in (`planner_model`).
30 - A terminal response without visible answer text gets at most one continuation
31 per Run, preserving completed tool results and the existing request prefix.
32 A second no-answer terminal fails with `no_deliverable_output`; intervening
33 tools do not reset this allowance. Cancellation and budgets still win.
34 Cancellation wins until the Run returns, even after a clean answer has been
35 committed, matching DeepSeek Harness: the turn ends cancelled and the answer
36 stays in history for display under the existing cancelled-turn replay policy.
37 Structured finalizers such as `submit_plan` retain their own completion contract.
38 - Compaction defaults to a single summary; chunked/tree-reduce recovery is
39 explicit only (manual `/compact` and marked recovery workflows).
40 - Final readiness, tool safety, cancellation, budgets, and explicit whole-file
41 read pauses stay as hard boundaries. Ordinary partial reads do not freeze
42 independent work; see [Read evidence lifecycle](READ_EVIDENCE_LIFECYCLE.md).
43 - Old configs and old session state stay readable for one release; the new
44 runtime never executes the old fallbacks.
45
46 ## Metrics baseline
47
48 Reuse the existing usage and e2ebench instrumentation; no new fallback
49 telemetry is added. Capture before/after per phase with:
50
51 - `reasonix run --metrics <path>` — per-run `RunMetrics`: token/cost totals,
52 `usage_by_source` (executor/planner/subagent/compaction/... request calls),
53 `retries`, `compactions`, `steps`.
54 - `go run ./cmd/e2ebench -task <task> -json` — per-task request counts,
55 `usage_by_source`, trajectory digest (stream retries, reasoning replays,
56 empty-final retries, TTFT, requests by source), wall time, cache hit/miss.
57
58 | Metric | Source |
59 |---|---|
60 | model requests per normal turn | `usage_by_source["executor"].Calls` / trajectory `ExecutorRequests` |
61 | planner requests | `usage_by_source["planner"].Calls` / trajectory `PlannerRequests` |
62 | reviewer/evaluator/guardian requests | `usage_by_source["recovery_reviewer"|"goal_evaluator"]`, guardian assessment usage |
63 | synthetic continuations | executor requests per clean turn above 1; trajectory `EmptyFinalRetries` |
64 | stream retries | trajectory `StreamRetries` / `RunMetrics.Retries` |
65 | compaction requests and summary spans | `RunMetrics.Compactions`, compaction telemetry notice (`spans=`, `reqs=`) |
66 | first text latency | trajectory `TTFTMs` |
67 | turn latency | `RunMetrics.DurationMs` / bench `WallMs` |
68 | tool execution success | bench task solved rate / `SolvedThenBroken` |
69 | protocol-error terminations | trajectory retry-exhausted outcomes |
70
71 Compare at least: normal Q&A, normal code edit, long-context/tool-heavy
72 (`context-pressure` tasks). Goal per phase: a normal request is one executor
73 request chain, no implicit planner/reviewer/evaluator requests, no extra
74 continuation after a clean final, default compaction never enters multi-span
75 summaries, and hard-safety failure rates do not increase.
76
77 ## Contract tests
78
79 New consolidated suite: `internal/agent/agent_contract_test.go`.
80
81 | Contract item | Test |
82 |---|---|
83 | clean final makes exactly one model request | `TestContractCleanFinalMakesOneModelRequest` |
84 | tool call executes, loop advances | `TestContractToolCallAdvancesToNextStep` |
85 | explicit retry retains thinking without a degraded mode | `TestContractExplicitRetryPreservesThinking` |
86 | provider failure stops after one request in every agent role | `TestProviderFailureReturnsWithoutWaitingOrRetrying` |
87 | interrupted output survives until the user retries | `TestInterruptedStreamStopsUntilUserRetries` |
88 | clean final adds no synthetic continuation | `TestContractCleanFinalAddsNoSyntheticContinuation` |
89 | reasoning-only stop recovers once, then fails without delivery | `TestRunRecoversReasoningOnlyFinalAnswer`, `TestNoDeliverableFailsWithoutProviderSpecificPolicy` |
90 | tool progress cannot replenish recovery; cancellation and budgets win | `TestNoDeliverableRecoveryDoesNotResetAfterTools`, `TestNoDeliverableRecoveryHonorsCancellationAndBudget`, `TestNoDeliverableBudgetSpentDuringRecoveryPauses` |
91 | cancellation after a committed answer still ends the Run cancelled | `TestCancelAfterCommittedAnswerEndsRunCancelled` |
92 | failed delivery and response metadata survive reopen/export | `TestNoDeliverableSettlementAndColdExport` |
93 | empty response leaves retry to the user | `TestEmptyResponseLeavesRetryToUser` |
94 | zero content returns an error without committing an empty message | `TestRunStopsOnZeroContentWithoutCommittingEmptyMessages` |
95 | strict-provider missing reasoning: one frozen-request retry | `TestRunSilentlyRecoversMissingToolCallReasoning` and the replay suites in `loop_e2e_test.go`/`retry_e2e_test.go` (#9776 repair) |
96 | incomplete-read gate | `incomplete_read_test.go` |
97 | final readiness | `final_readiness_test.go` |
98 | cancellation | `cancel_test.go` |
99 | task/token/cost budgets | `run_budget_test.go` |
100 | tool permission/malformed args | `argument_validation_test.go`, gate tests |
101 | ordinary request skips planner | `TestCoordinatorOrdinaryRequestDoesNotCallPlanner`, `TestDecidePlannerRouteExplicitOnly` |
102 | planner prose without `submit_plan` fails | `TestCoordinatorPlanAndExecuteRequiresSubmittedPlan` |
103 | planner failure does not run executor | `TestCoordinatorFailsClosedWhenPlannerFails` |
104 | unusable `planner_model` is a config error | `TestBuildFailsWhenPlannerModelIsUnresolvable` |
105 | ordinary Agent adds no todo continuation | `TestStandardTodoContinuationDisabledByDefault` |
106 | pressure compaction stays single-summary | `TestPressureCompactionDoesNotCallChunkedFold` |
107 | missing guardian/recovery models fail closed | `TestBuildFailsWhenGuardianModelIsUnresolvable`, `TestBuildFailsWhenRecoveryModelIsUnresolvable` |
108
109 ## Gates
110
111 Every phase runs:
112
113 ```bash
114 go test -count=1 ./internal/agent/... ./internal/control/... ./internal/config/... ./internal/boot/...
115 go test -race ./internal/agent/... ./internal/provider/...
116 go vet ./...
117 go run ./tools/repolint
118 ```
119
119 lines MARKDOWN