Skip to content

Commit 477eec9

Browse files
refactor(sdk): trim settings cleanup leftovers
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent cc1f534 commit 477eec9

2 files changed

Lines changed: 31 additions & 53 deletions

File tree

  • openhands-agent-server/openhands/agent_server
  • openhands-sdk/openhands/sdk/settings

openhands-agent-server/openhands/agent_server/models.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ class _StartConversationRequestBase(BaseModel):
184184
)
185185

186186

187+
def _start_request_payload_from_settings(
188+
*,
189+
workspace: LocalWorkspace,
190+
conversation_settings: ConversationSettings | None = None,
191+
**kwargs: Any,
192+
) -> dict[str, Any]:
193+
payload = dict(kwargs)
194+
if conversation_settings is not None:
195+
for key, value in conversation_settings.to_start_request_kwargs().items():
196+
payload.setdefault(key, value)
197+
payload["workspace"] = workspace
198+
return payload
199+
200+
187201
class StartConversationRequest(_StartConversationRequestBase):
188202
"""Payload to create a new conversation.
189203
@@ -201,11 +215,14 @@ def from_settings(
201215
conversation_settings: ConversationSettings | None = None,
202216
**kwargs: Any,
203217
) -> "StartConversationRequest":
204-
payload = dict(kwargs)
205-
if conversation_settings is not None:
206-
for key, value in conversation_settings.to_start_request_kwargs().items():
207-
payload.setdefault(key, value)
208-
return cls(agent=agent, workspace=workspace, **payload)
218+
return cls(
219+
agent=agent,
220+
**_start_request_payload_from_settings(
221+
workspace=workspace,
222+
conversation_settings=conversation_settings,
223+
**kwargs,
224+
),
225+
)
209226

210227

211228
class StartACPConversationRequest(_StartConversationRequestBase):
@@ -222,11 +239,14 @@ def from_settings(
222239
conversation_settings: ConversationSettings | None = None,
223240
**kwargs: Any,
224241
) -> "StartACPConversationRequest":
225-
payload = dict(kwargs)
226-
if conversation_settings is not None:
227-
for key, value in conversation_settings.to_start_request_kwargs().items():
228-
payload.setdefault(key, value)
229-
return cls(agent=agent, workspace=workspace, **payload)
242+
return cls(
243+
agent=agent,
244+
**_start_request_payload_from_settings(
245+
workspace=workspace,
246+
conversation_settings=conversation_settings,
247+
**kwargs,
248+
),
249+
)
230250

231251

232252
class StoredConversation(StartACPConversationRequest):

openhands-sdk/openhands/sdk/settings/model.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from collections.abc import Mapping
4-
from copy import deepcopy
53
from enum import Enum
64
from pathlib import Path
75
from typing import TYPE_CHECKING, Any, ClassVar, Literal, get_args, get_origin
@@ -205,50 +203,10 @@ def _default_llm_settings() -> LLM:
205203
return LLM(model=model)
206204

207205

208-
_SCHEMA_VERSION_KEY = "schema_version"
209206
_AGENT_SETTINGS_SCHEMA_VERSION = 1
210207
_CONVERSATION_SETTINGS_SCHEMA_VERSION = 1
211208

212209

213-
_MISSING = object()
214-
215-
216-
def _merge_patch_payload(
217-
base: Mapping[str, Any], patch: Mapping[str, Any]
218-
) -> dict[str, Any]:
219-
merged = deepcopy(dict(base))
220-
for key, value in patch.items():
221-
base_value = merged.get(key)
222-
if isinstance(base_value, dict) and isinstance(value, Mapping):
223-
merged[key] = _merge_patch_payload(base_value, value)
224-
else:
225-
merged[key] = deepcopy(value)
226-
return merged
227-
228-
229-
def _diff_payload(base: Mapping[str, Any], target: Mapping[str, Any]) -> dict[str, Any]:
230-
diff: dict[str, Any] = {}
231-
for key in sorted(set(base) | set(target)):
232-
if key == _SCHEMA_VERSION_KEY:
233-
continue
234-
base_value = base.get(key, _MISSING)
235-
target_value = target.get(key, _MISSING)
236-
237-
if target_value is _MISSING:
238-
continue
239-
if base_value is _MISSING:
240-
diff[key] = deepcopy(target_value)
241-
continue
242-
if isinstance(base_value, Mapping) and isinstance(target_value, Mapping):
243-
nested_diff = _diff_payload(base_value, target_value)
244-
if nested_diff:
245-
diff[key] = nested_diff
246-
continue
247-
if base_value != target_value:
248-
diff[key] = deepcopy(target_value)
249-
return diff
250-
251-
252210
class ConversationSettings(BaseModel):
253211
CURRENT_PERSISTED_VERSION: ClassVar[int] = _CONVERSATION_SETTINGS_SCHEMA_VERSION
254212

@@ -393,7 +351,7 @@ class AgentSettings(BaseModel):
393351
)
394352
verification: VerificationSettings = Field(
395353
default_factory=VerificationSettings,
396-
description="Verification settings (critic + security) for the agent.",
354+
description="Verification settings for the agent critic.",
397355
json_schema_extra={
398356
SETTINGS_SECTION_METADATA_KEY: SettingsSectionMetadata(
399357
key="verification",

0 commit comments

Comments
 (0)