Skip to content

Commit eeeccb4

Browse files
ymuichiromoonbox3
andauthored
Python: Respect FunctionChoiceBehavior filters in OpenAI responses agent tools (#13235)
issue: #13234 ## Summary - honor FunctionChoiceBehavior filters when retrieving kernel function metadata ### Contribution Checklist - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
1 parent 2435461 commit eeeccb4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,19 @@ def _get_tools(
12141214
if agent.tools:
12151215
tools.extend(agent.tools)
12161216

1217-
# TODO(evmattso): make sure to respect filters on FCB
1218-
if kernel.plugins:
1219-
funcs = kernel.get_full_list_of_function_metadata()
1220-
tools.extend([kernel_function_metadata_to_response_function_call_format(f) for f in funcs])
1217+
if not function_choice_behavior.enable_kernel_functions:
1218+
return tools
1219+
1220+
if not kernel.plugins:
1221+
return tools
1222+
1223+
funcs = (
1224+
kernel.get_list_of_function_metadata(function_choice_behavior.filters)
1225+
if function_choice_behavior.filters
1226+
else kernel.get_full_list_of_function_metadata()
1227+
)
1228+
1229+
tools.extend([kernel_function_metadata_to_response_function_call_format(f) for f in funcs])
12211230

12221231
return tools
12231232

python/tests/unit/agents/openai_responses/test_openai_responses_thread_actions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from semantic_kernel.agents.open_ai.openai_responses_agent import OpenAIResponsesAgent
1717
from semantic_kernel.agents.open_ai.responses_agent_thread_actions import ResponsesAgentThreadActions
18+
from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior
1819
from semantic_kernel.contents.chat_message_content import ChatMessageContent
1920
from semantic_kernel.contents.streaming_chat_message_content import StreamingChatMessageContent
2021
from semantic_kernel.contents.streaming_text_content import StreamingTextContent
@@ -499,11 +500,11 @@ async def mock_invoke_function_call(*args, **kwargs):
499500

500501
def test_get_tools(mock_agent, kernel, custom_plugin_class):
501502
kernel.add_plugin(custom_plugin_class)
502-
503+
fcb = FunctionChoiceBehavior()
503504
tools = ResponsesAgentThreadActions._get_tools(
504505
agent=mock_agent,
505506
kernel=kernel,
506-
function_choice_behavior=MagicMock(),
507+
function_choice_behavior=fcb,
507508
)
508509

509510
assert len(tools) == len(mock_agent.tools) + len(kernel.get_full_list_of_function_metadata())

0 commit comments

Comments
 (0)