Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion src/agents/realtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ async def _function_needs_approval(
self._context_wrapper,
parsed_args,
tool_call.call_id,
strict=False,
)

def _build_tool_approval_item(
Expand Down
18 changes: 17 additions & 1 deletion tests/realtime/test_session_approvals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import agents._debug as _debug
from agents._tool_identity import get_function_tool_lookup_key_for_tool
from agents.exceptions import ModelBehaviorError
from agents.exceptions import ModelBehaviorError, UserError
from agents.realtime.agent import RealtimeAgent
from agents.realtime.events import (
RealtimeToolApprovalRequired,
Expand Down Expand Up @@ -86,6 +86,22 @@ async def test_approval_resume_uses_pending_initial_settings_dispatch_snapshot(
finally:
await session.__aexit__(None, None, None)

@pytest.mark.asyncio
async def test_invalid_function_tool_needs_approval_raises(
self, mock_model, mock_agent, mock_function_tool
) -> None:
mock_function_tool.needs_approval = "always" # type: ignore[assignment]
mock_agent.get_all_tools.return_value = [mock_function_tool]
session = RealtimeSession(mock_model, mock_agent, None)
tool_call_event = RealtimeModelToolCallEvent(
name="test_function", call_id="call_invalid_approval", arguments="{}"
)

with pytest.raises(UserError, match="needs_approval"):
await session._handle_tool_call(tool_call_event)

assert mock_function_tool.on_invoke_tool.call_count == 0

@pytest.mark.asyncio
async def test_function_tool_needs_approval_emits_event(
self, mock_model, mock_agent, mock_function_tool
Expand Down