Skip to content

Commit c8bdeb9

Browse files
abrookinsclaude
andcommitted
feat: complete client library parameter naming updates
Updates client library models and implementation with descriptive parameter names: - Add new descriptive fields to RecencyConfig model alongside legacy ones - Update client.py parameter mapping with precedence logic - Add comprehensive test for parameter precedence validation - Maintain full backward compatibility with legacy short names 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5f849dc commit c8bdeb9

File tree

3 files changed

+101
-9
lines changed

3 files changed

+101
-9
lines changed

agent-memory-client/agent_memory_client/client.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,14 +675,45 @@ async def search_long_term_memory(
675675
if recency is not None:
676676
if recency.recency_boost is not None:
677677
payload["recency_boost"] = recency.recency_boost
678-
if recency.w_sem is not None:
679-
payload["recency_w_sem"] = recency.w_sem
680-
if recency.w_recency is not None:
681-
payload["recency_w_recency"] = recency.w_recency
682-
if recency.wf is not None:
683-
payload["recency_wf"] = recency.wf
684-
if recency.wa is not None:
685-
payload["recency_wa"] = recency.wa
678+
# Handle both new descriptive names and legacy short names
679+
# Prefer new descriptive names, fall back to old short names
680+
semantic_weight = (
681+
recency.semantic_weight
682+
if recency.semantic_weight is not None
683+
else recency.w_sem
684+
)
685+
if semantic_weight is not None:
686+
payload["recency_semantic_weight"] = semantic_weight
687+
payload["recency_w_sem"] = semantic_weight # For backward compatibility
688+
689+
recency_weight = (
690+
recency.recency_weight
691+
if recency.recency_weight is not None
692+
else recency.w_recency
693+
)
694+
if recency_weight is not None:
695+
payload["recency_recency_weight"] = recency_weight
696+
payload["recency_w_recency"] = (
697+
recency_weight # For backward compatibility
698+
)
699+
700+
freshness_weight = (
701+
recency.freshness_weight
702+
if recency.freshness_weight is not None
703+
else recency.wf
704+
)
705+
if freshness_weight is not None:
706+
payload["recency_freshness_weight"] = freshness_weight
707+
payload["recency_wf"] = freshness_weight # For backward compatibility
708+
709+
novelty_weight = (
710+
recency.novelty_weight
711+
if recency.novelty_weight is not None
712+
else recency.wa
713+
)
714+
if novelty_weight is not None:
715+
payload["recency_novelty_weight"] = novelty_weight
716+
payload["recency_wa"] = novelty_weight # For backward compatibility
686717
if recency.half_life_last_access_days is not None:
687718
payload["recency_half_life_last_access_days"] = (
688719
recency.half_life_last_access_days

agent-memory-client/agent_memory_client/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,29 @@ class RecencyConfig(BaseModel):
250250
recency_boost: bool | None = Field(
251251
default=None, description="Enable recency-aware re-ranking"
252252
)
253+
# Legacy short parameter names (deprecated)
253254
w_sem: float | None = Field(default=None, description="Weight for semantic score")
254255
w_recency: float | None = Field(
255256
default=None, description="Weight for recency composite"
256257
)
257258
wf: float | None = Field(default=None, description="Weight for freshness")
258259
wa: float | None = Field(default=None, description="Weight for age/novelty")
260+
261+
# New descriptive parameter names (preferred)
262+
semantic_weight: float | None = Field(
263+
default=None,
264+
description="Weight for semantic similarity (preferred over w_sem)",
265+
)
266+
recency_weight: float | None = Field(
267+
default=None, description="Weight for recency score (preferred over w_recency)"
268+
)
269+
freshness_weight: float | None = Field(
270+
default=None, description="Weight for freshness component (preferred over wf)"
271+
)
272+
novelty_weight: float | None = Field(
273+
default=None, description="Weight for novelty/age component (preferred over wa)"
274+
)
275+
259276
half_life_last_access_days: float | None = Field(
260277
default=None, description="Half-life (days) for last_accessed decay"
261278
)

agent-memory-client/tests/test_client.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,63 @@ async def test_recency_config_payload(self, enhanced_test_client):
326326
text="q", recency=rc, limit=5
327327
)
328328

329-
# Verify payload contained recency fields
329+
# Verify payload contained recency fields (both old and new names for compatibility)
330330
args, kwargs = mock_post.call_args
331331
assert args[0] == "/v1/long-term-memory/search"
332332
body = kwargs["json"]
333333
assert body["recency_boost"] is True
334+
# Old parameter names (for backward compatibility)
334335
assert body["recency_w_sem"] == 0.7
335336
assert body["recency_w_recency"] == 0.3
336337
assert body["recency_wf"] == 0.6
337338
assert body["recency_wa"] == 0.4
339+
# New descriptive parameter names (preferred)
340+
assert body["recency_semantic_weight"] == 0.7
341+
assert body["recency_recency_weight"] == 0.3
342+
assert body["recency_freshness_weight"] == 0.6
343+
assert body["recency_novelty_weight"] == 0.4
338344
assert body["recency_half_life_last_access_days"] == 7
339345
assert body["recency_half_life_created_days"] == 30
340346
assert body["server_side_recency"] is True
341347

348+
async def test_recency_config_new_parameter_names(self, enhanced_test_client):
349+
"""Test that new descriptive parameter names work and take precedence."""
350+
with patch.object(enhanced_test_client._client, "post") as mock_post:
351+
mock_response = AsyncMock()
352+
mock_response.raise_for_status.return_value = None
353+
mock_response.json.return_value = MemoryRecordResults(
354+
total=0, memories=[], next_offset=None
355+
).model_dump()
356+
mock_post.return_value = mock_response
357+
358+
rc = RecencyConfig(
359+
recency_boost=True,
360+
semantic_weight=0.9, # New parameter name should take precedence
361+
w_sem=0.1, # Old parameter name (should be ignored)
362+
recency_weight=0.1,
363+
freshness_weight=0.7,
364+
novelty_weight=0.3,
365+
half_life_last_access_days=5,
366+
half_life_created_days=20,
367+
server_side_recency=True,
368+
)
369+
370+
await enhanced_test_client.search_long_term_memory(
371+
text="test query", recency=rc, limit=10
372+
)
373+
374+
# Verify new parameter names take precedence
375+
args, kwargs = mock_post.call_args
376+
body = kwargs["json"]
377+
assert body["recency_boost"] is True
378+
# Both old and new names should be present
379+
assert body["recency_w_sem"] == 0.9 # Uses new value, not old
380+
assert body["recency_semantic_weight"] == 0.9 # New parameter
381+
assert body["recency_recency_weight"] == 0.1
382+
assert body["recency_freshness_weight"] == 0.7
383+
assert body["recency_novelty_weight"] == 0.3
384+
assert body["server_side_recency"] is True
385+
342386

343387
class TestClientSideValidation:
344388
"""Tests for client-side validation methods."""

0 commit comments

Comments
 (0)