The logic by which the bot answers people
The bot doesn’t work on the principle of “saw a message → generated text right away”.
First it decides whether to answer at all. Then it gathers context, pulls in the profile, and only after that builds a reply.
One of the key nodes looks like this:
ctx = ann_build_context_from_db(chat_id, limit=ANN_CONTEXT_MSG_LIMIT, max_chars=ANN_CONTEXT_MAX_CHARS)
profile_block = _build_profile_prompt_block(last_user_text, base_max_tokens, mention_max_tokens)
messages = [
{"role": "system", "content": system_prompt},
{"role": "system", "content": profile_block},
{"role": "user", "content": ctx},
]
What matters here:
• ann_build_context_from_db(…) The function gathers context from the database. So before replying the bot takes not only the last message but the history of the conversation.
• chat_id Context is gathered for a specific chat. This protects against mixing different dialogues.
• limit=ANN_CONTEXT_MSG_LIMIT Limits how many messages go into the context. Otherwise the prompt bloats and gets noisy.
• max_chars=ANN_CONTEXT_MAX_CHARS Additionally limits the size of the context in characters. This is needed so as not to overload the model.
• _build_profile_prompt_block(…) Separately builds the user profile block. So the bot mixes in not only the chat history but also accumulated observations about the person.
• last_user_text The user’s last message is passed to the profile block. This helps choose a more relevant tone and fact from the profile.
• messages = […] This is the final assembly of the prompt package before generation.
• {“role”: “system”, “content”: system_prompt} The main system layer. This holds the bot’s general character, its frame and behaviour.
• {“role”: “system”, “content”: profile_block} The second system layer. This holds personalisation: tone, facts, the particulars of a specific person.
• {“role”: “user”, “content”: ctx} And this holds the assembled context of the conversation itself.
So the logic is:
- the bot doesn’t answer “blindly”
- first it gathers the dialogue history
- then it adds the person’s profile
- then it connects this with the general philosophy and system rules
- and only after that generates a reply
That’s why its reply rests not on one last line but on several layers at once: context, profile, memory and system logic. The bot answers not “a message” but the situation of a conversation.