Do you mean that you want to add a comment (that mentions a user) to an entity?
In general, the contents of a comment can be described using markdown, and mentioning a user is done using the following format:
[[#@xxxxxx/yyyyyy]]
where xxxxxx is the ID of the user database and yyyyyy is the ID of the user.
I presume that you are comfortable with using scripting to create/update comments.