77from plugins .chat_with_data_plugin import ChatWithDataPlugin
88from services .chat_service import ChatService
99
10+ from common .config .config import Config
11+
1012
1113class ConversationAgentFactory :
1214 _lock = asyncio .Lock ()
@@ -16,11 +18,13 @@ class ConversationAgentFactory:
1618 async def get_agent (cls ) -> AzureAIAgent :
1719 async with cls ._lock :
1820 if cls ._agent is None :
21+ config = Config ()
22+ solution_name = config .solution_name
1923 ai_agent_settings = AzureAIAgentSettings ()
2024 creds = DefaultAzureCredential ()
2125 client = AzureAIAgent .create_client (credential = creds , endpoint = ai_agent_settings .endpoint )
2226
23- agent_name = "KM-ConversationKnowledgeAgent"
27+ agent_name = f "KM-ConversationKnowledgeAgent- { solution_name } "
2428 agent_instructions = '''You are a helpful assistant.
2529 Always return the citations as is in final response.
2630 Always return citation markers exactly as they appear in the source data, placed in the "answer" field at the correct location. Do not modify, convert, or simplify these markers.
@@ -48,14 +52,15 @@ async def get_agent(cls) -> AzureAIAgent:
4852
4953 @classmethod
5054 async def delete_agent (cls ):
51- if cls ._agent is not None :
52- thread_cache = getattr (ChatService , "thread_cache" , None )
53- if thread_cache is not None :
54- for conversation_id , thread_id in list (thread_cache .items ()):
55- try :
56- thread = AzureAIAgentThread (client = cls ._agent .client , thread_id = thread_id )
57- await thread .delete ()
58- except Exception as e :
59- print (f"Failed to delete thread { thread_id } for conversation { conversation_id } : { e } " , flush = True )
60- await cls ._agent .client .agents .delete_agent (cls ._agent .id )
61- cls ._agent = None
55+ async with cls ._lock :
56+ if cls ._agent is not None :
57+ thread_cache = getattr (ChatService , "thread_cache" , None )
58+ if thread_cache is not None :
59+ for conversation_id , thread_id in list (thread_cache .items ()):
60+ try :
61+ thread = AzureAIAgentThread (client = cls ._agent .client , thread_id = thread_id )
62+ await thread .delete ()
63+ except Exception as e :
64+ print (f"Failed to delete thread { thread_id } for conversation { conversation_id } : { e } " , flush = True )
65+ await cls ._agent .client .agents .delete_agent (cls ._agent .id )
66+ cls ._agent = None
0 commit comments