Repository navigation
feat(api): route ai bot replies through an llm router - #22
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add SpontaneousCaps, which records the last time a bot replied on its own in a channel and blocks another unprompted reply for 10 minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BotConversationService replaces MessageService.handleAIResponse. Human messages are debounced per channel (2.5 s of silence), then the router picks the speakers, merged with the bots named in the new messages by planSpeakers. Speakers reply in turns, each seeing the previous replies; a new human message skips the remaining turns and starts a new cycle. Spontaneous speakers after the first are re-confirmed with the router. After the turns, at most one bot that has not spoken may react. Spontaneous replies and reactions are capped per channel and bot. With AI_ROUTER=off or a router error, only the named bots reply, as before. stopBotTyping now takes the channel, so a reply ending in one channel does not clear the bot's typing indicator in another. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cycle queued behind a running one took the pending messages as soon as it started, so a message that arrived meanwhile skipped its 2.5 s of silence, and the next timer then ran a cycle with no new messages. A cycle now returns without consuming anything while a newer timer is waiting or when nothing is pending. A human message during the router re-ask for a spontaneous speaker did not stop that turn; the re-ask now reports the speaker as not picked once the cycle was interrupted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An interrupt now skips only the remaining turns of bots nobody named, plus the reaction; a named bot still answers. planSpeakers drops unnamed speakers from the tail instead of slicing, so a named bot that sits after router picks is never cut. A running cycle stops at its next turn and skips the reaction after onModuleDestroy. Also removes the unused detectBot, moving its name-variant cases under detectNamedBots, and adds tests for routerEnabled false, the spontaneous re-ask, and the router prompt without exclusions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Style: the three personas are shorter, and each one now ends with a shared CHAT_STYLE block that asks for one or two short sentences, a casual tone, no actions between asterisks, no commentary on the conversation, varied openings, no question at the end of every message and no words put in other people's mouths. Replies are capped at 150 output tokens. Router: questions about other bots go to whoever was talking with the person or to the bot not mentioned, "era para X" / "iba para X" makes X answer what it was asked, a greeting to the group gets one bot, and laughter, thanks and goodbyes normally get none. Pacing: the debounce drops to 1.5 s. The typing indicator stays on until the reply is posted, held after generation for typingDelayMs (27 chars/s, at most 5 s, minus the generation time). A bot pauses 1.2 s to read before answering another bot's reply, including the reaction, and the interrupt and destroy checks run again after every pause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The named-bots interrupt test now lets pedro post and checks that the reaction never routes. The destroy test checks that nothing is posted after the typing delay. New tests cover a human message during the read pause: an unnamed second speaker is skipped, a named one still answers, and a reaction is skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Live tests felt slow: a reply took 6.5-8 s, and a second bot asked the same question came 4 s after the first. Pacing: the debounce drops from 1.5 s to 0.6 s, typing speed goes from 27 to 40 chars/s and the typing cap from 5 s to 3 s. The read pause stays at 1.2 s and now only applies to sequential turns. Parallel rule: the leading run of addressed speakers (named or picked as addressed by the router) starts at once, each with its own typing indicator and history, and each posts when its own reply is typed. No read pause inside the run. Interrupt and destroy rules apply per speaker. Spontaneous speakers keep their sequential turns after the run (read pause, recheck, re-ask, cap) and see its replies; the reaction still comes last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pacing constants, history limits and helpers move out of the service into bot-conversation.util.ts, and both files live in message/bot-conversation/. Also drops the comment and leading blank line of CHAT_STYLE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Presence tracks every channel a bot is typing in, so a bot typing in two channels keeps its indicator until both replies are posted. - The spontaneous cap is only used up by a reply that was actually posted. - A reply cut off by the token limit is trimmed to its last full sentence. - compose.yaml passes AI_ROUTER through; the router history size lives in one constant; AGENTS.md states the real speaker limit (2 in total, more only when more bots are named) and the README notes that the router sends channel history to the provider. - BotConversationService passes one BotCycle object around instead of many parameters, and helpers used once are inlined. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bot picked to react is now told whose replies it reacts to, so it teases or disagrees with them instead of answering the human again. CHAT_STYLE allows friendly banter between bots, and the router is invited to pick a reaction when a bot has something witty to say, still none otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #21. Bots no longer need to be named: an LLM router reads the last 20 messages and decides who, if anyone, replies. Named bots always answer, addressed bots reply in parallel, one other bot may react to their replies (teasing allowed), spontaneous replies are capped (1 per bot/channel/10 min), and replies are short and paced like typing.
AI_ROUTER=offfalls back to name detection.Verified:
pnpm check, unit tests, full api suite 112/112 (--runInBand), manual tests withclaude-haiku-5-5.