Files
DeepTutor/deeptutor/capabilities/disclosure.py
zszz3 0670c14fcd fix: repeat the setup rules once the tools are loaded, skip them for partners
The setup protocol (confirm with ask_user before apply_setting, never
handle secrets, ...) reached the model only in the load_tools result or
the turn that opened setup mode. Once history snipping or summarisation
dropped that message, the setup tools stayed in tools[] without their
rules. A setup turn (explicit mode or an intent message) whose capability
already has tools loaded now gets the protocol repeated in its turn note,
and the intent wording says the tools are already loaded.

A partner turn refuses every setup write (setup/access.py can_write), so
the setup tools are no longer listed under Extended Tools or pointed at
by the turn note there. Non-admin users keep them: personal preferences
are still theirs to change.

Also correct the comment about when set_deferral_available runs:
is_active is already asked by the exclusive-capability checks before it.

Refs #2972
2026-11-30 23:35:08 +08:00

41 lines
1.8 KiB
Python

"""Whether this turn discloses optional tools through ``load_tools``.
A loop turn can offer a tool in two ways: mount its schema in ``tools[]``, or
list it in the Extended Tools catalog and let the model ``load_tools`` it when
it actually needs it. Mounting per message ("this message mentions a paper",
"this message says *switch the model*") makes ``tools[]`` differ between two
turns of one conversation, which invalidates the provider's prompt cache from
the first tool on. Deferred tools only ever grow: a loaded schema stays loaded
for the rest of the session.
The loop pipeline decides once per turn whether deferral is available (the
turn is not owned by an exclusive capability, and ``load_tools`` itself is
allowed) and records it here before anything that shapes the turn — the tool
list, the system prompt, the turn notes — asks a capability whether it is
active. (The exclusive-capability check that the decision itself depends on
asks earlier and sees the flag unset; that only concerns exclusive
capabilities, which never read it.) A capability whose tools would otherwise be mounted by a message heuristic
reads it to stay inactive — and to keep its system block out — on such turns.
Callers that never set it (other pipelines, direct tests) keep the eager
behaviour.
"""
from __future__ import annotations
from deeptutor.core.context import UnifiedContext
_EXTENSION = "tool_disclosure"
_DEFERRAL_KEY = "deferral_available"
def set_deferral_available(context: UnifiedContext, available: bool) -> None:
context.extension(_EXTENSION)[_DEFERRAL_KEY] = bool(available)
def deferral_available(context: UnifiedContext) -> bool:
"""``True`` once the pipeline has confirmed optional tools can be deferred."""
return bool(context.extension(_EXTENSION).get(_DEFERRAL_KEY))
__all__ = ["deferral_available", "set_deferral_available"]