@@ -21,39 +21,46 @@ def __new__(cls):
2121
2222 def __init__ (self ):
2323 if not self ._initialized :
24- # conversation_id -> agent_run_info
25- self .agent_runs : Dict [int , AgentRunInfo ] = {}
24+ # user_id: conversation_id -> agent_run_info
25+ self .agent_runs : Dict [str , AgentRunInfo ] = {}
2626 self ._initialized = True
2727
28- def register_agent_run (self , conversation_id : int , agent_run_info ):
28+ def _get_run_key (self , conversation_id : int , user_id : str ) -> str :
29+ """Generate unique key for agent run using user_id and conversation_id"""
30+ return f"{ user_id } :{ conversation_id } "
31+
32+ def register_agent_run (self , conversation_id : int , agent_run_info , user_id : str ):
2933 """register agent run instance"""
3034 with self ._lock :
31- self .agent_runs [conversation_id ] = agent_run_info
35+ run_key = self ._get_run_key (conversation_id , user_id )
36+ self .agent_runs [run_key ] = agent_run_info
3237 logger .info (
33- f"register agent run instance, conversation_id: { conversation_id } " )
38+ f"register agent run instance, user_id: { user_id } , conversation_id: { conversation_id } " )
3439
35- def unregister_agent_run (self , conversation_id : int ):
40+ def unregister_agent_run (self , conversation_id : int , user_id : str ):
3641 """unregister agent run instance"""
3742 with self ._lock :
38- if conversation_id in self .agent_runs :
39- del self .agent_runs [conversation_id ]
43+ run_key = self ._get_run_key (conversation_id , user_id )
44+ if run_key in self .agent_runs :
45+ del self .agent_runs [run_key ]
4046 logger .info (
41- f"unregister agent run instance, conversation_id: { conversation_id } " )
47+ f"unregister agent run instance, user_id: { user_id } , conversation_id: { conversation_id } " )
4248 else :
4349 logger .info (
44- f"no agent run instance found for conversation_id: { conversation_id } " )
50+ f"no agent run instance found for user_id: { user_id } , conversation_id: { conversation_id } " )
4551
46- def get_agent_run_info (self , conversation_id : int ):
52+ def get_agent_run_info (self , conversation_id : int , user_id : str ):
4753 """get agent run instance"""
48- return self .agent_runs .get (conversation_id )
54+ run_key = self ._get_run_key (conversation_id , user_id )
55+ return self .agent_runs .get (run_key )
4956
50- def stop_agent_run (self , conversation_id : int ) -> bool :
51- """stop agent run for specified conversation_id"""
52- agent_run_info = self .get_agent_run_info (conversation_id )
57+ def stop_agent_run (self , conversation_id : int , user_id : str ) -> bool :
58+ """stop agent run for specified conversation_id and user_id """
59+ agent_run_info = self .get_agent_run_info (conversation_id , user_id )
5360 if agent_run_info is not None :
5461 agent_run_info .stop_event .set ()
5562 logger .info (
56- f"agent run stopped, conversation_id: { conversation_id } " )
63+ f"agent run stopped, user_id: { user_id } , conversation_id: { conversation_id } " )
5764 return True
5865 return False
5966
0 commit comments