mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-08 08:11:38 +00:00
Merge pull request #28914 from justincc/fix/fix-blank-tool-names-at-msg-construction
fix blank tool_name entries in state.db and JSON session logs
This commit is contained in:
commit
2b41f9d893
6 changed files with 99 additions and 39 deletions
45
tests/run_agent/test_tool_name_db_persistence.py
Normal file
45
tests/run_agent/test_tool_name_db_persistence.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""Test that tool_name is correctly persisted to the session DB for tool-result messages.
|
||||
|
||||
make_tool_result_message() sets tool_name on every tool-result dict at construction
|
||||
time. This test verifies that the value survives the flush path into the session DB.
|
||||
"""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from run_agent import AIAgent
|
||||
from agent.tool_dispatch_helpers import make_tool_result_message
|
||||
|
||||
|
||||
def _make_agent(session_db):
|
||||
with (
|
||||
patch("run_agent.get_tool_definitions", return_value=[]),
|
||||
patch("run_agent.check_toolset_requirements", return_value={}),
|
||||
patch("run_agent.OpenAI"),
|
||||
):
|
||||
return AIAgent(
|
||||
api_key="test-key",
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
quiet_mode=True,
|
||||
skip_context_files=True,
|
||||
skip_memory=True,
|
||||
session_db=session_db,
|
||||
)
|
||||
|
||||
|
||||
def test_tool_name_persisted_to_session_db():
|
||||
"""tool_name set by make_tool_result_message must be passed through to
|
||||
append_message so the column is populated on first flush to the session DB."""
|
||||
session_db = MagicMock()
|
||||
agent = _make_agent(session_db)
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "run a command"},
|
||||
make_tool_result_message("terminal", "$ ls\nfile.txt", "c1"),
|
||||
]
|
||||
agent._flush_messages_to_session_db(messages)
|
||||
|
||||
tool_appends = [
|
||||
c for c in session_db.append_message.call_args_list
|
||||
if c.kwargs.get("role") == "tool"
|
||||
]
|
||||
assert len(tool_appends) == 1
|
||||
assert tool_appends[0].kwargs["tool_name"] == "terminal"
|
||||
|
|
@ -267,6 +267,23 @@ class TestMessageStorage:
|
|||
).fetchone()
|
||||
assert row["content"] == "plain text"
|
||||
|
||||
def test_replace_messages_persists_tool_name(self, db):
|
||||
"""`replace_messages` (used by /retry, /undo, /compress) must write
|
||||
tool_name to the DB for messages built by make_tool_result_message."""
|
||||
from agent.tool_dispatch_helpers import make_tool_result_message
|
||||
db.create_session(session_id="s1", source="cli")
|
||||
db.replace_messages(
|
||||
"s1",
|
||||
[
|
||||
{"role": "user", "content": "do something"},
|
||||
make_tool_result_message("web_search", "some results", "c1"),
|
||||
],
|
||||
)
|
||||
|
||||
msgs = db.get_messages("s1")
|
||||
tool_msg = next(m for m in msgs if m["role"] == "tool")
|
||||
assert tool_msg["tool_name"] == "web_search"
|
||||
|
||||
def test_replace_messages_handles_multimodal_content(self, db):
|
||||
"""`replace_messages` (used by /retry, /undo, /compress) must also
|
||||
handle list content without crashing."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue