Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.7 KB
Raw Blame
"""Observability: a chat follow-up's prior-context build logs its mode + size.

The summary path is otherwise silent (no token-counter entry), so a follow-up
looked like an unexplained pause. One info line per follow-up records what ran.
"""

from local_deep_research.chat.context import ChatContextManager

_LOGGER = "local_deep_research.chat.context.logger"


def _conversation():
    return [
        {"role": "user", "content": "What is X?", "message_type": "query"},
        {
            "role": "assistant",
            "content": "X is a thing with several properties.",
            "message_type": "response",
            "research_id": "r1",
        },
    ]


class TestFollowupContextLogging:
    def test_logs_mode_and_size_on_followup(self, mocker):
        log = mocker.patch(_LOGGER)
        manager = ChatContextManager(
            session_id="s1",
            messages=_conversation(),
            accumulated_context={},
            settings_snapshot={"chat.followup_context_mode": "raw"},
        )

        manager.build_research_context(current_query="tell me more")

        log.info.assert_called_once()
        fmt, *values = log.info.call_args.args
        assert "mode=" in fmt
        assert "raw" in values  # the resolved mode is logged

    def test_first_turn_does_not_log(self, mocker):
        log = mocker.patch(_LOGGER)
        manager = ChatContextManager(
            session_id="s1",
            messages=[
                {"role": "user", "content": "First", "message_type": "query"}
            ],
            accumulated_context={},
        )

        manager.build_research_context(current_query="First")

        # No prior work on the first turn → no context-build log line.
        log.info.assert_not_called()