def insert_message(self, msg:AgentMsg,tags:List[str] = None):
        """ insert a new message into the Messages table """
        try:
            action_name = None
            action_params = None
            action_result = None
            mentions = None
            if msg.mentions:
                mentions = json.dumps(msg.mentions,ensure_ascii=False)

            match msg.msg_type:
                case AgentMsgType.TYPE_MSG:
                    pass
                case AgentMsgType.TYPE_ACTION:# THIS Action is not AIAction
                    action_name = msg.func_name
                    action_params = json.dumps(msg.args,ensure_ascii=False)
                    action_result = msg.result_str
                case AgentMsgType.TYPE_INTERNAL_CALL:
                    action_name = msg.func_name
                    action_params = json.dumps(msg.args,ensure_ascii=False)
                    action_result = msg.result_str
                case AgentMsgType.TYPE_EVENT:
                    action_name = msg.event_name
                    action_params = json.dumps(msg.event_args,ensure_ascii=False)
            if tags is None:
                tags = []

            str_tags = ','.join(tags)
            conn = self._get_conn()
            conn.execute("""
                INSERT INTO Messages (MessageID, SessionID, MsgType, PrevMsgID, SenderID, ReceiverID, Timestamp, Topic,Mentions,ContentMIME,Content,ActionName,ActionParams,ActionResult,DoneTime,Status,Tags)
                VALUES (?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?,?)
            """, (msg.msg_id, msg.session_id, msg.msg_type.value, msg.prev_msg_id, msg.sender, msg.target, msg.create_time, msg.topic,mentions,msg.body_mime,msg.body,action_name,action_params,action_result,msg.done_time,msg.status.value,str_tags))
            conn.commit()

            if msg.inner_call_chain:
                for inner_call in msg.inner_call_chain:
                    self.insert_message(inner_call)

            return 0  # return 0 if successful
        except Error as e:
            logging.error("Error occurred while inserting message: %s", e)
            return -1  # return -1 if an error occurs
 insert a new message into the Messages table 
src/aios/agent/chatsession.py