Spaces:
Sleeping
Sleeping
| """Hermes tool-calling memory round-trip (no live server needed).""" | |
| import pytest | |
| from server import memory, tools | |
| def _clean(): | |
| memory.reset() | |
| yield | |
| memory.reset() | |
| def test_dispatch_remembers(): | |
| out = tools.dispatch("remember", '{"text":"Dana is the soccer coach","kind":"contact"}') | |
| assert "remembered" in out | |
| assert any("Dana" in f["text"] for f in memory.list_facts()) | |
| def test_dispatch_unknown_tool(): | |
| assert "unknown tool" in tools.dispatch("nope", "{}") | |
| def test_dispatch_handles_dict_args(): | |
| tools.dispatch("remember", {"text": "default location is Lincoln Elementary", "kind": "location"}) | |
| assert any("Lincoln" in f["text"] for f in memory.list_facts()) | |
| def test_run_with_tools_round_trip(): | |
| # Fake server: first turn calls `remember`, second returns the final JSON. | |
| calls = {"n": 0} | |
| def fake_post(msgs): | |
| calls["n"] += 1 | |
| if calls["n"] == 1: | |
| return {"choices": [{"message": {"role": "assistant", "tool_calls": [ | |
| {"id": "t1", "function": { | |
| "name": "remember", | |
| "arguments": '{"text":"you decline Mondays","kind":"preference"}'}}]}}]} | |
| return {"choices": [{"message": {"role": "assistant", "content": '{"events":[]}'}}]} | |
| content, _ = tools.run_with_tools([{"role": "user", "content": "hi"}], fake_post) | |
| assert content == '{"events":[]}' | |
| assert calls["n"] == 2 # one tool round, then the final answer | |
| assert any("Mondays" in f["text"] for f in memory.list_facts()) | |
| def test_run_with_tools_no_tool_calls_returns_immediately(): | |
| def fake_post(msgs): | |
| return {"choices": [{"message": {"content": "{}"}}]} | |
| content, _ = tools.run_with_tools([{"role": "user", "content": "hi"}], fake_post) | |
| assert content == "{}" | |