mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
fix: require memory schema fields by action
This commit is contained in:
parent
ae1f058b3c
commit
5b24c0fa85
2 changed files with 62 additions and 0 deletions
39
tests/tools/test_memory_tool_schema.py
Normal file
39
tests/tools/test_memory_tool_schema.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import json
|
||||
from tools.memory_tool import MEMORY_SCHEMA
|
||||
|
||||
|
||||
def test_memory_schema_requires_content_and_old_text_for_replace_action():
|
||||
schema = MEMORY_SCHEMA["parameters"]
|
||||
assert schema["required"] == ["action", "target"]
|
||||
|
||||
all_of = schema.get("allOf")
|
||||
assert all_of, "memory schema should use conditional requirements"
|
||||
|
||||
replace_requirements = [
|
||||
branch["then"].get("required", [])
|
||||
for branch in all_of
|
||||
if branch.get("if", {}).get("properties", {}).get("action", {}).get("const") == "replace"
|
||||
]
|
||||
assert replace_requirements == [["old_text", "content"]]
|
||||
|
||||
|
||||
def test_memory_schema_requires_content_for_add_action():
|
||||
add_requirements = [
|
||||
branch["then"].get("required", [])
|
||||
for branch in MEMORY_SCHEMA["parameters"].get("allOf", [])
|
||||
if branch.get("if", {}).get("properties", {}).get("action", {}).get("const") == "add"
|
||||
]
|
||||
assert add_requirements == [["content"]]
|
||||
|
||||
|
||||
def test_memory_schema_requires_old_text_for_remove_action():
|
||||
remove_requirements = [
|
||||
branch["then"].get("required", [])
|
||||
for branch in MEMORY_SCHEMA["parameters"].get("allOf", [])
|
||||
if branch.get("if", {}).get("properties", {}).get("action", {}).get("const") == "remove"
|
||||
]
|
||||
assert remove_requirements == [["old_text"]]
|
||||
|
||||
|
||||
def test_memory_schema_is_json_serializable():
|
||||
json.dumps(MEMORY_SCHEMA)
|
||||
|
|
@ -560,6 +560,29 @@ MEMORY_SCHEMA = {
|
|||
},
|
||||
},
|
||||
"required": ["action", "target"],
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"properties": {"action": {"const": "add"}},
|
||||
"required": ["action"],
|
||||
},
|
||||
"then": {"required": ["content"]},
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {"action": {"const": "replace"}},
|
||||
"required": ["action"],
|
||||
},
|
||||
"then": {"required": ["old_text", "content"]},
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {"action": {"const": "remove"}},
|
||||
"required": ["action"],
|
||||
},
|
||||
"then": {"required": ["old_text"]},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue