Skip to content

Commit 0996e4e

Browse files
fix: preserve empty tools array from server instead of coercing to None
Co-Authored-By: Paul Loeb <ploeb@launchdarkly.com>
1 parent c01300c commit 0996e4e

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

packages/sdk/server-ai/src/ldai/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def _completion_config(
6969
)
7070
for tool in variation['tools']
7171
if isinstance(tool, dict) and 'key' in tool
72-
] or None
72+
]
7373

7474
config = AICompletionConfig(
7575
key=key,
7676
enabled=bool(enabled),
7777
model=model,
7878
messages=messages,
79-
tools=tools if tools is not None else (default.tools if default.tools else None),
79+
tools=tools if tools is not None else default.tools,
8080
provider=provider,
8181
tracker=tracker,
8282
judge_configuration=judge_configuration,
@@ -742,15 +742,15 @@ def __evaluate_agent(
742742
)
743743
for tool in variation['tools']
744744
if isinstance(tool, dict) and 'key' in tool
745-
] or None
745+
]
746746

747747
return AIAgentConfig(
748748
key=key,
749749
enabled=bool(enabled) if enabled is not None else (default.enabled or False),
750750
model=model or default.model,
751751
provider=provider or default.provider,
752752
instructions=final_instructions,
753-
tools=tools if tools is not None else (default.tools if default.tools else None),
753+
tools=tools if tools is not None else default.tools,
754754
tracker=tracker,
755755
judge_configuration=judge_configuration or default.judge_configuration,
756756
)

packages/sdk/server-ai/tests/test_tools.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,34 @@ def test_completion_config_without_tools(ldai_client: LDAIClient):
207207

208208

209209
def test_completion_config_empty_tools(ldai_client: LDAIClient):
210-
"""Test that completion config handles empty tools array."""
210+
"""Test that completion config preserves empty tools array from server."""
211211
context = Context.create('user-key')
212212
default = AICompletionConfigDefault(enabled=False, model=ModelConfig('fallback'))
213213

214214
config = ldai_client.completion_config('empty-tools-config', context, default)
215215

216216
assert config.enabled is True
217-
assert config.tools is None
217+
# An explicit empty tools array from server should be preserved as empty list,
218+
# NOT fall back to defaults
219+
assert config.tools is not None
220+
assert config.tools == []
221+
222+
223+
def test_completion_config_empty_tools_no_default_fallback(ldai_client: LDAIClient):
224+
"""Test that empty tools array from server does NOT fall back to defaults."""
225+
context = Context.create('user-key')
226+
default_tools = [AITool(key='default-tool', version=1)]
227+
default = AICompletionConfigDefault(
228+
enabled=False,
229+
model=ModelConfig('fallback'),
230+
tools=default_tools,
231+
)
232+
233+
config = ldai_client.completion_config('empty-tools-config', context, default)
234+
235+
assert config.enabled is True
236+
# Server sent empty tools=[], so we should honor that, not use defaults
237+
assert config.tools == []
218238

219239

220240
def test_completion_config_uses_default_tools(ldai_client: LDAIClient):

0 commit comments

Comments
 (0)