fix(agent): set tool_name on tool-result messages at construction time

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.
This commit is contained in:
justincc 2026-05-19 20:24:30 +01:00
parent 7552e0f3c0
commit a61420952e
6 changed files with 99 additions and 39 deletions

View file

@ -38,6 +38,7 @@ from typing import List, Dict, Any, Optional, Literal
import fire
from dotenv import load_dotenv
from agent.tool_dispatch_helpers import make_tool_result_message
# Load environment variables
load_dotenv()
@ -536,11 +537,9 @@ Complete the user's task step by step."""
completed = True
# Add tool response
messages.append({
"role": "tool",
"content": result_json,
"tool_call_id": tc.id
})
messages.append(make_tool_result_message(
tc.function.name, result_json, tc.id,
))
print(f" ✅ exit_code={result['exit_code']}, output={len(result['output'])} chars")