From bd4345a2a6074e97700a0535b5c3f13f2095f880 Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Thu, 17 Sep 2026 23:43:06 +0000 Subject: [PATCH] narrow DeepSeek Flash tools for forced phases --- src/clean_agent_preview.py | 12 ++++++++++++ tests/test_clean_agent_preview.py | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/clean_agent_preview.py b/src/clean_agent_preview.py index ee19c156c..3b04fb3f9 100644 --- a/src/clean_agent_preview.py +++ b/src/clean_agent_preview.py @@ -186,6 +186,18 @@ def provider_compatible_tool_choice_request(request, model): """Keep tools but avoid forced choice unsupported by thinking providers.""" if canonical(model) == 'deepseek-flash' and 'tool_choice' in request: compatible = dict(request) + choice = compatible.get('tool_choice') + selected_name = ( + (choice.get('function') or {}).get('name') + if isinstance(choice, dict) else None + ) + if selected_name: + selected = [ + schema for schema in compatible.get('tools') or [] + if (schema.get('function') or {}).get('name') == selected_name + ] + if selected: + compatible['tools'] = selected compatible.pop('tool_choice', None) return compatible return request diff --git a/tests/test_clean_agent_preview.py b/tests/test_clean_agent_preview.py index 6f178b587..d244022c9 100644 --- a/tests/test_clean_agent_preview.py +++ b/tests/test_clean_agent_preview.py @@ -100,12 +100,15 @@ def test_provider_wire_messages_drops_empty_assistant_placeholder(): def test_deepseek_flash_keeps_tools_but_drops_unsupported_forced_choice(): request = { 'model': 'deepseek-flash', - 'tools': [{'type': 'function', 'function': {'name': 'inspect_media'}}], + 'tools': [ + {'type': 'function', 'function': {'name': 'inspect_media'}}, + {'type': 'function', 'function': {'name': 'python'}}, + ], 'tool_choice': {'type': 'function', 'function': {'name': 'inspect_media'}}, } compatible = provider_compatible_tool_choice_request(request, 'deepseek-flash') - assert compatible['tools'] == request['tools'] + assert [tool['function']['name'] for tool in compatible['tools']] == ['inspect_media'] assert 'tool_choice' not in compatible assert request['tool_choice']['function']['name'] == 'inspect_media' assert provider_compatible_tool_choice_request(request, 'qwen3.5-9b') is request