unsloth/studio/backend/state/tool_policy.py
Roland Tannous 0da8af56d6
unsloth run: add --enable-tools/--disable-tools server-side tool policy (#5277)
* Add process-level tool_policy state for unsloth run

* Apply tool_policy override at chat/completions, /messages, and tool pass-through gates

* Add pure resolver for unsloth run --enable-tools/--disable-tools

* Wire --enable-tools/--disable-tools into unsloth run

* Color tool-policy notices and confirmation prompt in Claude orange

* Always show tool-status notice; print URL + API key in silent mode

* Treat any non-loopback bind as external; forward --yes after parent prompt

* Fix tool_policy double-module bug: import via state.tool_policy to share global with routes
2026-05-05 12:45:15 +04:00

33 lines
903 B
Python

# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
"""Process-level server-side tool policy.
Set by `unsloth run` at startup; consulted by the inference route gates.
None -> no CLI override (default). Per-request `enable_tools` is honored.
True -> CLI forced tools on for every request.
False -> CLI forced tools off for every request.
"""
from typing import Optional
_tool_policy: Optional[bool] = None
def get_tool_policy() -> Optional[bool]:
return _tool_policy
def set_tool_policy(value: Optional[bool]) -> None:
if value is not None and not isinstance(value, bool):
raise TypeError(
f"tool_policy must be Optional[bool], got {type(value).__name__}"
)
global _tool_policy
_tool_policy = value
def reset_tool_policy() -> None:
global _tool_policy
_tool_policy = None