fix(toolchoice): default required tool choice on OpenAI-compatible custom endpoints

Reasoning models on OpenAI-compatible custom endpoints (e.g. GLM / Kimi)
often reason and reply with prose instead of emitting native tool calls
under the default auto tool choice, stalling the tool-driven scan loop
while burning tokens. Default force_required_tool_choice to auto (None):
enable tool_choice=required when an api_base is set (still gated to
models that accept it), off otherwise. Explicit 0/1 overrides.
This commit is contained in:
Alex Schapiro
2026-07-29 03:27:40 +00:00
parent d2fd1d6103
commit b861413d10
6 changed files with 56 additions and 4 deletions
+38
View File
@@ -255,6 +255,44 @@ def test_make_model_settings_forces_required_for_anyllm_routed_openai_model() ->
assert settings.tool_choice == "required"
def test_make_model_settings_auto_forces_required_on_custom_openai_endpoint() -> None:
# GLM / Kimi via cortecs: openai/-routed reasoning model on a custom base.
settings = make_model_settings(
None,
model_name="openai/glm-5.2",
custom_api_base=True,
)
assert settings.tool_choice == "required"
def test_make_model_settings_auto_skips_required_without_custom_endpoint() -> None:
settings = make_model_settings(None, model_name="openai/glm-5.2")
assert settings.tool_choice is None
def test_make_model_settings_explicit_false_overrides_custom_endpoint() -> None:
settings = make_model_settings(
None,
model_name="openai/glm-5.2",
force_required_tool_choice=False,
custom_api_base=True,
)
assert settings.tool_choice is None
def test_make_model_settings_auto_skips_required_for_non_openai_custom_endpoint() -> None:
settings = make_model_settings(
None,
model_name="anthropic/claude-3-7-sonnet-latest",
custom_api_base=True,
)
assert settings.tool_choice is None
def test_make_model_settings_sets_request_timeout() -> None:
settings = make_model_settings(
"none",
+1
View File
@@ -38,6 +38,7 @@ async def test_persistent_rate_limit_stops_gracefully(
model="openai/gpt-4o",
reasoning_effort="high",
force_required_tool_choice=False,
api_base=None,
timeout=300,
prompt_cache=True,
),
+1
View File
@@ -46,6 +46,7 @@ def _patch_engine_scaffold(
model="openai/gpt-4o",
reasoning_effort="high",
force_required_tool_choice=False,
api_base=None,
timeout=300,
prompt_cache=True,
),