Skip to content

Commit ca80767

Browse files
committed
Pass project_endpoint to agent constructors
Updated agent creation logic to explicitly pass the Azure AI project endpoint from config to agent constructors. Refactored AzureAgentBase to accept project_endpoint as an argument instead of reading from the environment variable. Also enabled Azure Search connection lookup in FoundryAgentTemplate.
1 parent 656f4c8 commit ca80767

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/backend/common/utils/utils_af.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async def create_RAI_agent() -> FoundryAgentTemplate:
3333
agent_instructions=agent_instructions,
3434
model_deployment_name=model_deployment_name,
3535
enable_code_interpreter=False,
36+
project_endpoint=config.AZURE_AI_PROJECT_ENDPOINT,
3637
mcp_config=None,
3738
search_config=None,
3839
)

src/backend/v4/magentic_agents/common/lifecycle.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,22 @@ class AzureAgentBase(MCPEnabledBase):
111111
- optionally register themselves via agent_registry
112112
"""
113113

114-
def __init__(self, mcp: MCPConfig | None = None, model_deployment_name: str | None = None) -> None:
114+
def __init__(self, mcp: MCPConfig | None = None, model_deployment_name: str | None = None, project_endpoint: str | None = None) -> None:
115115
super().__init__(mcp=mcp)
116116
self.creds: Optional[DefaultAzureCredential] = None
117117
self.client: Optional[AzureAIAgentClient] = None
118-
self.project_endpoint: Optional[str] = None
118+
119119
self._created_ephemeral: bool = (
120120
False # reserved if you add ephemeral agent cleanup
121121
)
122+
self.project_endpoint = project_endpoint
122123
self.model_deployment_name = model_deployment_name
123124

124125
async def open(self) -> "AzureAgentBase":
125126
if self._stack is not None:
126127
return self
127128
self._stack = AsyncExitStack()
128129

129-
# Resolve Azure AI Project endpoint (mirrors old SK env var usage)
130-
self.project_endpoint = os.getenv("AZURE_AI_PROJECT_ENDPOINT")
131-
if not self.project_endpoint:
132-
raise RuntimeError(
133-
"AZURE_AI_PROJECT_ENDPOINT environment variable is required for AzureAgentBase."
134-
)
135130

136131
# Acquire credential
137132
self.creds = DefaultAzureCredential()

src/backend/v4/magentic_agents/foundry_agent.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ def __init__(
3333
agent_description: str,
3434
agent_instructions: str,
3535
model_deployment_name: str,
36+
project_endpoint: str,
3637
enable_code_interpreter: bool = False,
3738
mcp_config: MCPConfig | None = None,
3839
search_config: SearchConfig | None = None,
3940
) -> None:
40-
super().__init__(mcp=mcp_config, model_deployment_name=model_deployment_name)
41+
super().__init__(mcp=mcp_config, model_deployment_name=model_deployment_name, project_endpoint=project_endpoint)
4142
self.agent_name = agent_name
4243
self.agent_description = agent_description
4344
self.agent_instructions = agent_instructions
@@ -110,10 +111,10 @@ async def _create_azure_search_enabled_client(self):
110111
query_type = getattr(self.search, "search_query_type", "vector")
111112

112113
# ai_search_conn_id = ""
113-
# async for connection in self.client.project_client.connections.list():
114-
# if connection.type == ConnectionType.AZURE_AI_SEARCH:
115-
# ai_search_conn_id = connection.id
116-
# break
114+
async for connection in self.client.project_client.connections.list():
115+
if connection.type == ConnectionType.AZURE_AI_SEARCH:
116+
connection_id = connection.id
117+
break
117118
if not connection_id or not index_name:
118119
self.logger.error(
119120
"Missing azure_search_connection_id or azure_search_index_name in search_config; aborting Azure Search path."

src/backend/v4/magentic_agents/magentic_agent_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ async def create_agent_from_config(self, user_id: str, agent_obj: SimpleNamespac
118118
agent_instructions=getattr(agent_obj, "system_message", ""),
119119
model_deployment_name=deployment_name,
120120
enable_code_interpreter=getattr(agent_obj, "coding_tools", False),
121+
project_endpoint=config.AZURE_AI_PROJECT_ENDPOINT,
121122
mcp_config=mcp_config,
122123
search_config=search_config,
123124
)

0 commit comments

Comments
 (0)