Skip to content

Commit 5f73b1f

Browse files
Fix: Condenser LLM should not pass extra_body (Fixes #1252) (#1266)
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent e861a97 commit 5f73b1f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

openhands-sdk/openhands/sdk/context/condenser/llm_summarizing_condenser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def get_condensation(self, view: View) -> Condensation:
6969

7070
messages = [Message(role="user", content=[TextContent(text=prompt)])]
7171

72+
# Do not pass extra_body explicitly. The LLM handles forwarding
73+
# litellm_extra_body only when it is non-empty.
7274
llm_response = self.llm.completion(
7375
messages=messages,
74-
extra_body=self.llm.litellm_extra_body,
7576
)
7677
# Extract summary from the LLMResponse message
7778
summary = None

tests/sdk/context/condenser/test_llm_summarizing_condenser.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,25 @@ def test_invalid_config(mock_llm: LLM) -> None:
197197
# Test keep_first must be less than max_size // 2 to leave room for condensation
198198
with pytest.raises(ValueError):
199199
LLMSummarizingCondenser(llm=mock_llm, max_size=10, keep_first=8)
200+
201+
202+
def test_get_condensation_does_not_pass_extra_body(mock_llm: LLM) -> None:
203+
"""Condenser should not pass extra_body to llm.completion.
204+
205+
This prevents providers like 1p Anthropic from rejecting the request with
206+
"extra_body: Extra inputs are not permitted".
207+
"""
208+
condenser = LLMSummarizingCondenser(llm=mock_llm, max_size=10, keep_first=2)
209+
210+
# Prepare a view that triggers condensation (len > max_size)
211+
events: list[Event] = [message_event(f"Event {i}") for i in range(12)]
212+
view = View.from_events(events)
213+
214+
result = condenser.condense(view)
215+
assert isinstance(result, Condensation)
216+
217+
# Ensure completion was called without an explicit extra_body kwarg
218+
completion_mock = cast(MagicMock, mock_llm.completion)
219+
assert completion_mock.call_count == 1
220+
_, kwargs = completion_mock.call_args
221+
assert "extra_body" not in kwargs

0 commit comments

Comments
 (0)