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:
teknium1 2026-03-10 06:35:28 -07:00
parent a2ea85924a
commit 771969f747
3 changed files with 18 additions and 7 deletions

View file

@ -2839,7 +2839,10 @@ class AIAgent:
spinner.start()
_spinner_result = None
try:
function_result = handle_function_call(function_name, function_args, effective_task_id)
function_result = handle_function_call(
function_name, function_args, effective_task_id,
enabled_tools=list(self.valid_tool_names) if self.valid_tool_names else None,
)
_spinner_result = function_result
except Exception as tool_error:
function_result = f"Error executing tool '{function_name}': {tool_error}"
@ -2850,7 +2853,10 @@ class AIAgent:
spinner.stop(cute_msg)
else:
try:
function_result = handle_function_call(function_name, function_args, effective_task_id)
function_result = handle_function_call(
function_name, function_args, effective_task_id,
enabled_tools=list(self.valid_tool_names) if self.valid_tool_names else None,
)
except Exception as tool_error:
function_result = f"Error executing tool '{function_name}': {tool_error}"
logger.error("handle_function_call raised for %s: %s", function_name, tool_error, exc_info=True)