The research, question and page-index loops (run_labeled_step) and the context explorer call the SDK client directly, so an anthropic/ model on OpenRouter got no cache_control breakpoint and cached nothing on any round. Move the chat loop's check into runtime/agentic/prompt_caching.py and apply it in all three places. Refs #3087.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J2vr2J41oqPYhmpP8CzSJA
* fix(llm): force temperature 1.0 for gpt-6 and treat reasoning_effort+tools rejection as tool-schema unsupported
* fix(llm): drop reasoning_effort instead of tools when combined request is rejected
---------
Co-authored-by: Shaikh Fardin <152140625+Fardin7798@users.noreply.github.com>
Co-authored-by: OrdoAbChao7 <2369980241@qq.com>
CallToolTool answered every unforwarded call with "load it first". That
was wrong for a tool already in tools[] (an MCP tool, a built-in) and for
malformed arguments, and for the former it sent the model round in a
loop. DeferredToolLoader.proxy_refusal now names the reason (missing
name, call_tool itself, already in the tool list, proxy off, unknown,
not loaded) and proxy_arguments checks the arguments: an object, or a
string holding valid JSON for one; anything else is refused. The
pipeline's _resolve_proxied_tool_calls and CallToolTool both go through
proxy_call_refusal, so the message matches the decision.
Setup tools loaded through load_tools are proxied. Opening setup mode
later left them proxied: not in tools[], no rules (already loaded), and
a note that never mentioned call_tool. An opened mode's tools are now
made native, like mastery's outline tools; a setup turn whose tools are
still proxied gets a hint to reach them through call_tool.
Also: call_tool is mounted only when the loader has built-in/capability
tools to proxy; its manifest order no longer duplicates load_tools'; a
forwarded call without an id is not marked for renaming.
Refs #2972
load_tools appended the loaded schema to the end of tools[]. tools[] is the
first thing in the provider's prompt-cache key, so the next request of the
same turn re-processed the system prompt and the whole history.
When the turn mounts the new call_tool builtin, load_tools now returns the
loaded tools' definitions in its result and leaves tools[] alone; the loop
forwards each call_tool call to the named tool before dispatch, so the tool
runs with its own argument checks, injected kwargs and trace, while the
history keeps the model's own call. Tools loaded this way stay proxied for
the session (loaded_tools.json gains proxied_tools). Runtime loads that must
land in tools[] pass native=True; the TypeScript engine keeps the old
behaviour.
The setup protocol (confirm with ask_user before apply_setting, never
handle secrets, ...) reached the model only in the load_tools result or
the turn that opened setup mode. Once history snipping or summarisation
dropped that message, the setup tools stayed in tools[] without their
rules. A setup turn (explicit mode or an intent message) whose capability
already has tools loaded now gets the protocol repeated in its turn note,
and the intent wording says the tools are already loaded.
A partner turn refuses every setup write (setup/access.py can_write), so
the setup tools are no longer listed under Extended Tools or pointed at
by the turn note there. Non-admin users keep them: personal preferences
are still theirs to change.
Also correct the comment about when set_deferral_available runs:
is_active is already asked by the exclusive-capability checks before it.
Refs #2972
The deferred-tool notes imported deeptutor.tools.research_tools on every
turn that had local deferred tools, so a minimal install (setup tools
deferred, no research module) failed the chat turn with
ModuleNotFoundError. Import it only when the research module is enabled,
as the rest of the pipeline already does.
Refs #2972
SetupCapability.turn_note and the legacy setup system block now read the
header, gap-list heading, intro section and explicit/intent/intro leads from
capabilities/setup/prompts/{en,zh}/notes.yaml (overridable under
setup.notes.<key>); the intro section gains a Chinese version. The Extended
Tools manifest header no longer says every entry is supplied by an external
service, since built-in setup and research tools are listed there too.
json-repair was closing the partial arguments and the tool then ran, so a
write could persist half a value and report success. A truncated round now
keeps the text and records one not-executed result per call.
Fixes#2713
Signed-off-by: fanjiahe <fanjiahe@mail.ustc.edu.cn>
Co-authored-by: Cursor <cursoragent@cursor.com>
When a tools snapshot goes away (a session stored before native requests
dropped the text manifest, or the turn after a schema-rejection fallback),
the generic retraction said the section is now empty, which reads as "no
tools" while the request carries native schemas. The tools snapshot now
gets its own retraction text, in the Python loop and the TypeScript engine.
Refs #2973
The provider-side fill only adds "" once another round in the request
already carries reasoning. A thinking model that calls a tool with no
reasoning on the very first round of a turn (or on every round so far)
still got the field dropped, and DeepSeek rejected the next request.
The stream says whether the model is thinking: DeepSeek in thinking
mode sends reasoning_content (as "" when it has nothing), and never
sends the key with thinking disabled. Record that on LLMCallResult and
send the tool round back with "" when the field was declared. Providers
that never send the field get nothing added.
Refs #2976
The runtime-snapshot comment had drifted above TOOL_MANIFEST_SNAPSHOT
instead of RUNTIME_BLOCK_NAMES. _restore_tool_manifest's docstring said a
native request never carries a tools snapshot and that the next turn keeps
it current; replayed history can carry one, and it is kept only while the
previous turn on the same route recorded a rejection.
Refs #2973
* fix: keep mastery prompt prefix stable across mode switches
* fix: load the outline tools together when a turn switches to outline
A study turn that switched to outline loaded mastery_build alone through load_tools; the next turn, in outline mode, mounts every outline tool eagerly, so its tools[] carried one schema more than the previous request and missed the whole cached prefix. The mode switch now loads the outline group into the live request at once. Refs #2922
* fix: close loaded tool schemas the same way as mounted ones
Mounted schemas go out with additionalProperties: false; a tool loaded through load_tools did not, so the same tool had two byte forms in tools[]. A tool that moved between mounted and loaded across turns (mastery_build/mastery_revise after an outline->study switch) rewrote the start of the cached prefix. Refs #2922
* fix: keep the outline tools on the deferred loader in outline mode too
Outline mode mounted mastery_build/mastery_revise eagerly and skipped the
loader, while study and review reached them through it. On an install with
no other deferred tool that also dropped load_tools on outline turns, so
tools[] changed in both directions around every switch. Refs #2922
* fix: mount mastery navigation from the first mastery turn
The first mastery turn usually creates the topic; navigation mounted only
once a topic existed, so the second turn's tools[] grew by three schemas and
missed the whole cached prefix. Refs #2922
* fix: send only the current mastery mode's rules, as a runtime snapshot
The system prompt carried all three mode sections so a mode switch would
not rewrite the cached prefix, but that showed the model three conflicting
rule sets and relied on a one-line snapshot to pick one. Keep only a short
frame in the system prompt and send the current mode's own section inside
the mastery_session_mode snapshot, which is appended only when the mode
changes.
Refs #2922
* fix: keep capability tools recorded by another turn in the session's loaded set
A mastery turn records its outline tools (mastery_build, mastery_revise) in
the session's loaded_tools.json so a later study turn keeps the same tools[].
A plain chat turn of the same session builds a provider loader without
capability names; with an unrestricted caller it treated those names as
stale and persisted the set without them, so the next mastery turn mounted
fewer tools and re-paid the cached prefix.
DeferredToolLoader now keeps names it cannot serve (registered tools it does
not own, or names outside its allowlist) as retained: never mounted or
reported, but written back with the session state. Only names whose tool is
gone from the registry are dropped.
Refs #2922
* fix(book): retry an interactive page with thinking off when it runs out of room
deepseek-flash thinks by default and can spend the whole 16000-token
visualize budget on reasoning, so a book interactive block came back with
no code. When the page is empty or cut off before </html>, ask once more
with thinking turned off (thinking_off_effort_for) before failing. If that
still runs out of room, the error names the budget sent to the model and
the settings that change it.
The shipped default stays at 16000: the budget is shared by every visualize
caller, and 32768 breaks models with a lower output cap (#3018).
Refs #3011
* fix(llm): raise the visualize budget to 32k and cap each request to the model
A thinking model can spend 16k tokens before it writes any code, so the
visualize default is now 32768. Sent unchanged that would be rejected by
models whose output stops lower (gpt-4o and gpt-4o-mini at 16384) and could
overflow a small local context window, so every request now carries
min(budget, the model's known output limit, half the configured context
window). The cap lives in get_token_limit_kwargs, so it applies to every
caller; BaseAgent and the agentic loop pass the configured window.
Move the context-full finish reason into the shared LLM protocol and add English and Chinese notices; test both localized warnings and provider mappings (186 passed).
The chat loop replays the workspace note as the "workspace" runtime
snapshot, which lives inside the cached prompt prefix. The note embedded
workspace.logical_output_dir — outputs/chat/<session>/<turn>/ — so its
bytes changed on every turn: the snapshot-replace logic cut the old copy
out of the middle of the rebuilt history and appended a fresh one,
invalidating the provider prompt cache on every multi-turn request
(cached-token hit rate <1%; single-turn tool loops were unaffected).
- workspace_system_note(state_turn_path=False) keeps the replayed chat
snapshot byte-identical for the whole session and points at the current
user message for the exact path instead.
- new workspace_turn_note() delivers the per-turn output folder in the
trailing user message — fresh bytes each turn, so cache-safe by
construction.
- phase-built prompts (question/research pipelines) keep embedding the
exact path via the default state_turn_path=True; their behavior is
unchanged.
- model-history reconstruction keeps an exact prefix once snapshots are
stable; new multi-turn replay tests assert byte-level prefix extension
across three consecutive turns, plus the second factor named in the
issue turns out to be a consequence of the turn-scoped snapshot and
needs no separate change.
Verified: tests/agents/chat 273 passed; tests/capabilities 739 passed;
tests/services/workspace+session 709 passed (8 failures pre-exist on the
clean tree and are unrelated); remaining tests/agents failures pre-exist.
Exclusive knowledge capabilities (obsidian, marginnote4, subagent) dropped
the whole chat built-in surface, including web_search (still shown on in
settings) and the always-on web_fetch. Add a coexisting_tools declaration
to KnowledgeCapability (default empty; the product KBs declare the web
pair), honoured in compose_enabled_tools' exclusive branch under each
tool's usual gate (user toggle / always-on / conditional flag) and the
partner builtin_whitelist, mirroring the #650 KB coexistence. The
capability's system prompt now also names what actually mounted via
coexisting_tools_block, so the model no longer disclaims mounted tools.
Fixes#2612
Signed-off-by: evan188199-tech <238371241+evan188199-tech@users.noreply.github.com>
model_context_window_exceeded mapped to "length", which the agent loop
treats as an output cap and answers with continue_truncated, resending the
same full history. Report it as context_length_exceeded instead, and have
the loop end the round with a notice.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Carry the #958 service-layer reasoning_effort override through the whole
turn contract: the core TurnRequest LLMSelection accepts the field
(validated against VALID_REASONING_EFFORTS, old two-ID payloads unchanged),
the generated web contracts are regenerated, and ChatStateAdapter's
asLLMSelection restores a legal override instead of dropping it.
The composer gains a selector beside the model picker, offering only the
levels the selected model supports (live supported_reasoning_efforts or
the provider/model tables) narrowed to the wire vocabulary, hidden when
the model has none. The choice persists on the conversation's
llm_selection, so the next send uses it without a backend restart and
other conversations are unaffected; switching models resets the override.
Precedence stays conversation override -> profile/model default ->
provider default, and the context-budget readout reports the effective
effort beside the model when one was used.
Keep learner-facing explanations visible across finish checks, persistence, and replay. Remove mastery prose heuristics and prioritize learner objections.
Coordinate service shutdown and descendant cleanup, and preserve video lesson identity and playable results across chat completion and reload.
Remove course pages, APIs and the course_study capability. Add anchored note
threads and reviewed learning-block generation, queued and withdrawable chat
messages, quote attachments, side chats, and the calendar/favorites/navigation
updates.
Keep preview's existing backend architecture. Wire the new features through
its Python application and existing chat engine, retain legacy selected-text
requests, persist mid-turn messages in replay, and restore note context when
regenerating. Leave stored user data intact.
Validate frontend contracts, dependency boundaries, types, 1290 node tests,
840 rendered tests, lint, localization and the production build. Exercise
session/notes/API regressions, 53 chat-engine tests and 20 Python/native
integration tests with isolated runtime data.