|
8 | 8 | try: |
9 | 9 | from azure.ai.projects import AIProjectClient # type: ignore |
10 | 10 | from azure.identity import DefaultAzureCredential # type: ignore |
| 11 | + from services.azure_auth import get_default_credential, get_inference_credential # type: ignore |
11 | 12 | _REMOTE_AVAILABLE = True |
12 | 13 | except Exception: |
13 | 14 | _REMOTE_AVAILABLE = False |
@@ -112,11 +113,32 @@ def __init__(self, agent_id: str, project_endpoint: str = None): |
112 | 113 | project_endpoint: Optional project endpoint (reads from env if not provided) |
113 | 114 | """ |
114 | 115 | self.agent_id = agent_id |
115 | | - self.project_endpoint = project_endpoint or os.environ.get("AZURE_AI_AGENT_ENDPOINT") |
116 | | - |
117 | | - if not self.project_endpoint or not _REMOTE_AVAILABLE: |
| 116 | + |
| 117 | + raw_endpoint = ( |
| 118 | + project_endpoint |
| 119 | + or os.environ.get("AZURE_AI_AGENT_ENDPOINT") |
| 120 | + or os.environ.get("AZURE_AI_PROJECT_ENDPOINT") |
| 121 | + or os.environ.get("AZURE_AI_FOUNDRY_ENDPOINT") |
| 122 | + ) |
| 123 | + if not raw_endpoint or not _REMOTE_AVAILABLE: |
118 | 124 | raise ValueError("Remote agent support unavailable (endpoint or SDK missing)") |
119 | | - self.client = AIProjectClient(endpoint=self.project_endpoint, credential=DefaultAzureCredential()) |
| 125 | + |
| 126 | + # The Azure AI Projects SDK expects: https://<hub>.services.ai.azure.com/api/projects/<project> |
| 127 | + project_name = os.environ.get("AZURE_AI_PROJECT_NAME") |
| 128 | + normalized = raw_endpoint.replace("cognitiveservices.azure.com", "services.ai.azure.com") |
| 129 | + |
| 130 | + if "/api/projects/" in normalized: |
| 131 | + # Already a full project endpoint |
| 132 | + full_project_endpoint = normalized.rstrip("/") |
| 133 | + elif project_name: |
| 134 | + base_endpoint = normalized.split("/api/")[0].rstrip("/") |
| 135 | + full_project_endpoint = f"{base_endpoint}/api/projects/{project_name}" |
| 136 | + else: |
| 137 | + # Best-effort fallback (may still work if the caller provided a full endpoint) |
| 138 | + full_project_endpoint = normalized.rstrip("/") |
| 139 | + |
| 140 | + self.project_endpoint = full_project_endpoint |
| 141 | + self.client = AIProjectClient(endpoint=self.project_endpoint, credential=get_default_credential()) |
120 | 142 |
|
121 | 143 | def run_conversation_with_text_stream( |
122 | 144 | self, |
|
0 commit comments