fix: wire up enabled_tools in agent loop + simplify sandbox tool selection
Completes the fix started in 8318a51 — handle_function_call() accepted
enabled_tools but run_agent.py never passed it. Now both call sites in
_execute_tool_calls() pass self.valid_tool_names, so each agent session
uses its own tool list instead of the process-global
_last_resolved_tool_names (which subagents can overwrite).
Also simplifies the redundant ternary in code_execution_tool.py:
sandbox_tools is already computed correctly (intersection with session
tools, or full SANDBOX_ALLOWED_TOOLS as fallback), so the conditional
was dead logic.
Inspired by PR #663 (JasonOA888). Closes #662.
Tests: 2857 passed.
This commit is contained in:
parent
a2ea85924a
commit
771969f747
3 changed files with 18 additions and 7 deletions
|
|
@ -601,7 +601,10 @@ class TestExecuteToolCalls:
|
|||
messages = []
|
||||
with patch("run_agent.handle_function_call", return_value="search result") as mock_hfc:
|
||||
agent._execute_tool_calls(mock_msg, messages, "task-1")
|
||||
mock_hfc.assert_called_once_with("web_search", {"q": "test"}, "task-1")
|
||||
# enabled_tools passes the agent's own valid_tool_names
|
||||
args, kwargs = mock_hfc.call_args
|
||||
assert args[:3] == ("web_search", {"q": "test"}, "task-1")
|
||||
assert set(kwargs.get("enabled_tools", [])) == agent.valid_tool_names
|
||||
assert len(messages) == 1
|
||||
assert messages[0]["role"] == "tool"
|
||||
assert "search result" in messages[0]["content"]
|
||||
|
|
@ -627,7 +630,9 @@ class TestExecuteToolCalls:
|
|||
with patch("run_agent.handle_function_call", return_value="ok") as mock_hfc:
|
||||
agent._execute_tool_calls(mock_msg, messages, "task-1")
|
||||
# Invalid JSON args should fall back to empty dict
|
||||
mock_hfc.assert_called_once_with("web_search", {}, "task-1")
|
||||
args, kwargs = mock_hfc.call_args
|
||||
assert args[:3] == ("web_search", {}, "task-1")
|
||||
assert set(kwargs.get("enabled_tools", [])) == agent.valid_tool_names
|
||||
assert len(messages) == 1
|
||||
assert messages[0]["role"] == "tool"
|
||||
assert messages[0]["tool_call_id"] == "c1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue