Skip to content

Commit f83fafa

Browse files
DK09876DK09876
andauthored
refactor(haystack): rename HindsightToolset -> HindsightMemoryWrapper (#2118)
The class subclasses Haystack's `Toolset` but is used as an automatic memory wrapper (auto_recall / auto_retain around an Agent), not a tool collection. Reusing the `Toolset` name was confusing next to Haystack's own `Toolset` abstraction — flagged by deepset DevRel in review of the haystack-integrations gallery entry (deepset-ai/haystack-integrations#505). Pure rename across the package, tests, README, and docs pages. The class still subclasses `haystack.tools.Toolset`. No backward-compat alias — the package is at 0.1.0 with no adoption yet, so the rename is clean. Co-authored-by: DK09876 <dk09876@Dikshants-MacBook-Pro.local>
1 parent 0a74ce3 commit f83fafa

6 files changed

Lines changed: 39 additions & 39 deletions

File tree

hindsight-docs/docs-integrations/haystack.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
sidebar_position: 34
33
title: "Haystack Persistent Memory with Hindsight | Integration"
4-
description: "Add persistent long-term memory to Haystack agents with Hindsight. Provides retain/recall/reflect Tools plus a HindsightToolset with optional auto-recall and auto-retain."
4+
description: "Add persistent long-term memory to Haystack agents with Hindsight. Provides retain/recall/reflect Tools plus a HindsightMemoryWrapper with optional auto-recall and auto-retain."
55
---
66

77
# Haystack
88

99
Persistent long-term memory for [Haystack](https://haystack.deepset.ai/) agents via Hindsight. The `hindsight-haystack` package gives you two complementary patterns:
1010

1111
- **`create_hindsight_tools(...)`** — Returns a list of Haystack `Tool`s (`retain_memory`, `recall_memory`, `reflect_on_memory`) the model can call directly inside a turn.
12-
- **`HindsightToolset`** — A Haystack `Toolset` that bundles the same tools and adds optional **auto-recall** (inject relevant memories into the system prompt before each turn) and **auto-retain** (store user + assistant messages after each turn).
12+
- **`HindsightMemoryWrapper`** — A Haystack `Toolset` that bundles the same tools and adds optional **auto-recall** (inject relevant memories into the system prompt before each turn) and **auto-retain** (store user + assistant messages after each turn).
1313

1414
## Installation
1515

@@ -48,14 +48,14 @@ result = agent.run(messages=[ChatMessage.from_user("Remember that I prefer dark
4848
print(result["messages"][-1].text)
4949
```
5050

51-
## Automatic Memory with HindsightToolset
51+
## Automatic Memory with HindsightMemoryWrapper
5252

5353
For automatic recall and retain without relying on the agent to call tools:
5454

5555
```python
56-
from hindsight_haystack import HindsightToolset
56+
from hindsight_haystack import HindsightMemoryWrapper
5757

58-
toolset = HindsightToolset(
58+
toolset = HindsightMemoryWrapper(
5959
client=client,
6060
bank_id="user-123",
6161
mission="Track user preferences",

hindsight-docs/src/data/integrations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
{
224224
"id": "haystack",
225225
"name": "Haystack",
226-
"description": "Persistent memory for Haystack agents. Provides retain/recall/reflect Tools plus a HindsightToolset with optional auto-recall and auto-retain.",
226+
"description": "Persistent memory for Haystack agents. Provides retain/recall/reflect Tools plus a HindsightMemoryWrapper with optional auto-recall and auto-retain.",
227227
"type": "official",
228228
"by": "hindsight",
229229
"category": "framework",

hindsight-integrations/haystack/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ result = agent.run(messages=[ChatMessage.from_user("Remember that I prefer dark
4141
print(result["messages"][-1].text)
4242
```
4343

44-
## Automatic Memory with HindsightToolset
44+
## Automatic Memory with HindsightMemoryWrapper
4545

4646
For automatic recall and retain without relying on the agent to call tools:
4747

4848
```python
49-
from hindsight_haystack import HindsightToolset
49+
from hindsight_haystack import HindsightMemoryWrapper
5050

51-
toolset = HindsightToolset(
51+
toolset = HindsightMemoryWrapper(
5252
client=client,
5353
bank_id="user-123",
5454
mission="Track user preferences",

hindsight-integrations/haystack/hindsight_haystack/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
reset_config,
2222
)
2323
from .errors import HindsightError
24-
from .tools import HindsightToolset, create_hindsight_tools
24+
from .tools import HindsightMemoryWrapper, create_hindsight_tools
2525

2626
__version__ = "0.1.0"
2727

@@ -32,5 +32,5 @@
3232
"HindsightHaystackConfig",
3333
"HindsightError",
3434
"create_hindsight_tools",
35-
"HindsightToolset",
35+
"HindsightMemoryWrapper",
3636
]

hindsight-integrations/haystack/hindsight_haystack/tools.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Provides a convenience factory that creates Haystack-compatible ``Tool``
44
instances backed by Hindsight's retain/recall/reflect APIs, and a
5-
``HindsightToolset`` with optional auto-recall and auto-retain.
5+
``HindsightMemoryWrapper`` with optional auto-recall and auto-retain.
66
"""
77

88
import asyncio
@@ -549,7 +549,7 @@ def create_hindsight_tools(
549549
550550
Convenience factory that creates a backend and returns Haystack ``Tool``
551551
instances ready for use with any Haystack agent. For automatic recall
552-
and retain behavior, use :class:`HindsightToolset` instead.
552+
and retain behavior, use :class:`HindsightMemoryWrapper` instead.
553553
554554
Args:
555555
bank_id: The Hindsight memory bank to operate on.
@@ -620,7 +620,7 @@ def create_hindsight_tools(
620620
)
621621

622622

623-
class HindsightToolset(Toolset):
623+
class HindsightMemoryWrapper(Toolset):
624624
"""Haystack ``Toolset`` with optional auto-recall and auto-retain.
625625
626626
Groups Hindsight memory tools into a single toolset and optionally adds
@@ -637,11 +637,11 @@ class HindsightToolset(Toolset):
637637
638638
Example::
639639
640-
from hindsight_haystack import HindsightToolset
640+
from hindsight_haystack import HindsightMemoryWrapper
641641
from haystack.components.agents import Agent
642642
from haystack.components.generators.chat import OpenAIChatGenerator
643643
644-
toolset = HindsightToolset(
644+
toolset = HindsightMemoryWrapper(
645645
bank_id="user-123",
646646
client=client,
647647
mission="Track user preferences",
@@ -925,7 +925,7 @@ def to_dict(self) -> dict[str, Any]:
925925
}
926926

927927
@classmethod
928-
def from_dict(cls, data: dict[str, Any]) -> "HindsightToolset":
928+
def from_dict(cls, data: dict[str, Any]) -> "HindsightMemoryWrapper":
929929
"""Deserialize the toolset from a dictionary."""
930930
inner = data["data"]
931931
backend_kwargs = inner["backend_kwargs"]

hindsight-integrations/haystack/tests/test_tools.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from haystack.dataclasses import ChatMessage
77
from hindsight_haystack import (
8-
HindsightToolset,
8+
HindsightMemoryWrapper,
99
configure,
1010
create_hindsight_tools,
1111
reset_config,
@@ -788,19 +788,19 @@ def test_no_retry_on_409_conflict(self):
788788
assert client.acreate_bank.call_count == 1
789789

790790

791-
class TestHindsightToolset:
792-
"""Test the HindsightToolset class."""
791+
class TestHindsightMemoryWrapper:
792+
"""Test the HindsightMemoryWrapper class."""
793793

794794
def test_creates_three_tools_by_default(self):
795795
client = _mock_client()
796-
toolset = HindsightToolset(bank_id="test", client=client)
796+
toolset = HindsightMemoryWrapper(bank_id="test", client=client)
797797
assert len(toolset) == 3
798798
names = {t.name for t in toolset}
799799
assert names == {"retain_memory", "recall_memory", "reflect_on_memory"}
800800

801801
def test_include_flags(self):
802802
client = _mock_client()
803-
toolset = HindsightToolset(
803+
toolset = HindsightMemoryWrapper(
804804
bank_id="test",
805805
client=client,
806806
include_retain=True,
@@ -814,7 +814,7 @@ def test_serialization_round_trip(self):
814814
client = _mock_client()
815815
client._base_url = "http://test:8888"
816816
client._api_key = "test-key"
817-
toolset = HindsightToolset(
817+
toolset = HindsightMemoryWrapper(
818818
bank_id="test",
819819
client=client,
820820
auto_recall=True,
@@ -829,19 +829,19 @@ def test_serialization_round_trip(self):
829829

830830
with patch("hindsight_haystack._client.Hindsight") as mock_cls:
831831
mock_cls.return_value = _mock_client()
832-
restored = HindsightToolset.from_dict(d)
832+
restored = HindsightMemoryWrapper.from_dict(d)
833833
assert len(restored) == 3
834834
assert restored._auto_recall is True
835835
assert restored._auto_retain is True
836836

837837

838838
class TestToolsetAutoRecall:
839-
"""Test auto-recall behavior in HindsightToolset.run()."""
839+
"""Test auto-recall behavior in HindsightMemoryWrapper.run()."""
840840

841841
def test_auto_recall_enriches_system_prompt(self):
842842
client = _mock_client()
843843
client.arecall.return_value = _mock_recall_response(["User likes Python", "User is in NYC"])
844-
toolset = HindsightToolset(bank_id="test", client=client, auto_recall=True)
844+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_recall=True)
845845

846846
# Create a mock agent
847847
agent = MagicMock()
@@ -862,7 +862,7 @@ def test_auto_recall_enriches_system_prompt(self):
862862
def test_auto_recall_uses_agent_system_prompt_when_none_provided(self):
863863
client = _mock_client()
864864
client.arecall.return_value = _mock_recall_response(["some memory"])
865-
toolset = HindsightToolset(bank_id="test", client=client, auto_recall=True)
865+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_recall=True)
866866

867867
agent = MagicMock()
868868
agent.system_prompt = "Agent default prompt."
@@ -878,7 +878,7 @@ def test_auto_recall_uses_agent_system_prompt_when_none_provided(self):
878878
def test_auto_recall_overrides_with_explicit_system_prompt(self):
879879
client = _mock_client()
880880
client.arecall.return_value = _mock_recall_response(["memory"])
881-
toolset = HindsightToolset(bank_id="test", client=client, auto_recall=True)
881+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_recall=True)
882882

883883
agent = MagicMock()
884884
agent.system_prompt = "Agent default."
@@ -899,7 +899,7 @@ def test_auto_recall_overrides_with_explicit_system_prompt(self):
899899

900900
def test_auto_recall_skips_when_no_user_message(self):
901901
client = _mock_client()
902-
toolset = HindsightToolset(bank_id="test", client=client, auto_recall=True)
902+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_recall=True)
903903

904904
agent = MagicMock()
905905
agent.system_prompt = "base prompt"
@@ -914,7 +914,7 @@ def test_auto_recall_skips_when_no_user_message(self):
914914

915915
def test_auto_recall_disabled_by_default(self):
916916
client = _mock_client()
917-
toolset = HindsightToolset(bank_id="test", client=client)
917+
toolset = HindsightMemoryWrapper(bank_id="test", client=client)
918918

919919
agent = MagicMock()
920920
agent.system_prompt = "base"
@@ -930,7 +930,7 @@ def test_auto_recall_respects_max_recall_results(self):
930930
client = _mock_client()
931931
# Return many results
932932
client.arecall.return_value = _mock_recall_response([f"Memory {i}" for i in range(20)])
933-
toolset = HindsightToolset(
933+
toolset = HindsightMemoryWrapper(
934934
bank_id="test",
935935
client=client,
936936
auto_recall=True,
@@ -954,7 +954,7 @@ def test_auto_recall_respects_max_recall_results(self):
954954
def test_auto_recall_no_memories_passes_base_prompt(self):
955955
client = _mock_client()
956956
client.arecall.return_value = _mock_recall_response([])
957-
toolset = HindsightToolset(bank_id="test", client=client, auto_recall=True)
957+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_recall=True)
958958

959959
agent = MagicMock()
960960
agent.system_prompt = "base prompt"
@@ -969,12 +969,12 @@ def test_auto_recall_no_memories_passes_base_prompt(self):
969969

970970

971971
class TestToolsetAutoRetain:
972-
"""Test auto-retain behavior in HindsightToolset.run()."""
972+
"""Test auto-retain behavior in HindsightMemoryWrapper.run()."""
973973

974974
def test_auto_retain_stores_user_and_assistant_messages(self):
975975
client = _mock_client()
976976
client.aretain.return_value = _mock_retain_response()
977-
toolset = HindsightToolset(bank_id="test", client=client, auto_retain=True)
977+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_retain=True)
978978

979979
agent = MagicMock()
980980
agent.system_prompt = None
@@ -995,7 +995,7 @@ def test_auto_retain_stores_user_and_assistant_messages(self):
995995
def test_auto_retain_includes_role_metadata(self):
996996
client = _mock_client()
997997
client.aretain.return_value = _mock_retain_response()
998-
toolset = HindsightToolset(bank_id="test", client=client, auto_retain=True)
998+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_retain=True)
999999

10001000
agent = MagicMock()
10011001
agent.system_prompt = None
@@ -1017,7 +1017,7 @@ def test_auto_retain_includes_role_metadata(self):
10171017
def test_auto_retain_skips_system_messages(self):
10181018
client = _mock_client()
10191019
client.aretain.return_value = _mock_retain_response()
1020-
toolset = HindsightToolset(bank_id="test", client=client, auto_retain=True)
1020+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_retain=True)
10211021

10221022
agent = MagicMock()
10231023
agent.system_prompt = None
@@ -1040,7 +1040,7 @@ def test_auto_retain_skips_system_messages(self):
10401040

10411041
def test_auto_retain_disabled_by_default(self):
10421042
client = _mock_client()
1043-
toolset = HindsightToolset(bank_id="test", client=client)
1043+
toolset = HindsightMemoryWrapper(bank_id="test", client=client)
10441044

10451045
agent = MagicMock()
10461046
agent.system_prompt = None
@@ -1055,7 +1055,7 @@ def test_auto_retain_disabled_by_default(self):
10551055
def test_auto_retain_handles_error_gracefully(self):
10561056
client = _mock_client()
10571057
client.aretain.side_effect = RuntimeError("connection refused")
1058-
toolset = HindsightToolset(bank_id="test", client=client, auto_retain=True)
1058+
toolset = HindsightMemoryWrapper(bank_id="test", client=client, auto_retain=True)
10591059

10601060
agent = MagicMock()
10611061
agent.system_prompt = None
@@ -1077,7 +1077,7 @@ def test_both_auto_recall_and_retain(self):
10771077
client = _mock_client()
10781078
client.arecall.return_value = _mock_recall_response(["remembered fact"])
10791079
client.aretain.return_value = _mock_retain_response()
1080-
toolset = HindsightToolset(
1080+
toolset = HindsightMemoryWrapper(
10811081
bank_id="test",
10821082
client=client,
10831083
auto_recall=True,

0 commit comments

Comments
 (0)