Skip to content

Commit 4e78066

Browse files
reverted template changes
1 parent 8bed648 commit 4e78066

1 file changed

Lines changed: 17 additions & 43 deletions

File tree

src/backend/api/agent/template_agent_factory.py

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,11 @@ async def create_or_get_agent(cls):
1818
Returns:
1919
object: The created agent instance.
2020
"""
21-
try:
22-
project_client = AIProjectClient(
23-
endpoint=app_settings.azure_ai.agent_endpoint,
24-
credential=await get_azure_credential_async(client_id=app_settings.base_settings.azure_client_id),
25-
api_version=app_settings.azure_ai.agent_api_version
26-
)
27-
28-
# Test the connection early to provide better error messages
29-
# Use a safer approach that doesn't fail if no agents exist
30-
agents_list = project_client.agents.list_agents()
31-
try:
32-
await agents_list.__anext__() # Try to get first agent
33-
except StopAsyncIteration:
34-
# This is expected if no agents exist - connection is working
35-
pass
36-
37-
except Exception as e:
38-
# Skip the "End of paging" error as it means connection is working but no agents exist
39-
if "End of paging" not in str(e):
40-
error_msg = f"Failed to connect to Azure AI Project endpoint '{app_settings.azure_ai.agent_endpoint}'. "
41-
error_msg += f"Original error: {str(e)}"
42-
43-
raise Exception(error_msg)
21+
project_client = AIProjectClient(
22+
endpoint=app_settings.azure_ai.agent_endpoint,
23+
credential=await get_azure_credential_async(),
24+
api_version=app_settings.azure_ai.agent_api_version
25+
)
4426

4527
agent_name = f"DG-TemplateAgent-{app_settings.base_settings.solution_name}"
4628
# 1. Check if the agent already exists
@@ -62,25 +44,17 @@ async def create_or_get_agent(cls):
6244
"titleField": "sourceurl",
6345
}
6446

65-
try:
66-
project_index = await project_client.indexes.create_or_update(
67-
name=index_name,
68-
version=index_version,
69-
body={
70-
"connectionName": app_settings.datasource.connection_name,
71-
"indexName": app_settings.datasource.index,
72-
"type": "AzureSearch",
73-
"fieldMapping": field_mapping
74-
}
75-
)
76-
except Exception as e:
77-
error_msg = f"Failed to create or update project index '{index_name}'. "
78-
error_msg += f"Connection name: {app_settings.datasource.connection_name}, "
79-
error_msg += f"Index: {app_settings.datasource.index}, "
80-
error_msg += f"Original error: {str(e)}"
81-
82-
raise Exception(error_msg)
83-
47+
project_index = await project_client.indexes.create_or_update(
48+
name=index_name,
49+
version=index_version,
50+
body={
51+
"connectionName": app_settings.datasource.connection_name,
52+
"indexName": app_settings.datasource.index,
53+
"type": "AzureSearch",
54+
"fieldMapping": field_mapping
55+
}
56+
)
57+
print("Project index created or updated.")
8458
ai_search = AzureAISearchTool(
8559
index_asset_id=f"{project_index.name}/versions/{project_index.version}",
8660
index_connection_id=None,
@@ -111,4 +85,4 @@ async def _delete_agent_instance(cls, agent_wrapper: dict):
11185
Args:
11286
agent_wrapper (dict): A dictionary containing the 'agent' and the corresponding 'client'.
11387
"""
114-
await agent_wrapper["client"].agents.delete_agent(agent_wrapper["agent"].id)
88+
await agent_wrapper["client"].agents.delete_agent(agent_wrapper["agent"].id)

0 commit comments

Comments
 (0)