@miller-tech/uap 1.20.9 → 1.20.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -280,9 +280,6 @@ PROXY_FORCED_TOOL_DAMPENER_REJECTIONS = int(
|
|
|
280
280
|
PROXY_TOOL_STARVATION_THRESHOLD = int(
|
|
281
281
|
os.environ.get("PROXY_TOOL_STARVATION_THRESHOLD", "5")
|
|
282
282
|
)
|
|
283
|
-
PROXY_CONTEXT_HIGH_RELAXATION_THRESHOLD = float(
|
|
284
|
-
os.environ.get("PROXY_CONTEXT_HIGH_RELAXATION_THRESHOLD", "0.70")
|
|
285
|
-
)
|
|
286
283
|
PROXY_SESSION_CONTAMINATION_BREAKER = os.environ.get(
|
|
287
284
|
"PROXY_SESSION_CONTAMINATION_BREAKER", "on"
|
|
288
285
|
).lower() not in {
|
|
@@ -2388,22 +2385,6 @@ def build_openai_request(
|
|
|
2388
2385
|
if not has_tool_results:
|
|
2389
2386
|
monitor.reset_tool_turn_state(reason="no_tool_results")
|
|
2390
2387
|
|
|
2391
|
-
# CONTEXT-AWARE RELAXATION: when context utilization is high and
|
|
2392
|
-
# tool_choice was forced to required, relax to auto to let the model
|
|
2393
|
-
# emit shorter text responses instead of consuming more tokens.
|
|
2394
|
-
if openai_body.get("tool_choice") == "required":
|
|
2395
|
-
ctx_utilization = (
|
|
2396
|
-
monitor.last_input_tokens / monitor.context_window
|
|
2397
|
-
if monitor.context_window > 0
|
|
2398
|
-
else 0.0
|
|
2399
|
-
)
|
|
2400
|
-
if ctx_utilization >= PROXY_CONTEXT_HIGH_RELAXATION_THRESHOLD:
|
|
2401
|
-
openai_body["tool_choice"] = "auto"
|
|
2402
|
-
logger.warning(
|
|
2403
|
-
"CONTEXT-AWARE RELAXATION: tool_choice=auto (utilization=%.1f%% >= %.0f%% threshold)",
|
|
2404
|
-
ctx_utilization * 100,
|
|
2405
|
-
PROXY_CONTEXT_HIGH_RELAXATION_THRESHOLD * 100,
|
|
2406
|
-
)
|
|
2407
2388
|
|
|
2408
2389
|
if PROXY_DISABLE_THINKING_ON_TOOL_TURNS:
|
|
2409
2390
|
openai_body["enable_thinking"] = False
|
|
@@ -3166,44 +3166,6 @@ class TestToolStarvationBreaker(unittest.TestCase):
|
|
|
3166
3166
|
self.assertIn("tools", result)
|
|
3167
3167
|
|
|
3168
3168
|
|
|
3169
|
-
class TestContextAwareRelaxation(unittest.TestCase):
|
|
3170
|
-
"""Tests for context-aware tool_choice relaxation."""
|
|
3171
|
-
|
|
3172
|
-
def test_relaxes_at_high_utilization(self):
|
|
3173
|
-
monitor = proxy.SessionMonitor()
|
|
3174
|
-
monitor.context_window = 100000
|
|
3175
|
-
monitor.last_input_tokens = 75000 # 75% > 70% threshold
|
|
3176
|
-
body = {
|
|
3177
|
-
"model": "qwen3.5",
|
|
3178
|
-
"messages": [
|
|
3179
|
-
{"role": "user", "content": "hello"},
|
|
3180
|
-
{"role": "assistant", "content": "text only"},
|
|
3181
|
-
{"role": "user", "content": [{"type": "tool_result", "tool_use_id": "x", "content": "ok"}]},
|
|
3182
|
-
],
|
|
3183
|
-
"tools": [{"name": "Bash", "input_schema": {"type": "object", "properties": {"command": {"type": "string"}}}}],
|
|
3184
|
-
}
|
|
3185
|
-
result = proxy.build_openai_request(body, monitor)
|
|
3186
|
-
# Should be auto, not required
|
|
3187
|
-
self.assertEqual(result.get("tool_choice"), "auto")
|
|
3188
|
-
|
|
3189
|
-
def test_no_relaxation_below_threshold(self):
|
|
3190
|
-
monitor = proxy.SessionMonitor()
|
|
3191
|
-
monitor.context_window = 100000
|
|
3192
|
-
monitor.last_input_tokens = 50000 # 50% < 70%
|
|
3193
|
-
body = {
|
|
3194
|
-
"model": "qwen3.5",
|
|
3195
|
-
"messages": [
|
|
3196
|
-
{"role": "user", "content": "hello"},
|
|
3197
|
-
{"role": "assistant", "content": "text only"},
|
|
3198
|
-
{"role": "user", "content": [{"type": "tool_result", "tool_use_id": "x", "content": "ok"}]},
|
|
3199
|
-
],
|
|
3200
|
-
"tools": [{"name": "Bash", "input_schema": {"type": "object", "properties": {"command": {"type": "string"}}}}],
|
|
3201
|
-
}
|
|
3202
|
-
result = proxy.build_openai_request(body, monitor)
|
|
3203
|
-
# Should still be required (state machine forces it)
|
|
3204
|
-
self.assertEqual(result.get("tool_choice"), "required")
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
3169
|
if __name__ == "__main__":
|
|
3208
3170
|
unittest.main()
|
|
3209
3171
|
|