Skip to content

Commit 3ab14b5

Browse files
committed
add comment how to get agents
1 parent ff36a2a commit 3ab14b5

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

src/backend/app_config.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -220,30 +220,41 @@ async def create_azure_ai_agent(
220220
if client is None:
221221
client = self.get_ai_project_client()
222222

223-
# First try to get an existing agent with this name as assistant_id
224-
try:
225-
226-
existing_definition = await client.agents.get_agent(agent_name)
227-
# Create the agent instance directly with project_client and existing definition
228-
agent = AzureAIAgent(
229-
client=client,
230-
definition=existing_definition,
231-
plugins=tools,
232-
)
233-
234-
return agent
235-
except Exception as e:
236-
# The Azure AI Projects SDK throws an exception when the agent doesn't exist
237-
# (not returning None), so we catch it and proceed to create a new agent
238-
if "ResourceNotFound" in str(e) or "404" in str(e):
239-
logging.info(
240-
f"Agent with ID {agent_name} not found. Will create a new one."
241-
)
242-
else:
243-
# Log unexpected errors but still try to create a new agent
244-
logging.warning(
245-
f"Unexpected error while retrieving agent {agent_name}: {str(e)}. Attempting to create new agent."
246-
)
223+
# # ToDo: This is the fixed code but commenting it out as agent clean up is no happening yet
224+
# # and there are multiple versions of agents due to testing
225+
# # First try to get an existing agent with this name as assistant_id
226+
# try:
227+
# agent_id = None
228+
# agent_list = await client.agents.list_agents()
229+
# for agent in agent_list.data:
230+
# if agent.name == agent_name:
231+
# agent_id = agent.id
232+
# break
233+
# # If the agent already exists, we can use it directly
234+
# # Get the existing agent definition
235+
# existing_definition = await client.agents.get_agent(agent_id)
236+
# # Create the agent instance directly with project_client and existing definition
237+
# agent = AzureAIAgent(
238+
# client=client,
239+
# definition=existing_definition,
240+
# plugins=tools,
241+
# )
242+
243+
# client.agents.list_agents()
244+
245+
# return agent
246+
# except Exception as e:
247+
# # The Azure AI Projects SDK throws an exception when the agent doesn't exist
248+
# # (not returning None), so we catch it and proceed to create a new agent
249+
# if "ResourceNotFound" in str(e) or "404" in str(e):
250+
# logging.info(
251+
# f"Agent with ID {agent_name} not found. Will create a new one."
252+
# )
253+
# else:
254+
# # Log unexpected errors but still try to create a new agent
255+
# logging.warning(
256+
# f"Unexpected error while retrieving agent {agent_name}: {str(e)}. Attempting to create new agent."
257+
# )
247258

248259
# Create the agent using the project client with the agent_name as both name and assistantId
249260
agent_definition = await client.agents.create_agent(

0 commit comments

Comments
 (0)