24 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
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
Botong
5f4d878735 fix: 将预读附件全文放在来源清单之前 (#3006)
* fix: 将预读附件全文放在来源清单之前

* fix(explore): tell the model the preloaded text needs no read_source

Without the note the model re-reads the preloaded lecture with read_source on
the upload turn, sending the whole text a second time.

---------

Co-authored-by: zszz3 <91608029+zszz3@users.noreply.github.com>
2026-11-28 13:51:00 +08:00
Botong
d1ca4f0b55 fix: 按请求统计附件预读的流式 Token 用量 (#3007) 2026-11-27 16:31:24 +08:00
AleFlyX
c26140abf3 fix(explore): bound the pre-pass connection as well as its reads
Opening the response stream was still unbounded, so a provider that hangs
while connecting parked the turn the same way a mid-stream stall did. The
answer loop bounds both halves (agent_loop.py:886 pairs the create() call with
the same _STREAM_IDLE_TIMEOUT_SECONDS the reader uses); mirror that here.
2026-11-11 18:33:25 +08:00
AleFlyX
13164c8200 fix(explore): bound the pre-pass stream so a stalled CLI cannot park a turn
ContextExplorer._call_llm iterated the provider stream with a bare
``async for``. A provider that connects and then stops yielding frames left
that await pending forever, so ``pre_loop`` never returned, the capability
never finished, and the turn stayed ``running``. The lease kept renewing, so
TurnRecoveryService saw a live owner and never claimed it; only an explicit
cancel freed the turn.

The answer loop already bounds its own reads (``_bounded_stream_chunks``,
90s), but the pre-pass runs before that loop starts, so it never inherited
the bound. Give it the same watchdog: on idle, raise
LLMProviderTransportError, which the existing ``except Exception`` around
``_run_loop`` turns into the single-pass briefing fallback.

Refs #2539 (the third attempt left ``running`` is a separate, pre-existing
bug, not the empty-error-message one this session's other PR fixes).
2026-11-11 18:24:57 +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
Bingxi Zhao (Frank)
8b73efbaeb Merge PR #1958: stabilize cached prefixes with bounded sources and complete summary accounting 2026-10-19 00:59:30 +08:00
Bingxi Zhao (Frank)
399297e7f0 feat: preserve TypeScript engine migration and workspace updates 2026-10-18 23:09:10 +08:00
zane-i
c04598bfae perf(explore-context): read the source ahead of the per-turn question
The exploring pre-pass re-read the same attached source on every turn -
39,627 characters, byte-identical across six turns - but put the
per-turn question first in the user message, so the longest shared
prefix with the previous request ended a handful of tokens in and the
whole re-read missed cache. That call ran 24,778 prompt tokens for
1,024 cached (4.1%), which is most of the misses in a turn.

Split the message the way the answer loop already splits everything
stable from everything per-turn: mode, manifest and the preloaded
source text go ahead of it and the question becomes the last message,
so the repeatable part is a byte-identical prefix across turns.

The preload stays capped (two sources, 120,000 characters) so a wide
manifest cannot spend the budget on its own; the document digest is
still the primary evidence path.

After both commits, on the same session: the exploration call runs
24,566 prompt tokens for 24,448 cached (99.5%), every call in the turn
reports first_change=append, and the turn reaches 94.0% cached, up
from 54.7%.
2026-10-13 23:47:21 +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
ZQR1101
f27f347713 fix(explore-context): keep reasoning on replayed rounds for thinking providers (#1400) (#1404)
Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>
2026-09-14 01:28:05 +08:00
Bingxi Zhao (Frank)
ed85fe9bc2 refactor(config): put every LLM budget in agents.yaml, one entry per stage
A capability that makes several different LLM calls cannot be described
by one max_tokens: the step emitting a whole JSON plan and the step
writing one paragraph need different room. `chat` has said so since it
grew `exploring`/`responding`. `question` and `research` said the same
thing in module constants instead, where no user could reach them.

The cost of that was not theoretical. `capabilities.question.max_tokens`
governed exactly one of question's six LLM calls — the follow-up agent —
while the pipeline's five steps used constants that ignored it. The plan
step's constant sat below the capability's own ceiling, which is how
#1318 shipped a step that could spend its whole allowance thinking and
emit zero templates without an error. `EXPLORE_FINISH_MAX_TOKENS` had
been dead since it was written.

Generalises the seam that already worked rather than adding a parallel
one: `get_chat_params` becomes `get_capability_params(capability)` over a
table of per-stage defaults, and `question`, `research` and
`explore_context` get tables of their own holding the numbers they
already ran on. The pipelines resolve once in `__init__` beside the
budget they already cached. Unknown keys are dropped, so a misspelled
stage cannot become a silent no-op that reads like a setting.

The rule this establishes, stated in the tables: **agents.yaml owns every
LLM budget** (temperature, max_tokens, per stage); **main.yaml owns
runtime behaviour** (iteration caps, timeouts, retry policy, modes). A
budget in main.yaml is a bug. `tool_summarizer.max_tokens` still reads
its main.yaml value first so nobody's existing configuration moves; new
installs reach the same number through agents.yaml like everything else.
GraphRAG's reachability probe is the one documented exemption — tuning it
could only make a health check lie.

Seeds are derived from the same tables the pipelines read, because two
lists of the same numbers is how a default and its seed drift apart —
the shape of #1316. Tests pin both halves: the shipped values, and that
every stage in code is present in the seeded file.

No behaviour change: every default is the constant it replaced.
6902 passed, 24 skipped.
2026-09-11 12:43:41 +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)
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
Bingxi Zhao (Frank)
1c918e87a8 Merge pull request #1032 from Zuan0/reading-chat-references
# Conflicts:
#	deeptutor/services/session/source_inventory.py
#	deeptutor/services/session/turn_runtime.py
#	tests/reading/test_turn_wiring.py
#	web/app/(workspace)/home/[[...sessionId]]/page.tsx
#	web/context/UnifiedChatContext.tsx
2026-08-31 19:19:38 +08:00
wayblink
2ba5e3aa5d feat(llm): support explicit OpenAI wire API selection 2026-08-29 15:02:31 +08:00
Benjamin
e3d8b05c0d feat(reading): add chat section references 2026-08-27 16:15:28 +08:00
Bingxi Zhao (Frank)
9e4233c3ae fix(chat): assign streamed tool-call ids instead of appending them
A router in front of an OpenAI-compatible provider re-sends the complete
`id` on every delta chunk rather than only on the first. The chat loop and
the explore capability appended it, so the id grew one copy per chunk —
#937 observed 551, 754, 870, 1566, 9715, 17864 and 47241 characters. Past
the provider's own 64-character ceiling every round died with HTTP 400
`Invalid 'messages[i].tool_calls[0].id': string too long`, the
forced-finish call died the same way, and the turn surfaced as "I could not
produce a useful response from the model output."

The report named one site and declared `name` correct as-is. There were two
sites, and both had the identical defect on `name`, which a repeat corrupts
into an unresolvable `toolnametoolnametoolname` — latent for that
reporter's gateway, fatal for any gateway that repeats the name.

Rather than restate the per-field rule a third and fourth time, converge
the three core-layer sites (chat loop, explore capability, labeled step)
onto one accumulator that states it once: `id` and `name` arrive whole and
are assigned, `arguments` arrives in fragments and is concatenated. That
rule is not new — it is what the services-layer provider's `_accum_tc` has
always done, which is the evidence that assigning `name` is safe across
every gateway users have configured. That accumulator stays where it is:
it reads deltas that may be plain dicts, so folding it in would widen the
blast radius without fixing anything.

Coercing a missing `index` to 0 also removes a latent crash in the labeled
step runner, where a `None` key made the final `sorted()` raise as soon as
one real index appeared.
2026-08-21 16:20:13 +08:00
Ching Wing Kwok
8297fc7b7e feat(provider): add codebuddy as a LLM provider (#780)
* feat: add codebuddy provider

* fix: treat codebuddy as login-backed provider

* feat: sync codebuddy account models

* fix: ignore no-key placeholder for codebuddy

* feat: add codebuddy web login

* fix: streamline codebuddy settings and latency

* fix: support switching codebuddy accounts

* fix: preserve codebuddy sessions and tool calls

* feat: use CodeBuddy HTTP provider over Agent SDK

Chat with CodeBuddy over plain HTTP by reusing the login state that the
IDE plugin / CLI stores on disk, instead of bundling the ~130MB Agent SDK.

- add codebuddy_http_provider (OpenAI-compatible /chat/completions on
  <endpoint>/v2) with codebuddy_credentials for local OAuth session reuse
- provider_factory picks HTTP transport whenever a login state or API key
  is available; Agent SDK stays as fallback for CLI agent features
- demote codebuddy-agent-sdk from core deps to optional codebuddy extra
- default model codebuddy/default -> codebuddy/hy3
- update auth card UX and locales for SDK-less sign-in flow

* chore: label codebuddy provider as codebuddy/workbuddy in the dashboard

* style: apply pre-commit formatting after upstream merge

* chore: capitalise codebuddy provider label as CodeBuddy/WorkBuddy

---------

Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
2026-08-13 00:02:42 +08:00
Bingxi Zhao (Frank)
fb3c568697 fix pageindex & minor bugs 2026-07-18 19:47:03 +08:00
Bingxi Zhao (Frank)
7ac3a3ba79 release: v1.4.6
A broad consolidation release across four product surfaces.

- Learning Space: Space becomes a learning dashboard; My Agents imports
  local Claude Code / Codex chat history into resumable agents (with an
  objective explore_context briefing so the tutor never role-plays the
  user); Memory is promoted to a top-level /memory route; Partner
  conversations flow into Memory; EduHub skills install inline.
- Knowledge Center: /knowledge rebuilt as a console with per-engine
  detail pages; GraphRAG / PageIndex / LightRAG engines join LlamaIndex;
  linked-KB read-only mounts; Obsidian live-vault capability.
- Settings: pluggable document parsing (MinerU / Docling / MarkItDown)
  with a content-addressed cache and MinerU cloud/local backends; voice
  TTS/STT; image & video generation; rebuilt settings navigation.
- Platform: per-user capability gating by assigned model; Solve rebuilt
  on the chat loop with a per-step gate and mid-run failure fallback;
  username login + inline errors; CLI skill publish/update; picker
  polish; math-before-citation render fix.

Docs were split out to a standalone site, so site/ is now landing-page
only. Bumps __version__ to 1.4.6 and adds assets/releases/ver1-4-6.md.

Folds in mypy fixes surfaced by pre-commit (mineru/local Path typing,
knowledge/manager no-redef, explore_context token kwargs, CLI
set_dist_tag capability probe) plus prettier reformatting of
previously-committed web files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 10:50:44 +08:00
Bingxi Zhao (Frank)
c9d387e2b6 super super great great update 2026-06-17 00:56:27 +08:00