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
32 changes: 20 additions & 12 deletions sdk/ai/azure-ai-projects/tests/agents/test_agents_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# cSpell:disable
import json
import io
import openai
from test_base import TestBase, servicePreparer
from devtools_testutils import recorded_by_proxy, RecordedTransport
from azure.ai.projects.models import PromptAgentDefinition, AgentDetails, AgentVersionDetails
Expand Down Expand Up @@ -141,7 +142,15 @@ def test_agent_disable_enable(self, **kwargs):

# Setup
project_client = self.create_client(operation_group="agents", **kwargs)
openai_client = project_client.get_openai_client()
# Intentionally use Agent Endpoint here for Responses calls (by giving `agent_name`). Async tests will use Project
# endpoint instead, so we cover both endpoint.
openai_client = project_client.get_openai_client(agent_name=agent_name)

# Delete any existing agent from previous test runs (ignore failures)
try:
project_client.agents.delete(agent_name=agent_name)
except Exception:
pass

# Create an Agent
agent = project_client.agents.create_version(
Expand Down Expand Up @@ -173,17 +182,16 @@ def test_agent_disable_enable(self, **kwargs):
print(f"Agent disabled")

# Verify requests fail when agent is disabled
# TODO: Why does this call succeed, even though the Agent is disabled?
# error_raised = False
# try:
# _ = openai_client.responses.create(
# conversation=conversation.id,
# extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
# )
# except Exception as e:
# error_raised = True
# print(f"Expected error when calling disabled agent: {e}")
# assert error_raised, "Expected an error when calling a disabled agent"
error_raised = False
try:
_ = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
except openai.PermissionDeniedError as e:
error_raised = True
print(f"Expected error when calling disabled agent: {e}")
assert error_raised, "Expected an error when calling a disabled agent"

# Enable the agent
project_client.agents.enable(agent_name=agent_name)
Expand Down
31 changes: 20 additions & 11 deletions sdk/ai/azure-ai-projects/tests/agents/test_agents_crud_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# cSpell:disable
import json
import io
import openai
from test_base import TestBase, servicePreparer
from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils import RecordedTransport
Expand Down Expand Up @@ -131,9 +132,18 @@ async def test_agent_disable_enable_async(self, **kwargs):

# Setup
project_client = self.create_async_client(operation_group="agents", **kwargs)
# Intentionally use Project Endpoint here for Responses calls (by not giving `agent_name`). Sync tests will use Agent
# endpoint instead, so we cover both endpoint.
openai_client = project_client.get_openai_client()

async with project_client:

# Delete any existing agent from previous test runs (ignore failures)
try:
await project_client.agents.delete(agent_name=agent_name)
except Exception:
pass

# Create an Agent
agent = await project_client.agents.create_version(
agent_name=agent_name,
Expand Down Expand Up @@ -164,17 +174,16 @@ async def test_agent_disable_enable_async(self, **kwargs):
print("Agent disabled")

# Verify requests fail when agent is disabled
# TODO: Why does this call succeed, even though the Agent is disabled?
# error_raised = False
# try:
# _ = await openai_client.responses.create(
# conversation=conversation.id,
# extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
# )
# except Exception as e:
# error_raised = True
# print(f"Expected error when calling disabled agent: {e}")
# assert error_raised, "Expected an error when calling a disabled agent"
error_raised = False
try:
_ = await openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
except openai.PermissionDeniedError as e:
error_raised = True
print(f"Expected error when calling disabled agent: {e}")
assert error_raised, "Expected an error when calling a disabled agent"

# Enable the agent
await project_client.agents.enable(agent_name=agent_name)
Expand Down
Loading