Skip to content

Commit aec44be

Browse files
committed
fix(providers): replay reasoning without tool declarations
1 parent e351227 commit aec44be

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

raven/providers/litellm_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ async def chat(
436436
original_model = model or self.default_model
437437
model = self._resolve_model(original_model)
438438
extra_msg_keys = self._extra_msg_keys(original_model, model)
439-
ensure_tool_reasoning = bool(tools) and self._requires_tool_reasoning_replay(original_model, model)
439+
ensure_tool_reasoning = self._requires_tool_reasoning_replay(original_model, model)
440440

441441
if self._supports_cache_control(original_model):
442442
if not self.disable_auto_cache_control:
@@ -546,7 +546,7 @@ async def chat_stream(
546546
original_model = model or self.default_model
547547
model = self._resolve_model(original_model)
548548
extra_msg_keys = self._extra_msg_keys(original_model, model)
549-
ensure_tool_reasoning = bool(tools) and self._requires_tool_reasoning_replay(original_model, model)
549+
ensure_tool_reasoning = self._requires_tool_reasoning_replay(original_model, model)
550550

551551
if self._supports_cache_control(original_model):
552552
if not self.disable_auto_cache_control:

tests/test_litellm_provider_stream.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,13 @@ async def fake_acompletion(**kwargs: Any):
279279
("openrouter/deepseek/deepseek-v4-pro", "openrouter"),
280280
],
281281
)
282+
@pytest.mark.parametrize("declare_tools", [True, False], ids=["declared", "omitted"])
282283
@pytest.mark.asyncio
283284
async def test_chat_replays_empty_reasoning_for_deepseek_v4_tool_calls(
284285
monkeypatch: pytest.MonkeyPatch,
285286
model: str,
286287
provider_name: str,
288+
declare_tools: bool,
287289
) -> None:
288290
captured: dict[str, Any] = {}
289291

@@ -307,17 +309,19 @@ async def fake_acompletion(**kwargs: Any):
307309
},
308310
{"role": "tool", "content": "done", "tool_call_id": "call_1"},
309311
]
310-
tools = [{"type": "function", "function": {"name": "probe", "parameters": {}}}]
312+
tools = [{"type": "function", "function": {"name": "probe", "parameters": {}}}] if declare_tools else None
311313
provider = LiteLLMProvider(api_key="test-key", provider_name=provider_name, default_model=model)
312314

313315
await provider.chat(messages=messages, tools=tools)
314316

315317
assert captured["messages"][0]["reasoning_content"] == ""
316318

317319

320+
@pytest.mark.parametrize("declare_tools", [True, False], ids=["declared", "omitted"])
318321
@pytest.mark.asyncio
319322
async def test_chat_stream_replays_empty_reasoning_for_deepseek_v4_tool_calls(
320323
monkeypatch: pytest.MonkeyPatch,
324+
declare_tools: bool,
321325
) -> None:
322326
captured: dict[str, Any] = {}
323327

@@ -328,7 +332,7 @@ async def fake_acompletion(**kwargs: Any):
328332
monkeypatch.setattr("raven.providers.litellm_provider.acompletion", fake_acompletion)
329333

330334
messages = [{"role": "assistant", "content": "", "tool_calls": [{"id": "call_1"}]}]
331-
tools = [{"type": "function", "function": {"name": "probe", "parameters": {}}}]
335+
tools = [{"type": "function", "function": {"name": "probe", "parameters": {}}}] if declare_tools else None
332336
provider = LiteLLMProvider(
333337
api_key="test-key",
334338
provider_name="deepseek",

0 commit comments

Comments
 (0)