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
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,12 @@ def _separate_tool_calls(self, current_response, messages) -> tuple[list, list,
logger.debug(f"Choice message tool_calls: {choice.message.tool_calls}")

if choice.message.tool_calls and self.ctx.response_tools:
executed_tool_calls: list = []
has_deferred_or_denied = False
for tool_call in choice.message.tool_calls:
if is_function_tool_call(tool_call, self.ctx.response_tools):
function_tool_calls.append(tool_call)
executed_tool_calls.append(tool_call)
elif (
tool_call.function
and tool_call.function.name not in _SERVER_SIDE_BUILTIN_TOOL_NAMES
Expand All @@ -709,6 +712,7 @@ def _separate_tool_calls(self, current_response, messages) -> tuple[list, list,
"treating as a client-side function call."
)
function_tool_calls.append(tool_call)
executed_tool_calls.append(tool_call)
else:
if self._approval_required(tool_call.function.name):
approval_response = self.ctx.approval_response(
Expand All @@ -718,15 +722,25 @@ def _separate_tool_calls(self, current_response, messages) -> tuple[list, list,
if approval_response.approve:
logger.info(f"Approval granted for {tool_call.id} on {tool_call.function.name}")
non_function_tool_calls.append(tool_call)
executed_tool_calls.append(tool_call)
else:
logger.info(f"Approval denied for {tool_call.id} on {tool_call.function.name}")
next_turn_messages.pop()
has_deferred_or_denied = True
else:
logger.info(f"Requesting approval for {tool_call.id} on {tool_call.function.name}")
approvals.append(tool_call)
next_turn_messages.pop()
has_deferred_or_denied = True
else:
non_function_tool_calls.append(tool_call)
executed_tool_calls.append(tool_call)
if has_deferred_or_denied:
if executed_tool_calls:
next_turn_messages[-1] = OpenAIAssistantMessageParam(
content=choice.message.content,
tool_calls=executed_tool_calls,
)
else:
next_turn_messages.pop()

return function_tool_calls, non_function_tool_calls, approvals, next_turn_messages

Expand Down
Loading
Loading