Skip to content

fix blank tool_name entries in state.db and JSON session logs - #28914

Merged
ethernet8023 merged 1 commit into
NousResearch:mainfrom
justincc:fix/fix-blank-tool-names-at-msg-construction
May 19, 2026
Merged

fix blank tool_name entries in state.db and JSON session logs#28914
ethernet8023 merged 1 commit into
NousResearch:mainfrom
justincc:fix/fix-blank-tool-names-at-msg-construction

Conversation

@justincc

@justincc justincc commented May 19, 2026

Copy link
Copy Markdown

What does this PR do?

This PR fixes blank tool_name entries in state.db and JSON session logs. It refactors the tool message construction for the OpenAI format at 6 sites and adds "tool_name" to the message. This doesn't cause any problems for the existing code but means that session persistence can pick it up.

The alternative would have been to check for both "name" and "tool_name" at various persistence points - some existing code already does this. But that seems a fragile solution if downstream code is changed or new peristence paths added - that kind of thing might have caused this very bug!

Related Issue

Fixes #28915

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/tool_dispatch_helpers.py — adds make_tool_result_message(name, content, tool_call_id) factory and exports it via __all__
  • agent/tool_executor.py — all four tool-result construction sites (sequential normal, sequential interrupt skip, concurrent normal, concurrent interrupt skip) replaced with make_tool_result_message
  • agent/agent_runtime_helpers.py — repair/rewrite path updated to use make_tool_result_message
  • mini_swe_runner.py — tool response construction updated; also adds the missing "name" field which was previously absent entirely
  • tests/run_agent/test_tool_name_db_persistence.py — new test verifying tool_name survives the flush path into the session DB
  • tests/test_hermes_state.py — new test verifying tool_name is correctly written by replace_messages (used by /retry, /undo, /compress)

How to Test

  1. Run hermes and send a prompt that triggers a tool call (e.g. ask it to run a terminal command or search the web)
  2. After the response completes, query the session DB:
sqlite3 ~/.hermes/state.db
SELECT role, tool_name, substr(content,1,80) FROM messages ORDER BY timestamp DESC LIMIT 5;
  1. The role = 'tool' row should have tool_name populated with the function name rather than NULL

Also added tests:

  • tests/run_agent/test_tool_name_db_persistence.py — new file; tests that tool_name set by make_tool_result_message survives the flush path into the session DB (_flush_messages_to_session_db)
  • tests/test_hermes_state.py — existing file; one new test added (test_replace_messages_persists_tool_name) to the TestMessageStorage class, covering the replace_messages path used by /retry, /undo, and /compress

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

Introduces make_tool_result_message() in tool_dispatch_helpers.py as the
single place where tool-result message dicts are built. All six construction
sites in tool_executor.py, agent_runtime_helpers.py, and mini_swe_runner.py
now use it, so tool_name is set in memory from the moment a message is
created rather than relying on fallback logic in the flush paths.

Fixes blank tool_name in both state.db and JSON session logs.

Adds tests.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 19, 2026

@ethernet8023 ethernet8023 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, ty for the fix!

@ethernet8023
ethernet8023 merged commit 2b41f9d into NousResearch:main May 19, 2026
@justincc

Copy link
Copy Markdown
Author

Thanks @ethernet8023 !

@justincc
justincc deleted the fix/fix-blank-tool-names-at-msg-construction branch May 19, 2026 20:52
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…l-names-at-msg-construction

fix blank tool_name entries in state.db and JSON session logs
Seven74AI pushed a commit to Seven74AI/hermes-agent that referenced this pull request Jun 13, 2026
…l-names-at-msg-construction

fix blank tool_name entries in state.db and JSON session logs
alt-glitch pushed a commit that referenced this pull request Jun 14, 2026
…sg-construction

fix blank tool_name entries in state.db and JSON session logs
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
…l-names-at-msg-construction

fix blank tool_name entries in state.db and JSON session logs
liuchanchen pushed a commit to liuchanchen/hermes-agent that referenced this pull request Jun 23, 2026
…l-names-at-msg-construction

fix blank tool_name entries in state.db and JSON session logs
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…l-names-at-msg-construction

fix blank tool_name entries in state.db and JSON session logs
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…l-names-at-msg-construction

fix blank tool_name entries in state.db and JSON session logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: tool_name is blank in state.db

4 participants