Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions areal/experimental/openai/proxy/proxy_rollout_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ def _setup_openai_client():
# any attacker who can reach this port can call admin endpoints
# (grant_capacity, start_session, export_trajectories, ...).
loopback_hosts = {"127.0.0.1", "::1", "localhost"}
allow_override = (
os.environ.get("AREAL_ALLOW_DEFAULT_ADMIN_KEY", "0") == "1"
)
allow_override = os.environ.get("AREAL_ALLOW_DEFAULT_ADMIN_KEY", "0") == "1"
if _server_host in loopback_hosts or allow_override:
logger.warning(
"Using default admin API key. Change 'admin_api_key' in "
Expand Down
21 changes: 21 additions & 0 deletions examples/tir/tests/test_tir.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ async def test_tool_manager():
await calc_manager.acleanup()


@pytest.mark.asyncio
async def test_tool_manager_error_handling():
"""Test tool manager error handling with real execution"""
python_manager = ToolManager(timeout=10, enabled_tools="python", debug_mode=False)

try:
# Test ZeroDivisionError
zero_result, zero_status = await python_manager.aexecute_tool_call(
"```python\n1 / 0\n```"
)
print(f"Zero division result: {zero_result}, status: {zero_status}")
assert zero_status == ToolCallStatus.ERROR
assert (
"division by zero" in zero_result.lower()
or "zerodivisionerror" in zero_result.lower()
)

finally:
await python_manager.acleanup()


@pytest.mark.asyncio
async def test_tir_workflow():
"""Test TIR workflow initialization."""
Expand Down
11 changes: 8 additions & 3 deletions examples/tir/tools/python_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,14 @@ def execute(self, parameters: dict[str, Any]) -> tuple[str, ToolCallStatus]:

try:
# Directly call apply to avoid using ProcessPool in async environment
result = self.python_executor.apply(code)
logger.debug(f"Python execution completed: {str(result)[:100]}...")
return str(result), ToolCallStatus.SUCCESS
res, report = self.python_executor.apply(code)

if report != "Done":
logger.error(f"Error in Python execution: {report}")
return f"Error: {report}", ToolCallStatus.ERROR

logger.debug(f"Python execution completed: {str(res)[:100]}...")
return str(res), ToolCallStatus.SUCCESS
except Exception as e:
logger.error(f"Python execution error: {e}")
return f"Error: {str(e)}", ToolCallStatus.ERROR
Loading