The quiz panel sends per_type_counts (e.g. choice=3, fill_in_blank=2)
and the planner prompt asks for that exact mix, but _parse_plan only
enforced the allowed types and difficulty. A planner that returned five
choice templates produced a five-choice quiz.
Retype the surplus templates to the types that are still short, keeping
topics, order and difficulty.
Two assertions could not fail: "report" in the research user message
matched other words, and the question number check passed for any digit
near the template heading. They now look for the rendered mode
(``report``) and for "#n of 3" / "第 n/3 道". The research forced-finish
docstring said tool_choice="none" while the test asserts "auto".
Refs #2974
The forced FINISH round keeps the loop's tools, so the model may still
call one. That call is not run, and the assistant turn added before the
repair note had empty content plus the round's reasoning or thinking
blocks. Anthropic rejects an empty text block, so the turn now carries a
short note ("Tool call not run: this round must finish.") when the round
returned tool calls and no text. Rounds that returned text are unchanged.
Refs #2974
The research block already tests the case where the model calls a tool
in the forced FINISH round; deep_question's _force_finish had no such
test. The new test checks that both requests carry the tools, the call
is not dispatched (no tool or tool_calls messages) and the repair note
is appended before the second attempt.
Refs #2974
When a research block or a deep_question explore/quiz loop runs out of
rounds, the forced FINISH request was sent with no tools. Removing the
tools changes the first bytes of the request, so none of the block's
history is served from the provider cache. In a real deep_research run a
block's forced finish paid 28.6k and 279.8k uncached tokens.
The forced rounds now send the loop's tool schemas unchanged; the prompt
already tells the model to stop calling tools. tool_choice="none" is not
used because DeepSeek renders it like no tools (replayed: 1,152 cached
tokens with "none" or no tools, 14,976 with the tools left as they were).
A tool call in a forced round is not dispatched; it fails the attempt and
gets the existing repair note.
Refs #2974
The tool-result summarizer always sent stream_options and, on providers
that reject it, only logged a warning and dropped the summary. Retry once
without stream_options, as agent_loop and labeled_step already do.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
_parse_quiz_payload swapped the reply for the body of its first ``` fence
before parsing anything. The quiz FINISH schema asks for a bare JSON object
whose `question` is Markdown and whose coding answer is code, so that fence
is usually a code sample inside a string value. The parser decoded the
sample instead, got {}, and the question was lost: after one repair round
that hit the same parser, the learner got "[Generation failed] <topic>"
with N/A as the answer and the explanation.
Take a reply that is one complete JSON object as it is first, the order
parse_json_response already uses for the same case (#825). Wrapped replies
still go through the fence; when a fence inside a field cuts the wrapper's
body short, the first object in the whole reply is used instead.
The quiz step asks for one JSON object out of a budget that reasoning
tokens also draw on, so a thinking model can spend the whole budget
thinking and leave nothing to parse. The repair round that exists to
rescue it is itself an LLM round and starves the same way, with nothing
after it left to ask again -- the learner got a "[Generation failed]"
placeholder, which is #1508's probabilistic missing question. Give that
round the retry _plan already has.
The envelope then hid the failure: `successful` counted
metadata["error"], a key the pipeline never writes, so an
all-placeholder quiz reported success=True / failed=0 to book blocks and
exam_mimic. Count `issues` instead -- it is recomputed after the repair
attempt, so what survives it is the question the learner actually got.
Rebased onto dev, where c31bed8a now gives a planner that spent its budget
reasoning a second pass at lower effort. "The plan came back empty" is
therefore the state *after* a retry, not the first thing that happens, and
this narrows accordingly.
The two outcomes are not the same outcome. No templates is not a small quiz,
it is no quiz — phase 3 iterates the templates, which is how #1318 shipped a
zero-question result with no error anywhere. Fewer templates than asked is a
smaller quiz, and three real questions beat a failure, so that case keeps the
warning and proceeds. `_parse_plan` already caps the other direction, so
"more than asked" cannot reach here.
Two notices rather than one key doing both jobs: `plan_unusable` for the
failure, `plan_count_mismatch` keeping its "proceeding with what we have".
`test_plan_still_empty_after_the_retry_keeps_the_existing_behaviour` was
written as a placeholder naming this PR, pinning that the retry had not
quietly answered the question. It has an answer now, so it asserts it.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.
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.
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
Trailing prose that contains braces made the greedy brace slice invalid, so
valid quiz payloads were dropped to {}. Decode the first JSON object instead.
Replaces three bespoke multi-agent pipelines with orchestrators on top
of a shared agentic-engine primitive set (core/agentic/: labeled_step,
loop, tool_dispatch, usage, client). Each capability now lives in one
pipeline.py file with one pipeline.yaml prompt.
- Deep Research: Rephrase (ask_user loop) -> Decompose (OUTLINE) ->
Research blocks (THINK/TOOL/APPEND/FINISH per topic, dynamic queue
preserved) -> Reporting (OUTLINE/INTRO/SECTION/CONCLUSION).
CitationManager and the dynamic topic queue are kept.
- Deep Solve: Pre-retrieve (KB-only, QUERIES/rag/SUMMARY) -> Plan ->
per-step THINK/TOOL/FINISH/REPLAN loop with back-edge to Plan ->
Synthesize. Step FINISH text flows into the next step's context.
- Question: coordinator + pipeline replace generator / idea_agent /
models, with new history.py and mimic_source.py helpers.
Removed: research/agents/, research/research_pipeline.py,
research/prompts/{en,zh}/*.yaml (legacy multi-agent prompts);
solve/agents/, solve/memory/, solve/utils/, main_solver.py,
session_manager.py, tool_runtime.py and old prompts;
question/agents/{generator,idea_agent}.py, example.py, models.py,
old prompts; api/routers/solve.py (capability owns its own routing).
Adds shared agents/_shared/tool_composition.py for cross-pipeline
tool wiring. Updates deep_research/deep_solve/deep_question
capabilities to dispatch through the new pipelines.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>