Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hindsight-api-slim/hindsight_api/mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ async def retain(
result = await memory.submit_async_retain(
bank_id=target_bank,
contents=[content_dict],
strategy=content_dict.pop("strategy", None),
request_context=request_context,
)
return {
Expand Down Expand Up @@ -698,6 +699,7 @@ async def retain(
result = await memory.submit_async_retain(
bank_id=target_bank,
contents=[content_dict],
strategy=content_dict.pop("strategy", None),
request_context=request_context,
)
return {
Expand Down
19 changes: 19 additions & 0 deletions hindsight-api-slim/tests/test_mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,25 @@ async def test_retain_with_document_id(self, mock_memory):
contents = call_args.kwargs["contents"]
assert contents[0]["document_id"] == "doc-1"

async def test_retain_passes_strategy_to_the_worker(self, mock_memory):
"""The strategy must travel as the submit argument, not inside the content item.

``submit_async_retain`` only puts a strategy into the task payload when it
is passed as the keyword; a strategy left inside the content dict never
reaches the worker, so every strategy override silently falls back to the
bank configuration.
"""
mcp = _make_mcp_server(mock_memory, {"retain"}, include_bank_id=True)
await _tools(mcp)["retain"].fn(content="test", strategy="documents")
call_args = mock_memory.submit_async_retain.call_args
assert call_args.kwargs["strategy"] == "documents"

async def test_retain_passes_strategy_single_bank(self, mock_memory):
mcp = _make_mcp_server(mock_memory, {"retain"}, include_bank_id=False)
await _tools(mcp)["retain"].fn(content="test", strategy="documents")
call_args = mock_memory.submit_async_retain.call_args
assert call_args.kwargs["strategy"] == "documents"

async def test_retain_without_new_params_backward_compat(self, mock_memory):
"""Existing behavior preserved when new params not provided."""
mcp = _make_mcp_server(mock_memory, {"retain"})
Expand Down