Files
DeepTutor/deeptutor/agents/question/request_config.py
Bingxi Zhao (Frank) 6153d8c092 release: v1.4.0 — release notes, version bump, repo hygiene
- Add assets/releases/ver1-4-0.md covering deltas since v1.4.0-beta
  (reasoning_effort normalization, tool-schema fallback, restart-safe
  turn runtime, frontend placeholder hardening, CLI chat REPL config).
- Bump deeptutor/__version__ to 1.4.0.
- Update README Releases section: v1.4.0 at top, install opt-in note
  updated for stable.
- Fix pre-existing pre-commit failures so the v1.4.0 cut runs clean:
  bandit B324 (mark _sha1 as non-security), mypy no-redef in
  document.py / line_doc.py, mypy arg-type/assignment in
  snapshot/adapters.py, mypy assignment + arg-type in
  services/memory/settings.py, mypy func-returns-value on
  set.add idiom in deeptutor_cli/init_wizard.py.
- Apply ruff format / prettier sweep across the repo.
- Remove stale workspace + i18n env example + playwright captures
  already cleaned locally; ignore .playwright-cli/ going forward.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 21:09:22 +08:00

78 lines
2.6 KiB
Python

"""Runtime config builder for ``QuestionPipeline``.
Mirrors the shape used by :mod:`deeptutor.agents.research.request_config`,
but with a much smaller surface — the question pipeline only needs a
handful of knobs out of the service config:
* ``exploring.max_iterations`` (int, default 8) — agentic-loop cap for the
Explore phase.
* ``exploring.tool_summarizer.enabled`` (bool, default True) — toggle the
per-tool-result LLM reflection step that compresses raw tool output
before downstream phases see it.
* ``exploring.tool_summarizer.max_tokens`` (int, default 800) — token cap
on each summarizer call.
The helper is intentionally tolerant: missing keys / wrong types collapse
to defaults so callers can pass any base config (e.g. ``main.yaml``)
without first defining a ``capabilities.deep_question`` section.
"""
from __future__ import annotations
from typing import Any
def _read_int(source: dict[str, Any], key: str, default: int) -> int:
value = source.get(key)
if isinstance(value, int) and value > 0:
return value
return default
def _read_bool(source: dict[str, Any], key: str, default: bool) -> bool:
value = source.get(key)
if isinstance(value, bool):
return value
return default
def build_question_runtime_config(
*,
base_config: dict[str, Any] | None,
) -> dict[str, Any]:
"""Build the runtime_config dict passed to :class:`QuestionPipeline`.
The pipeline reads its knobs from ``runtime_config["exploring"]`` —
everything else in ``base_config`` is currently ignored by question.
"""
base = base_config if isinstance(base_config, dict) else {}
capabilities = base.get("capabilities") if isinstance(base.get("capabilities"), dict) else {}
question_root = (
capabilities.get("deep_question")
if isinstance(capabilities.get("deep_question"), dict)
else {}
)
exploring_root = (
question_root.get("exploring") if isinstance(question_root.get("exploring"), dict) else {}
)
summarizer_root = (
exploring_root.get("tool_summarizer")
if isinstance(exploring_root.get("tool_summarizer"), dict)
else {}
)
exploring = {
"max_iterations": _read_int(exploring_root, "max_iterations", 8),
"tool_summarizer": {
"enabled": _read_bool(summarizer_root, "enabled", True),
"max_tokens": _read_int(summarizer_root, "max_tokens", 800),
},
}
runtime_config = dict(base)
runtime_config["exploring"] = exploring
return runtime_config
__all__ = ["build_question_runtime_config"]