diff --git a/sdk/ai/azure-ai-agents/samples/agents_async/utils/user_async_functions.py b/sdk/ai/azure-ai-agents/samples/agents_async/utils/user_async_functions.py index 202efe8b5df9..7ffd3cb3cf6c 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_async/utils/user_async_functions.py +++ b/sdk/ai/azure-ai-agents/samples/agents_async/utils/user_async_functions.py @@ -13,12 +13,12 @@ from azure.ai.agents.telemetry import trace_function -# Add parent directory to sys.path to import user_functions +# Add package directory to sys.path to import user_functions current_dir = os.path.dirname(os.path.abspath(__file__)) -parent_dir = os.path.abspath(os.path.join(current_dir, "..", "..", "..")) -if parent_dir not in sys.path: - sys.path.insert(0, parent_dir) -from samples.utils.user_functions import fetch_current_datetime, fetch_weather, send_email +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) +from samples.utils.user_functions import fetch_weather, send_email async def send_email_async(recipient: str, subject: str, body: str) -> str: diff --git a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_functions.py b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_functions.py index e16a99df53a7..7aeb75ead787 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_functions.py +++ b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_functions.py @@ -40,10 +40,11 @@ ) from azure.identity import DefaultAzureCredential -current_path = os.path.dirname(__file__) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -if root_path not in sys.path: - sys.path.insert(0, root_path) +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import user_functions project_client = AIProjectClient( diff --git a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_toolset.py b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_toolset.py index b355baefac05..83e3423b14d6 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_toolset.py +++ b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_toolset.py @@ -38,10 +38,11 @@ import os, sys from typing import Any -current_path = os.path.dirname(__file__) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -if root_path not in sys.path: - sys.path.insert(0, root_path) +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import user_functions project_client = AIProjectClient( diff --git a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_functions.py b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_functions.py index bc5646270da8..8169664f6297 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_functions.py +++ b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_functions.py @@ -41,10 +41,11 @@ ) from azure.identity import DefaultAzureCredential -current_path = os.path.dirname(__file__) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -if root_path not in sys.path: - sys.path.insert(0, root_path) +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import user_functions project_client = AIProjectClient( diff --git a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_toolset.py b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_toolset.py index 4562c7bfa381..0a515f38f25f 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_toolset.py +++ b/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_iteration_with_toolset.py @@ -35,10 +35,11 @@ from azure.ai.agents.models import FunctionTool, ToolSet from azure.identity import DefaultAzureCredential -current_path = os.path.dirname(__file__) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -if root_path not in sys.path: - sys.path.insert(0, root_path) +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import user_functions project_client = AIProjectClient( diff --git a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_auto_function_call.py b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_auto_function_call.py index a1a9ee49a697..ecbc6179b0aa 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_auto_function_call.py +++ b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_auto_function_call.py @@ -27,6 +27,12 @@ from azure.ai.projects import AIProjectClient from azure.identity import DefaultAzureCredential from azure.ai.agents.models import FunctionTool + +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import user_functions project_client = AIProjectClient( diff --git a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_functions.py b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_functions.py index fd712a5f5342..573fb800cd7c 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_functions.py +++ b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_functions.py @@ -32,10 +32,11 @@ ToolOutput, ) -current_path = os.path.dirname(__file__) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -if root_path not in sys.path: - sys.path.insert(0, root_path) +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import user_functions project_client = AIProjectClient( diff --git a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_logic_apps.py b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_logic_apps.py index d0a9590f822e..5aae90f30303 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_logic_apps.py +++ b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_logic_apps.py @@ -44,11 +44,11 @@ from azure.ai.agents.models import ToolSet, FunctionTool from azure.identity import DefaultAzureCredential -# Example user function -current_path = os.path.dirname(__file__) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -if root_path not in sys.path: - sys.path.insert(0, root_path) +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import fetch_current_datetime # Import AzureLogicAppTool and the function factory from user_logic_apps diff --git a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_run_with_toolset.py b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_run_with_toolset.py index b6c86a10b28d..ad35860fda53 100644 --- a/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_run_with_toolset.py +++ b/sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_run_with_toolset.py @@ -27,10 +27,11 @@ from azure.identity import DefaultAzureCredential from azure.ai.agents.models import FunctionTool, ToolSet, CodeInterpreterTool -current_path = os.path.dirname(__file__) -root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) -if root_path not in sys.path: - sys.path.insert(0, root_path) +# Add package directory to sys.path to import user_functions +current_dir = os.path.dirname(os.path.abspath(__file__)) +package_dir = os.path.abspath(os.path.join(current_dir, os.pardir, os.pardir)) +if package_dir not in sys.path: + sys.path.insert(0, package_dir) from samples.utils.user_functions import user_functions project_client = AIProjectClient(