Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(agent-core): give the checkpoint turn an output budget of min(64,000, O) (#2493)
Call White5018b6ffcc6f
diff --git a/core/agent_core/harness/context.py b/core/agent_core/harness/context.pyindex 8a53a8639..578256dc4 100644--- a/core/agent_core/harness/context.py+++ b/core/agent_core/harness/context.py@@ -92,7 +92,8 @@ CLEARED_PLACEHOLDER = ("[Old tool result cleared to save context. Re-run the tool or re-read the file if you need it again.]")-CHECKPOINT_MAX_TOKENS = 16_000+#: A checkpoint request asks for at most this many output tokens, its reasoning included (section 6).+CHECKPOINT_MAX_TOKENS = 64_000CHECKPOINT_TRUNCATED = ("[Output truncated to fit this checkpoint turn: showing about {shown} of {total} tokens. ""Read a smaller range if you need more.]"@@ -366,7 +367,7 @@ def output_tokens(capabilities: ModelCapabilities, configured: int) -> int:def checkpoint_max_tokens(capabilities: ModelCapabilities, configured: int) -> int:- """A checkpoint request's ``max_tokens``: ``min(16,000, O)`` (section 6)."""+ """A checkpoint request's ``max_tokens``: ``min(64,000, O)`` (section 6)."""return min(CHECKPOINT_MAX_TOKENS, output_tokens(capabilities, configured))diff --git a/docs/plans/agent-core-contracts/context.md b/docs/plans/agent-core-contracts/context.mdindex ce6424122..2df1e32e7 100644--- a/docs/plans/agent-core-contracts/context.md+++ b/docs/plans/agent-core-contracts/context.md@@ -1,10 +1,10 @@# C-9 Context managementFrozen 2026-10-04 by owner decision; amended 2026-10-12 by owner decision (the estimate of opaque reasoning payloads-and the anchor's validity, §2; the cache lifetime per route, §3). The `harness` owns the rules-(`core/agent_core/harness/context.py`, `projection.py`); the loop applies them before every model request-(`core/agent_core/agent/loop.py`); the adapter supplies the Session-specific parts (§9). Row shapes:-[`transcript-rows.schema.json`](transcript-rows.schema.json); events:+and the anchor's validity, §2; the cache lifetime per route, §3; the checkpoint request's output budget, §1 and §6).+The `harness` owns the rules (`core/agent_core/harness/context.py`, `projection.py`); the loop applies them before+every model request (`core/agent_core/agent/loop.py`); the adapter supplies the Session-specific parts (§9). Row+shapes: [`transcript-rows.schema.json`](transcript-rows.schema.json); events:[`agent-event.schema.json`](agent-event.schema.json).Three tiers, cheapest first:@@ -30,7 +30,7 @@ stage only considers: the fork it would send first, and the minimal request of tW = context_window (128,000 when unknown)L_in = input_limit (W when unknown)O = the request's max_tokens: for a conversation request max_output_tokens (8,192 when unknown), capped by the- Agent's output budget; for a checkpoint request min(16,000, that)+ Agent's output budget; for a checkpoint request min(64,000, that)M = min(max(8,000, ceil(0.03 * W)), floor(W / 8))T = min(L_in - O - M, floor(0.9 * W)) the compaction thresholdkeep = min(20,000, floor(0.25 * T)) the verbatim tail of a normal checkpoint@@ -199,7 +199,13 @@ A checkpoint is written by a **side turn** of the conversation (C-10 `fork.md`- The request uses the same hop, system prompt, tool definitions, tool choice, and reasoning settings as theconversation's next request, and its messages begin with the conversation's projected messages unchanged, so itsprefix is byte-identical to the previous request's and a warm provider cache hits. Tool choice, thinking, and- effort are never changed: Anthropic renders them into the prompt. `max_tokens = min(16,000, O)`.+ effort are never changed: Anthropic renders them into the prompt. `max_tokens = min(64,000, O)`. It bounds the+ reasoning as well as the checkpoint text, and a length stop fails the turn (below). Three checkpoints measured at+ `xhigh` effort on 246,000 to 307,000-token contexts wrote 9,200 to 10,600 tokens of checkpoint text, and 11,552 to+ 20,644 tokens of output with their reasoning. Reasoning varied from 2,070 to 10,018 tokens and may grow with the+ context; a checkpoint near `T` on a 1,000,000-token window reads about three times those contexts. Output is billed+ as produced, so an unused budget costs nothing, and `T` already reserves `O` (§1), so the request can fit at+ `est = T`.- **Normal**: the prefix is the whole projected conversation. **Rolling**: the prefix is the projected context up tothe cut, which is a prefix of the original request.- One user message is appended: the checkpoint request (§11). It takes the user role, but it comes from the harness,@@ -224,9 +230,9 @@ below, and the budget's 5 rounds, 4,000-token floor, and 1,000-token slack; C-10unavailable. Write the checkpoint as your reply text, not into a file.` (a model denied a file write may otherwisekeep trying one; the owner-approved request, §11, stays untouched).- Every request of the turn is budgeted on the route resolved for it (§1): its `max_tokens` is that route's- `min(16,000, O)`.+ `min(64,000, O)`.- The bound is the window, not `T`, the same way in threshold and rolling turns. Before each call,- `room = L_in - est - min(16,000, O) - reserved`, where `est` is the budget of the turn's latest request plus the+ `room = L_in - est - min(64,000, O) - reserved`, where `est` is the budget of the turn's latest request plus thetokens of the response and results since, and `reserved` is one fixed-text result (the longer of the two below)for each later call of the same response, so every result of the batch is accounted for before it exists. This isthe one bound that extends the latest request's budget by arithmetic (§10, invariant 1). A call runs only whilediff --git a/docs/plans/agent-core-contracts/fork.md b/docs/plans/agent-core-contracts/fork.mdindex 8e2ff9532..89c923cca 100644--- a/docs/plans/agent-core-contracts/fork.md+++ b/docs/plans/agent-core-contracts/fork.md@@ -494,7 +494,7 @@ through `reserve_forked_session`:- When to compact: the trigger, the overflow ladder, and the bounds.- Which prefix to use: the whole view for a normal checkpoint, or `units` from `rolling_cut` for a rolling one.-- The checkpoint request and `max_tokens = min(16,000, O)`.+- The checkpoint request and `max_tokens = min(64,000, O)`.- The validator (the side turn's check, with its one repair), the row, and the events.Behavior does not change. The C-9 tests pass, with only the audit kind renamed.@@ -625,7 +625,7 @@ class SideTurn:# the request puts the caller's rehydrated messages firstprompt: UserMessagepolicy: ForkPolicy- max_tokens: Callable[[ModelCapabilities], int] # per route; C-9: min(16,000, O)+ max_tokens: Callable[[ModelCapabilities], int] # per route; C-9: min(64,000, O)fold: Callable[[SideReply], Awaitable[Folded]] # sees only a reply the check acceptedcheck: Optional[Callable[[AssistantMessage], Optional[str]]] = None # None accepts; else the problemrepair: Optional[Callable[[str], UserMessage]] = None # the one corrective follow-up; comes with checkdiff --git a/docs/plans/avibe-agent-core.md b/docs/plans/avibe-agent-core.mdindex 62ccf663d..ee9f064df 100644--- a/docs/plans/avibe-agent-core.md+++ b/docs/plans/avibe-agent-core.md@@ -184,7 +184,7 @@ and `bash` results with `context_edit` rows, on by default; and a checkpoint wri- **Limits from Model Hub.** `W` and `L_in` come from the `context_window` and `input_limit` of the route resolvedfor the request (128,000 when unknown). `O` is the request's `max_tokens`: the hop's `max_output_tokens` (8,192- when unknown) capped by the Agent's output budget, and `min(16,000, O)` for a checkpoint request. One pure+ when unknown) capped by the Agent's output budget, and `min(64,000, O)` for a checkpoint request. One purefunction derives the rest and `est` from the final request, immediately before it is sent.`M = min(max(8,000, 3% W), W / 8)`, `T = min(L_in - O - M, 0.9 W)`.- **Trigger** before every model request, including inside the tool loop, on the final request (in v1 no user hookdiff --git a/tests/agent_core/agent/test_compaction.py b/tests/agent_core/agent/test_compaction.pyindex 75275c777..b45a8bbfe 100644--- a/tests/agent_core/agent/test_compaction.py+++ b/tests/agent_core/agent/test_compaction.py@@ -42,6 +42,7 @@ from core.agent_core.agent.models import ModelSelectionfrom core.agent_core.cancel import CancelTokenfrom core.agent_core.harness.context import (CHECKPOINT_REQUEST,+ CHECKPOINT_TRUNCATED,TOOL_TRUNCATED,ContextConfig,StateRequest,@@ -234,6 +235,18 @@ def growing(count: int, final: str = "done"):return [call("read", f"read-{index}", path=f"f{index}") for index in range(count)] + [[Done(assistant(final))]]+async def at_threshold(store, selection, threshold: int, sizes, **options) -> int:+ """A first run on ``selection`` of reads sized ``sizes`` that stays under ``threshold``; the tokens of an input+ that brings the next request to it exactly. No reply reports usage, so nothing anchors and the estimate is the+ request's ``tokens()`` (section 2)."""+ model = Model(reads(len(sizes), final="noted"))+ agent = make_agent(model, store=store, tools=[sized_reader(*sizes)], selection=selection, **options)+ events = await run(agent, row="history")+ assert events[-1].reason == "completed" and not model.checkpoint_requests+ last = model.requests[-1]+ return threshold - request_tokens(last.system, last.tools, project(await store.load("session")).messages)++async def test_a_threshold_checkpoint_forks_the_exact_prefix_and_leaves_checkpoint_and_tail():host = Host()model = Model(growing(4), [[TextDelta(0, "streamed checkpoint"), Done(assistant(CHECKPOINT))]])@@ -311,19 +324,37 @@ async def _wire(request):@pytest.mark.parametrize("protocol", ["anthropic", "openai_chat", "openai_responses"])-async def test_the_fork_is_a_byte_identical_prefix_on_every_protocol_wire(protocol):+ "limits,read,asked",+ [+ ((64_000, 32_000, 4_096), 6_000, 4_096), # O up to 64,000: the conversation's own output cap+ ((400_000, 272_000, 128_000), 33_000, 64_000), # T = 132,000; above 64,000 a checkpoint asks for 64,000+ ],+ ids=["O 4,096", "O 128,000"],+)+async def test_the_fork_is_a_byte_identical_prefix_on_every_protocol_wire(protocol, limits, read, asked):+ window, input_limit, output = limitsendpoint = ModelEndpoint(protocol, "http://model.invalid", "test-model", "", provider="test-provider")- capabilities = replace(SELECTION.capabilities, supports_reasoning=True, reasoning_efforts=("high",))+ capabilities = replace(+ SELECTION.capabilities,+ context_window=window,+ input_limit=input_limit,+ max_output_tokens=output,+ supports_reasoning=True,+ reasoning_efforts=("high",),+ )selection = ModelSelection(endpoint, capabilities)model = Model(growing(4), [[Done(assistant(CHECKPOINT))]])- agent = make_agent(model, tools=[reader(tokens(6_000))], selection=selection)+ agent = make_agent(model, tools=[reader(tokens(read))], selection=selection, max_tokens=output)agent.reasoning_effort = "high"await run(agent)previous, fork = model.requests[3], model.requests[4]assert is_checkpoint(fork) and fork.reasoning_effort == "high"+ assert (previous.max_tokens, fork.max_tokens) == (output, asked)previous_settings, previous_items = await _wire(previous)fork_settings, fork_items = await _wire(fork)- assert fork_settings == previous_settings # model, system, tools, tool choice, thinking, effort, output cap+ # Model, system, tools, tool choice, thinking, and effort are the conversation's; only the output cap may differ.+ assert fork_settings == (await _wire(replace(previous, max_tokens=asked)))[0]assert fork_items[: len(previous_items)] == previous_itemsassert len(fork_items) > len(previous_items)@@ -501,6 +532,44 @@ async def test_a_checkpoint_turn_reserves_room_for_every_result_of_its_batch():assert request_tokens(second.system, second.tools, second.messages) + 4_096 <= 32_000+#: A 128,000-token route answering up to 32,000 tokens: M = 8,000 and T = 88,000 (section 1).+WIDE = ModelSelection(+ ENDPOINT, replace(SELECTION.capabilities, context_window=128_000, input_limit=None, max_output_tokens=32_000)+)+++ "room,ran,last",+ [(4_000, ["peek"], CHECKPOINT_TRUNCATED.format(shown=3_000, total=10_000)), (3_999, [], BUDGET_USED)],+ ids=["room 4,000", "room 3,999"],+)+async def test_a_checkpoint_turn_at_T_reads_only_while_the_window_leaves_the_floor_after_its_output(room, ran, last):+ # At est = T on WIDE a checkpoint asks for all of O, 32,000, so the room its tools have,+ # L_in - est - min(64,000, O) - reserved, is about M less the checkpoint request and the response (section 6).+ # The response is sized to leave exactly ``room``: a read runs from 4,000 tokens on, its result cut to+ # room - 1,000, and one token less denies it.+ store = InMemoryTranscriptStore()+ size = await at_threshold(store, WIDE, 88_000, [20_000] * 4, max_tokens=32_000)++ def peek(request):+ read = ToolCallBlock("peek", "read", {"path": "f"}) # 4 tokens+ pad = 128_000 - request_tokens(request.system, request.tools, request.messages) - 32_000 - room - 4+ return [Done(AssistantMessage((text(tokens(pad)), read), assistant().origin, "tool_use"))]++ tool = reader(tokens(10_000))+ model = Model([[Done(assistant("done"))]], [peek, [Done(assistant(CHECKPOINT))]])+ agent = make_agent(model, store=store, tools=[tool], selection=WIDE, max_tokens=32_000)+ events = await run(agent, tokens(size), row="crossing")+ first, second = model.checkpoint_requests+ assert request_tokens(first.system, first.tools, first.messages[:-1]) == 88_000 # est = T+ assert (first.max_tokens, second.max_tokens) == (32_000, 32_000)+ assert [ctx.tool_call_id for _, ctx in tool.calls] == ran+ result = second.messages[-1]+ assert result.content[-1].text == last and message_tokens(result) <= room - 1_000+ assert [event.mode for event in events if isinstance(event, CompactionFinished)] == ["normal"]+ assert events[-1].reason == "completed"++class FailingHost(Host):def __init__(self, step: str) -> None:super().__init__()@@ -841,6 +910,55 @@ async def test_the_ladder_rolls_when_no_fork_can_take_the_whole_context():assert events[-1].reason == "completed"+#: A 1,000,000-token route answering up to 128,000 tokens: M = 30,000 and T = 842,000 (section 1).+MILLION = ModelSelection(+ ENDPOINT, replace(SELECTION.capabilities, context_window=1_000_000, input_limit=None, max_output_tokens=128_000)+)+++def _calls(request) -> list[str]:+ return [call.id for message in request.messages if isinstance(message, AssistantMessage) for call in message.tool_calls]+++async def test_a_threshold_checkpoint_on_a_1m_route_asks_for_64k_and_can_fit_at_T():+ store = InMemoryTranscriptStore()+ size = await at_threshold(store, MILLION, 842_000, [100_000] * 8, max_tokens=128_000)+ model = Model([[Done(assistant("done"))]], [[Done(assistant(CHECKPOINT))]])+ agent = make_agent(model, store=store, tools=[reader("")], selection=MILLION, max_tokens=128_000)+ events = await run(agent, tokens(size), row="crossing")+ (fork,) = model.checkpoint_requests+ # The request is at T exactly. Its fork, the whole context and the checkpoint request, asks for 64,000 and can+ # fit: T reserves O (section 1).+ assert request_tokens(fork.system, fork.tools, fork.messages[:-1]) == 842_000+ assert fork.max_tokens == 64_000+ assert request_tokens(fork.system, fork.tools, fork.messages) + 64_000 <= 1_000_000+ finished = [(event.reason, event.mode) for event in events if isinstance(event, CompactionFinished)]+ assert finished == [("threshold", "normal")]+ assert [request.max_tokens for request in model.conversation_requests] == [128_000] # the conversation asks for O+ assert events[-1].reason == "completed"+++async def test_the_overflow_ladder_on_a_1m_route_asks_for_64k_and_still_rolls_at_half_the_tokens():+ # The provider refuses a request under T (it counts more than the estimate), then the normal checkpoint over the+ # whole context too, so the ladder rolls (section 8 a, b). Each fork asks for 64,000 and can fit, and the rolling+ # one cuts nearest half the tokens, as with 16,000: the first four of the eight reads move out.+ model = Model(+ [*_long_context(8), [OVERFLOW], [Done(assistant("done"))]], [[OVERFLOW], [Done(assistant(CHECKPOINT))]]+ )+ agent = make_agent(model, tools=[reader(tokens(100_000))], selection=MILLION, max_tokens=128_000)+ events = await run(agent)+ assert [event.mode for event in events if isinstance(event, CompactionFinished)] == ["rolling"]+ normal, rolling = model.checkpoint_requests+ refused, sent = model.conversation_requests[-2:]+ assert normal.messages[:-1] == refused.messages and _calls(rolling) == ["r0", "r1", "r2", "r3"]+ for fork in (normal, rolling):+ assert fork.max_tokens == 64_000+ assert request_tokens(fork.system, fork.tools, fork.messages) + 64_000 <= 1_000_000+ assert _calls(sent) == ["r4", "r5", "r6", "r7"]+ assert {request.max_tokens for request in model.conversation_requests} == {128_000}+ assert events[-1].reason == "completed"++#: The reply of the E2E checkpoint turn that replaced a Session's history: a write the turn denied, then a meta note._E2E_WRITE = ToolCallBlock("toolu_write",diff --git a/tests/agent_core/agent/test_context.py b/tests/agent_core/agent/test_context.pyindex c111f2bcb..62ec98475 100644--- a/tests/agent_core/agent/test_context.py+++ b/tests/agent_core/agent/test_context.py@@ -185,22 +185,25 @@ def make_request(messages=(), *, system="system", tools=(), endpoint=ENDPOINT, m@pytest.mark.parametrize(- "window,input_limit,hop_output,configured,output,margin,threshold,keep",+ "window,input_limit,hop_output,configured,output,margin,threshold,keep,checkpoint",[- (200_000, None, 32_000, 64_000, 32_000, 8_000, 160_000, 20_000),- (1_000_000, None, 32_000, 32_000, 32_000, 30_000, 900_000, 20_000),- (None, None, None, 8_192, 8_192, 8_000, 111_808, 20_000), # unknown: W = 128,000, O = 8,192- (400_000, 272_000, 128_000, 128_000, 128_000, 12_000, 132_000, 20_000),- (32_000, None, 64_000, 4_096, 4_096, 4_000, 23_904, 5_976), # O is the request's, capped by the Agent- (8_000, None, 2_000, 2_000, 2_000, 1_000, 5_000, 1_250), # M is at most W / 8+ (200_000, None, 32_000, 64_000, 32_000, 8_000, 160_000, 20_000, 32_000), # a checkpoint asks for all of O+ (1_000_000, None, 32_000, 32_000, 32_000, 30_000, 900_000, 20_000, 32_000),+ (1_000_000, None, 128_000, 128_000, 128_000, 30_000, 842_000, 20_000, 64_000), # and at most 64,000+ (None, None, None, 8_192, 8_192, 8_000, 111_808, 20_000, 8_192), # unknown: W = 128,000, O = 8,192+ (400_000, 272_000, 128_000, 128_000, 128_000, 12_000, 132_000, 20_000, 64_000),+ (200_000, None, 16_000, 64_000, 16_000, 8_000, 176_000, 20_000, 16_000),+ (256_000, None, 64_000, 64_000, 64_000, 8_000, 184_000, 20_000, 64_000),+ (32_000, None, 64_000, 4_096, 4_096, 4_000, 23_904, 5_976, 4_096), # O is the request's, capped by the Agent+ (8_000, None, 2_000, 2_000, 2_000, 1_000, 5_000, 1_250, 2_000), # M is at most W / 8],)def test_limits_follow_the_frozen_formula_from_the_route_capabilities(- window, input_limit, hop_output, configured, output, margin, threshold, keep+ window, input_limit, hop_output, configured, output, margin, threshold, keep, checkpoint):capabilities = ModelCapabilities(context_window=window, input_limit=input_limit, max_output_tokens=hop_output)assert output_tokens(capabilities, configured) == output- assert checkpoint_max_tokens(capabilities, configured) == min(16_000, output)+ assert checkpoint_max_tokens(capabilities, configured) == checkpointplan = budget(make_request(system="", max_tokens=output), capabilities, transcript=())assert (plan.output, plan.margin, plan.threshold, plan.keep) == (output, margin, threshold, keep)limit = input_limit or window or 128_000