mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-09 17:08:29 +00:00
Coerce memory load numeric args
Normalize memory_load threshold and limit values from model calls before vector search so numeric strings from Responses tool arguments do not reach FAISS unchanged. Add a focused regression covering string threshold/limit values and document the memory plugin contract.
This commit is contained in:
parent
0b38258d6c
commit
b07d142938
3 changed files with 56 additions and 0 deletions
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
- Keep memory scoped by configured subdirectory/context.
|
||||
- Preserve embedding metadata needed to rebuild indexes safely.
|
||||
- `memory_load` accepts numeric `threshold` and `limit` values as native numbers or numeric strings and coerces them before vector search.
|
||||
- Avoid storing transient action-history noise as durable memory.
|
||||
|
||||
## Work Guidance
|
||||
|
|
|
|||
|
|
@ -8,6 +8,13 @@ DEFAULT_LIMIT = 10
|
|||
class MemoryLoad(Tool):
|
||||
|
||||
async def execute(self, query="", threshold=DEFAULT_THRESHOLD, limit=DEFAULT_LIMIT, filter="", **kwargs):
|
||||
if threshold is None or threshold == "":
|
||||
threshold = DEFAULT_THRESHOLD
|
||||
if limit is None or limit == "":
|
||||
limit = DEFAULT_LIMIT
|
||||
threshold = float(threshold)
|
||||
limit = int(limit)
|
||||
|
||||
db = await Memory.get(self.agent)
|
||||
docs = await db.search_similarity_threshold(query=query, limit=limit, threshold=threshold, filter=filter)
|
||||
|
||||
|
|
|
|||
|
|
@ -548,6 +548,54 @@ def test_memory_forget_tool_imports_plugin_memory_load(monkeypatch):
|
|||
]
|
||||
|
||||
|
||||
def test_memory_load_coerces_numeric_string_args(monkeypatch):
|
||||
_install_tool_stub(monkeypatch)
|
||||
monkeypatch.syspath_prepend(str(Path.cwd()))
|
||||
|
||||
class FakeDb:
|
||||
def __init__(self) -> None:
|
||||
self.calls = []
|
||||
|
||||
async def search_similarity_threshold(self, **kwargs):
|
||||
self.calls.append(kwargs)
|
||||
return []
|
||||
|
||||
fake_db = FakeDb()
|
||||
|
||||
async def get_memory(_agent):
|
||||
return fake_db
|
||||
|
||||
memory_stub = types.ModuleType("plugins._memory.helpers.memory")
|
||||
memory_stub.Memory = types.SimpleNamespace(get=get_memory)
|
||||
monkeypatch.setitem(sys.modules, "plugins._memory.helpers.memory", memory_stub)
|
||||
|
||||
sys.modules.pop("plugins._memory.tools.memory_load", None)
|
||||
module = importlib.import_module("plugins._memory.tools.memory_load")
|
||||
tool = module.MemoryLoad(
|
||||
_FakeAgent(),
|
||||
"memory_load",
|
||||
None,
|
||||
{
|
||||
"query": "smoke test project context",
|
||||
"threshold": "0.7",
|
||||
"limit": "3",
|
||||
},
|
||||
"",
|
||||
None,
|
||||
)
|
||||
|
||||
asyncio.run(tool.execute(**tool.args))
|
||||
|
||||
assert fake_db.calls == [
|
||||
{
|
||||
"query": "smoke test project context",
|
||||
"threshold": 0.7,
|
||||
"limit": 3,
|
||||
"filter": "",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_behaviour_adjustment_normalizes_duplicate_rules(monkeypatch):
|
||||
_install_tool_stub(monkeypatch)
|
||||
monkeypatch.syspath_prepend(str(Path.cwd()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue