48 Commits

Author SHA1 Message Date
greenhand-fjm
a943eb0b1e fix(runtime): add gateway cache breakpoints to the tool loops (#3115)
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
2026-12-01 21:38:18 +08:00
Shaikh Fardin
8a8cdf785f fix(llm): force temperature 1.0 for gpt-6 and drop reasoning_effort before tools (#2446)
* 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>
2026-12-01 19:27:05 +08:00
crimson-gzx
f56225f9b1 fix(llm): send session-scoped prompt_cache_key on Responses API requests (#2827)
Co-authored-by: Josh Guo <crimsongzx@gmail.com>
2026-12-01 14:13:16 +08:00
iQuantum
b5fb281a3e fix: default Anthropic to a Claude model Anthropic still serves (#2888)
AnthropicProvider and the agentic client's Anthropic adapter fell back to claude-sonnet-4-20250514, which Anthropic retired on 2026-06-15, so an Anthropic binding with no model failed with not_found_error. Both now use one DEFAULT_ANTHROPIC_MODEL constant, claude-sonnet-5-5.
2026-12-01 11:20:50 +08:00
lipeh1
803c4a4a35 fix: preserve empty reasoning in quiz tool continuations (#2800)
* fix: preserve empty reasoning in quiz tool continuations

* test: cover empty reasoning in assistant tool messages

---------

Co-authored-by: lipeih <lipeihan@eazytec.com>
2026-11-28 18:22:57 +08:00
wojiecihuo
651a616b02 fix(visualize): raise the budget to 32k, cap it to the model, and retry without thinking (#3019)
* 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.
2026-11-27 22:26:59 +08:00
Bingxi Zhao (Frank)
47e4c33c90 Merge PR #2493: fix(runtime): separate indexless streamed tool calls 2026-11-14 23:00:46 +08:00
Bingxi Zhao (Frank)
39239ac1a8 Merge PR #2624: fix: sanitize raw agentic chat replay messages 2026-11-14 22:58:48 +08:00
Bingxi Zhao (Frank)
ebd0f11083 Merge PR #2605: fix(mastery): let a new reply supersede an ungraded clarification 2026-11-14 22:58:03 +08:00
Bingxi Zhao (Frank)
675f44690d Merge PR #2630: fix: time out stalled labeled-step provider streams 2026-11-14 22:52:55 +08:00
stefanielizeth73-art
5ecf3d6b84 fix: make Python provider stream termination persistent 2026-11-13 22:54:43 +08:00
Steven Huang
46a1eb1b91 fix: bound stalled labeled-step provider calls 2026-11-11 23:19:30 +08:00
Adithya
9d8742e994 fix: sanitize raw agentic chat replay messages 2026-11-11 14:07:44 +05:30
AleFlyX
1e86d251bd fix(dispatch): reserve _working_brief, an injected flag the list missed
`mastery_status` receives `_working_brief` from the mastery loop
(capabilities/mastery/loop.py:436) and reads it as a trusted switch for
whether to project the working brief (capabilities/mastery/tools.py:915).
It was not in RESERVED_ARGUMENT_NAMES, so a model could send
`_working_brief: false` and the tool would honour it.

Same class as `_learner_message`: an injected name treated as fact while
the model can write it. Caught on a later audit pass rather than by any
test, which is the argument for the follow-up in #2610.
2026-11-11 08:49:06 +08:00
AleFlyX
636f522b43 fix(dispatch): withhold the arguments the runtime owns
`_`-prefixed names reach tools as provenance: `_learner_message` is the
learner's own words, `_sandbox_mounts` is where the turn may write,
`_turn_id` is which turn produced the call. A few of them gate credit or
sandbox access.

Nothing enforced that on the way in. A model emits arbitrary JSON and the
dispatch path never rejected a name it did not expect, so a model could
write `_learner_message` itself and have a built-in tool believe it. That
is how `mastery_grade` came to accept a model-authored answer as grounds
to overwrite a committed learner answer (#2595).

Withhold a fixed list of the names the runtime injects, at bind time,
before the augmenter runs. Adapter arguments outside that list are left
alone, so an MCP server publishing `_id` keeps working.

Also record the filtered arguments rather than the raw JSON. `_rebind`
replays the recording straight into the augmenter, so keeping the raw one
let any round containing a rebinding tool — `ask_user` and
`workspace_export` always qualify — re-admit a forged name the first bind
had already dropped.
2026-11-11 08:28:10 +08:00
KaiChan
fefa6c0437 fix(runtime): isolate indexless streamed tool calls 2026-11-06 19:16:02 +08:00
Bingxi Zhao (Frank)
7948deb5f5 Merge #2349 from rudycelekli 2026-11-06 01:56:24 +08:00
Rudy Celekli
d516269b43 fix(runtime): apply the tool-call id fallback in run_labeled_step
run_labeled_step returned tool calls via the accumulator's raw ordered()
view, which keeps id="" when a provider streams a tool call without an id
delta. The sibling consumers use collected(), which applies the positional
id and arguments fallbacks. Switch to collected() so a tool call made by an
id-less gateway is still correlatable and passes the non-empty-id schema.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-02 01:14:01 -05:00
yert
4e113d0e4f fix(llm): preserve custom headers in Codex OAuth requests 2026-11-02 04:07:25 +00:00
quocldce-sys
b16b187244 feat: add Claude Code provider backed by the Claude Agent SDK
Adds a `claude_code` LLM provider that runs turns through the local Claude
Code CLI via `claude-agent-sdk`, so DeepTutor can use the account signed in
with `claude /login` (including a Claude subscription) without an Anthropic
API key.

- One long-lived Claude Code process per DeepTutor session, mirroring the
  CodeBuddy SDK provider's owner-task pattern.
- Claude Code's built-in tools, settings, CLAUDE.md and hooks are disabled;
  DeepTutor tools are exposed through an in-process SDK MCP server and tool
  calls are returned to DeepTutor's dispatcher.
- Tool turns end via max_turns=1 and are drained instead of interrupted, so
  the transcript does not record an interrupted request.
- System messages become Claude's real system prompt.
- Optional extra: `pip install deeptutor[claude-code]`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 15:07:04 +07:00
Bingxi Zhao (Frank)
d23206ebc0 Merge remote-tracking branch 'origin/dev' into HEAD 2026-10-27 21:42:52 +08:00
Bingxi Zhao (Frank)
6bbcc00c55 Merge dev into preview, preserving preview features
Integrate dev fixes with preview's Python/TypeScript schedulers, chat queue, learning navigation, and live turn persistence.
2026-10-27 01:16:58 +08:00
octo-patch
53d19a39f0 feat: recommend MiniMax Flash and map current reasoning controls 2026-10-20 16:31:03 +08:00
Bingxi Zhao (Frank)
9aae961412 Merge PR #1957: separate private source evidence from explicit public presentation 2026-10-19 00:53:44 +08:00
Bingxi Zhao (Frank)
399297e7f0 feat: preserve TypeScript engine migration and workspace updates 2026-10-18 23:09:10 +08:00
yepyhun
755686264d fix(mastery): separate source inspection from assessment delivery 2026-10-13 13:49:35 +02:00
yepyhun
e648442a87 fix(agentic): accept explicitly supplied schema-valid nulls 2026-10-13 00:34:55 +02:00
Bingxi Zhao (Frank)
2350ea2dba feat(mastery): complete source-grounded visual practice and evidence (#1611)
Bind original visual sources and keys to supported tasks; verify accepted model pixels, preserve cues/assistance and canonical attempts, keep uncertainty ungraded, expose challenge/repair, and separate required visual evidence from generic text mastery.
2026-10-08 05:25:05 +08:00
Bingxi Zhao (Frank)
081c9e6d98 fix(chat): bound cold-start stream waits and avoid nested retries (#1421) 2026-10-08 00:00:30 +08:00
Bingxi Zhao (Frank)
2ccd8a75fb fix(mastery): deliver retrieved source images through the active agent loop (#1611) 2026-10-07 23:17:15 +08:00
Bingxi Zhao (Frank)
bb39f0d911 fix(rag): bound visual manifests and per-turn image context 2026-09-27 11:08:44 +08:00
Bingxi Zhao (Frank)
0bb753868e fix(rag): keep visual tool replies valid and pin asset scope 2026-09-27 11:03:10 +08:00
Bingxi Zhao (Frank)
5e7be659a2 Preserve retrieved source visuals for vision answers 2026-09-27 10:57:00 +08:00
Bingxi Zhao (Frank)
ffbe0a541b fix(agentic): replay reasoning in repair and report retries 2026-09-23 12:30:01 +08:00
Bingxi Zhao
d43e24a048 Merge pull request #1499 from AoHanBei/fix/llm-key-rotation-exhaust-pool
fix(llm): try every API key after rate limits
2026-09-23 10:24:42 +08:00
Frank_zhu
6fbed6c28e fix(research): recover report labels on finished reply (#1514)
Keep the streaming 64-char probe strict, then re-read a finished report
reply so an unclosed/over-wide fence or a matching ## n. heading no
longer kills the turn. Raise report_section max_tokens to 12000 and
turn reasoning off for report prose so first attempts stop starving.
2026-09-21 10:27:09 +08:00
Bingxi Zhao (Frank)
da856ad670 release: v1.6.9
Ship folder-based workspaces and data migration, daily practice, redesigned
provider and model settings, and streaming conversation improvements.
Synchronize README translations and document the archive/permanent-delete
upgrade behavior in assets/releases/ver1-6-9.md.

Reduce initial JavaScript by deduplicating English resources and loading
animation features after hydration. Keep the existing route size budgets.
Update regression fixtures and browser audits for scoped URLs and the new
settings and learning interfaces.
2026-09-21 02:30:40 +08:00
AoHanBei
e8842ff114 fix(llm): try every API key after rate limits 2026-09-16 22:15:06 +08:00
Gao Chenkai
3192757d45 fix: handle DeepSeek reasoning budget exhaustion (#1331)
* fix: handle DeepSeek reasoning budget exhaustion

* style: satisfy ruff format, the one thing CI was red on

`ruff format --check` on agent_loop.py, the Responses parser and the test
file that came with them. No behaviour change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 01:43:40 +08:00
Bingxi Zhao (Frank)
4e2f088548 merge: bring 19 reviewed PRs from origin/dev into dev
Resolves two collisions with the fixes committed locally tonight:

* book/blocks/_llm_writer.py — #1366 threaded a reasoning_effort
  through llm_json while 5ac8e2c9 replaced this file's private
  _json_has_expected with the shared json_payload_is_usable.
  Taking either side alone breaks: origin/dev's calls a helper that no
  longer exists, ours drops the caller's explicit effort. Kept the shared
  helper and the threading, and the retry now reuses an explicitly given
  effort so a round deliberately run without thinking cannot re-enable it.

* runtime/agentic/tool_dispatch.py — #1357 added tool_timeout /
  tool_max_retries to execute_tool_call in the same parameter list where
  4e816d79 renamed unknown_error_message_factory (tool) to
  tool_error_message_factory (tool, error). Both are needed: the
  dispatcher already passes the timeout pair through, and every call site
  in the tree now uses the renamed factory.
2026-09-10 23:52:04 +08:00
evan188199-tech
30e0f7c3a2 fix(research): enforce tool timeout and retry policy (#1357)
Co-authored-by: XZH <cto@xzh.ai>
2026-09-10 23:45:30 +08:00
AoHanBei
eb49228d8f fix(chat): recover hallucinated PDF tool calls for attached sources (#1333)
* fix(chat): recover PDF source tool calls

* fix(runtime): preserve tool alias defaults
2026-09-10 23:44:31 +08:00
Bingxi Zhao (Frank)
0027051b32 fix(question): tell a starved plan apart from an empty one, and retry it
Ask for a quiz with a reasoning model and sometimes one question arrives,
sometimes none, with nothing in the UI and one `LLM returned empty
response` in the log (#1318). Reproduced on both a 35B llama.cpp build
and a 27B vLLM one, so it is not a model or a backend.

The plan step is a single labeled call that must emit a whole JSON object
of templates, and it had the tightest budget in the file — 2000, below
even the 4096 the `question` capability ships with. A reasoning model
pays for its hidden tokens out of that same allowance, so on a rich
exploration trace it can spend the lot before the label. `PLAN_MAX_TOKENS`
is now 6000: the plan itself is a few hundred tokens and the rest is room
to think in.

A bigger number is not the fix, because no number is large enough for
every model. The fix is that the step now says what happened.
`run_labeled_step` strips the scratchpad on the way out — deliberately,
so a truncated one never reaches a reader — which left "starved
mid-thought" and "the model genuinely said nothing" as the same empty
string. `_parse_plan` read it as a plan of zero templates and phase 3,
which iterates them, emitted no questions and no error.

`LabeledStepResult.reasoning_only` separates them: no label ever arrived,
no text, no tool calls, and the model demonstrably did reason (inline
`<think>` or the provider's own channel). Tool calls disqualify it — that
round acted, it just did not narrate, and re-asking would repeat the
call. The plan step spends the signal on one more attempt with thinking
turned down, which is the same escape hatch Book already uses; its
`RETRY_REASONING_EFFORT` moved to `services/llm/reasoning_params` so the
choice of level, and why it is "low" and not "minimal", is stated once.

Every labeled step in the codebase now carries the flag, so `EXPLORE`,
`QUIZ` and `REPAIR` — which share the same exposure on smaller budgets —
are at least diagnosable. Whether an under-filled plan should warn or
fail is a separate question and is deliberately left where it was.
2026-09-10 23:05:52 +08:00
Bingxi Zhao (Frank)
4e816d7933 fix(tools): tell the model why a tool failed, not that it failed
Stop the Ollama a vector KB embeds against, ask a question, and the model
is told "An unknown error occurred while executing rag." The adapter had
already written the answer — `Cannot connect to Ollama at
http://localhost:11434. Make sure Ollama is running. Start it with:
ollama serve` — and the dispatcher was holding it (#1356).

`unknown_error_message_factory` took the tool name and nothing else, so
no caller could have done better. Four capabilities each wrote their own
message from that one argument and three of them called the result
unknown; the fourth, pageindex, restated the dispatcher's own default
minus the cause. The name was the bug: it presumed a cause the runtime
always had.

It is now `ToolErrorMessageFactory`, `(tool, cause) -> str`, and the key
plus the English wording live once in `tool_error_message_factory`, which
each capability wraps around its own `_t`. Capabilities keep their
translations and can no longer keep the cause out of them. pageindex
passes nothing and takes the default. A bundle predating the new
`notices.tool_error` key falls back to English rather than to silence
about what went wrong, which is the reason the fallback carries the cause
too.

This is the same shape as read_skill answering "skill not found" when the
skill resolved and only the file was missing (#1347): a failure the
caller cannot see has no way out, and the model spends its rounds
inventing one.

The regression test is the reporter's turn — a `rag` call raising the
real adapter error — and asserts the endpoint and the remediation reach
the role=tool message.
2026-09-10 23:00:11 +08:00
Bingxi Zhao (Frank)
5f7e165161 fix(llm): carry a round's reasoning through the shared agentic loop
DeepSeek's thinking models reject a continuation whose history has lost the
previous assistant turn's reasoning:

    The `reasoning_content` in the thinking mode must be passed back to the API.

Chat's loop has replayed it since #1058. The shared `runtime/agentic` loop —
the one quiz, research, PageIndex and explore_context all run on — never
did. `LabeledStepResult` had no field for it; the stream reader pulled
`reasoning_content` off each delta, pushed it to the trace UI for display,
and dropped it. All three assistant rebuild sites therefore emitted
reasoning-less turns. Round one cannot fail (system + user only); round two
always did, which is why this reads as "quiz generation failed".

The message builder's own docstring said as much: "The provider has always
known how to read this field off a message — nothing ever wrote it."

v1.6.5 made it visible rather than causing it. `deepseek-v4-flash` was in
`_THINKING_DISABLED_BY_DEFAULT_MODELS` in v1.6.4 and the list was emptied,
so the model now thinks by default — correctly, since suppressing reasoning
to dodge this cost every flash user their reasoning stream. `deepseek-v4-pro`
and `deepseek-reasoner` are sent `thinking: enabled` by our own code and were
already broken in v1.6.4. Re-adding flash to that list would hide it again
and still leave those two broken, so this fixes the replay instead.

The reasoning is accumulated for every label, not only the pre-label prelude
the trace happens to render — whether it was displayed is a display question,
and the provider wants the whole round back. Anthropic's signed thinking
blocks are read off `provider_specific_fields`, where the adapter puts them,
because a signature cannot be rebuilt from text. `_append_repair_messages`
now takes the step rather than its text, since a repair round is still a
round. Rounds with no reasoning append no field, so ordinary models see a
byte-identical history.

Deliberately NOT setting `_provider_response_state` alongside: the shared
loop posts its messages straight into `chat.completions.create` on what is
usually a raw AsyncOpenAI client, and the private-key stripping lives inside
`OpenAICompatProvider._sanitize_messages` — so it would be serialized into
the request body for every model off the adapter route.

Also reorders `_classify_failure`: a provider quoting the field it objected
to was landing in `prompt_leak`, which is not retryable and told the user the
model had leaked a prompt. `"prompt" in lower` goes with it — it matches
`prompt_tokens`.

Still open: `_sanitize_messages(responses_api=True)` ignores `reasoning_content`
entirely, so a surface that mounts native web search (which routes DeepSeek
to the Responses API) is not covered by this and falls back to Chat
Completions. The book quiz mounts no tools, so it is not that surface.
2026-09-08 00:52:57 +08:00
Bingxi Zhao (Frank)
04040a2c06 release: v1.6.5
Ship a content workspace you choose, one exec tool for every language,
Mastery Path modes that gate its tools, and Settings that grades
readiness instead of listing faults.

Release notes: assets/releases/ver1-6-5.md
2026-09-06 13:46:29 +08:00
Bingxi Zhao (Frank)
93df3d48b7 release: v1.6.4
Ship lighter isolated runtimes, richer Books and Mastery flows,
Reading/session polish, and explicit model API capabilities.

Release notes: assets/releases/ver1-6-4.md
2026-09-03 01:38:54 +08:00
Bingxi Zhao (Frank)
02ba56793e chore: checkpoint backend stabilization workspace 2026-09-01 21:28:15 +08:00