feat(ai): add tool-calling agent (list_chats, get_user_info, read_chat_messages)#22
feat(ai): add tool-calling agent (list_chats, get_user_info, read_chat_messages)#22belyakova-anna wants to merge 1 commit intodevfrom
Conversation
|
@claude Please review this PR and suggest improvements |
|
Claude finished @fedorn's task in 1m 38s —— View job PR Review: feat(ai): add tool-calling agent
Overall this is a clean, well-structured addition. The tool-calling loop, the async Bugs / Correctness1. No recursion depth limit on tool-calling loop Add a max iteration counter (e.g. 10) and bail with an error when exceeded.
2.
Recommended fix: only connect 3. Network error silently swallowed
4.
5. Security / Privacy Considerations6. Tools always sent — no opt-in 7. Robustness8. 9. OpenRouter headers removed
Minor / Style10. 11. SummaryThe architecture is sound — the tool-call loop with async state management is well done. The main concerns are: (1) unbounded recursion on tool calls, (2) double signal handling causing potential double error callbacks, (3) null pointer crash risk in |
Summary
Adds an AI tool-calling agent so the AI can use Telegram data via three tools: list chats, get user info, and read chat messages. The client handles tool calls from the API, runs the right tool, and sends tool results back in a follow-up completion request.
Changes
buildToolsDefinition()defineslist_chats,get_user_info, andread_chat_messagesfor the chat completion request.list_chats: Returns dialogs (chat id, name, type, optional username) with a configurable limit.get_user_info: Resolves user byuser_idorusernameand returns id, name, and username.read_chat_messages: Loads recent messages for a chat viarequestRecentForContextand returns sender, date, and text.sendCompletionRequest()sends the payload;handleResponse()detectstool_calls, runsprocessToolCalls(), appends tool-result messages to_lastSentMessages, and callssendCompletionRequest()again for the next turn.ensureContextLoaded(done)is added so callers can preload context (e.g. for the current chat/topic) before starting a completion.prepareSystemMessage()no longer takes or injects chat context; the system prompt is built without it.