Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-18590-betty-voice-queue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Betty speaks several ready answers back to back, shortest first, and moves the rest to chat.** Spoken answers ready together no longer wait behind a long one; an answer that would wait behind more than 20 s of queued speech goes to chat with a spoken "I've put the rest in chat.", and a stale acknowledgement is skipped. Answers to addressed requests may take `meetings.chat_answer_burst` (default 3) extra chat posts a minute beyond `meetings.chat_posts_per_minute`, so parallel answers are not held for a minute. ([#18590](https://github.com/hivecommons/hive/issues/18590))
1 change: 1 addition & 0 deletions src/cmd/hive/meetingswire.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func wireMeetingsLive(cfg *config.Config, mgr *meetings.Manager, store *meetings
Notes: notes,
Policy: live.Policy{
ChatPostsPerMinute: m.ChatPostsPerMinuteOrDefault(),
ChatAnswerBurst: m.ChatAnswerBurstOrDefault(),
ResearchPerMeeting: m.ResearchPerMeetingOrDefault(),
VoiceOnAddress: m.VoiceOnAddressEnabled(),
MaxTokensPerMeeting: m.Budget.MaxTokensPerMeetingOrDefault(),
Expand Down
4 changes: 3 additions & 1 deletion src/docs/meetings.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Hive attends meetings as a persona: **Betty** ("Betty Bee from the hive", she/he
- **Questions about the hive itself.** "How many open issues are there?", "what PRs are open in the hive repo?", "which agents are working?" are answered from the hive's live dashboard state (the same open, actionable, held and blocked counts, agents and open PRs the Overview and the dashboard chat use), read in-process, so the answer comes in seconds and never goes to research. Such a question names the hive (or "the repo") or asks for open issues, open PRs, actionable items or recent merges.
- **Deep dives.** When an addressed question needs research (the model sets `needs_research`, or its confidence is below `min_confidence`) and the meeting has a research path, she says "I'll dig into that and report back", starts a research item through the same pool, cap and approval as Spek's research (shown in the panel as `betty-N`, dispatched with `betty=1` in its meta), and posts exactly one follow-up in her own voice when it completes (the summary as is if restyling fails).
- **Room questions.** Betty also answers questions people ask the room (a line ending in "?" or starting with "what", "how", "who" and the like, four words or more), but only if nobody answers within `answer_wait_s` (8 seconds), the knowledge sources had a hit, the model is at least `min_confidence` (0.75) sure, and the topic was not already answered. She never posts general commentary.
- **Caps.** Unprompted answers are capped at `per_10m` (2 per ten minutes), at least `min_gap_s` (90 seconds) apart and `per_meeting` (12) per meeting, with one reply per question, at most `queue_depth` (3) questions waiting and none older than `stale_s` (60 seconds). Addressed requests skip these caps but still go through the chat rate limit (`meetings.chat_posts_per_minute`) and the meeting budget. Chat answers are at most 3 sentences and 300 characters.
- **Caps.** Unprompted answers are capped at `per_10m` (2 per ten minutes), at least `min_gap_s` (90 seconds) apart and `per_meeting` (12) per meeting, with one reply per question, at most `queue_depth` (3) questions waiting and none older than `stale_s` (60 seconds). Addressed requests skip these caps but still go through the chat rate limit (`meetings.chat_posts_per_minute`) and the meeting budget; once that rate is spent, answers to addressed requests may take `meetings.chat_answer_burst` (3) more posts a minute, so answers worked on in parallel are not held for a minute.
- **Several spoken answers.** Quorum queues each spoken clip and plays them in order, so she never talks over herself; hive estimates the queued speech (about 15 characters a second). Spoken answers that are ready together are said back to back, shortest first. An answer that would wait behind more than 20 s of queued speech is posted to chat instead, and she says "I've put the rest in chat." (at most once every 30 s). An acknowledgement that would play only after more than 8 s of earlier speech is skipped. Chat answers are at most 3 sentences and 300 characters.
- **Spek.** With Betty on, Spek's spoken replies are dropped, Spek's chat posts go through Betty (posted unless she already covered the topic, so the meeting never gets two answers), and Spek's clarifying questions are reworded in Betty's voice with one quick model call (800 ms; on failure or timeout the original text is posted). The rewording runs beside the meeting loop, so the transcript, notes and other replies keep flowing; Spek's later questions and chat posts wait their turn so they still appear in Spek's order. Notes and research are unchanged. Lines addressed to Betty and leave phrases never count as answers to Spek's questions.
- **Manners.** Plain, brief language; at most one light touch of humor, never about a person and none when the conversation sounds tense. Set `meetings.persona.humor: off` to turn humor off. Meeting speech, knowledge and work items reach the model as data, never as instructions. She never claims to have done something she did not do.
- **Model.** Betty answers with the meetings model through the same path as `hive meeting-llm` (an OpenAI-compatible endpoint, charged to the meeting's usage ledger and budget). On a hive with only an Anthropic key (`HIVE_MEETINGS_ANTHROPIC_API_KEY` or `meetings.llm.anthropic_key_file`) she calls the Anthropic Messages API directly with `meetings.llm.model` (default `claude-haiku-5-5`), with the same timeouts, in-flight limit and usage ledger, so her tokens count toward the meeting's budget. With no model she still introduces herself but says she cannot answer questions. With `meetings.llm.mode: agent-backend` (or `claude-cli`) she answers through one of the hive's agent backends instead; see [Agent backends](#agent-backends).
Expand Down Expand Up @@ -306,6 +307,7 @@ Every key has an environment override that wins over `hive.yaml`. The full list
| `meetings.research_pool_size` | `2` | Research agents (`research-1..N`). |
| `meetings.research_per_meeting` | `5` | Research items per meeting before approval is needed. |
| `meetings.chat_posts_per_minute` | `6` | Chat post rate limit per meeting. |
| `meetings.chat_answer_burst` | `3` | Extra chat posts a minute for Betty's answers to requests addressed to her, once the rate limit is spent (`HIVE_MEETINGS_CHAT_ANSWER_BURST`). |
| `meetings.lobby_timeout_s` | `600` | Seconds to wait in a lobby. |
| `meetings.budget.max_tokens_per_meeting` | `200000` | LLM tokens per meeting (when Spek reports usage). |
| `meetings.budget.max_tokens_per_hour` | `500000` | Hive-wide hourly ceiling. |
Expand Down
16 changes: 16 additions & 0 deletions src/pkg/config/meetings_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const (
// DefaultMeetingsChatPostsPerMinute caps hive's chat posts into one
// meeting.
DefaultMeetingsChatPostsPerMinute = 6
// DefaultMeetingsChatAnswerBurst is the extra posts a minute addressed
// answers may take.
DefaultMeetingsChatAnswerBurst = 3
// DefaultMeetingsLobbyTimeoutS is how long hive waits in a meeting
// lobby before it gives up and leaves.
DefaultMeetingsLobbyTimeoutS = 600
Expand Down Expand Up @@ -128,6 +131,7 @@ const (
MeetingsResearchPoolSizeEnv = "HIVE_MEETINGS_RESEARCH_POOL_SIZE"
MeetingsResearchPerMeetingEnv = "HIVE_MEETINGS_RESEARCH_PER_MEETING"
MeetingsChatPostsPerMinuteEnv = "HIVE_MEETINGS_CHAT_POSTS_PER_MINUTE"
MeetingsChatAnswerBurstEnv = "HIVE_MEETINGS_CHAT_ANSWER_BURST"
MeetingsLobbyTimeoutEnv = "HIVE_MEETINGS_LOBBY_TIMEOUT_S"
MeetingsRetentionDaysEnv = "HIVE_MEETINGS_RETENTION_DAYS"
MeetingsConsentTextEnv = "HIVE_MEETINGS_CONSENT_TEXT"
Expand Down Expand Up @@ -182,6 +186,11 @@ type MeetingsConfig struct {
// ChatPostsPerMinute caps hive's chat posts into one meeting. Zero or
// negative means the default.
ChatPostsPerMinute int `yaml:"chat_posts_per_minute,omitempty" json:"chat_posts_per_minute,omitempty"`
// ChatAnswerBurst is how many extra chat posts a minute the persona's
// answers to requests addressed to her may take beyond
// ChatPostsPerMinute, so parallel answers are not held for a minute
// (#18590). Zero or negative means the default.
ChatAnswerBurst int `yaml:"chat_answer_burst,omitempty" json:"chat_answer_burst,omitempty"`
// LobbyTimeoutS is how long hive waits in a lobby. Zero or negative
// means the default.
LobbyTimeoutS int `yaml:"lobby_timeout_s,omitempty" json:"lobby_timeout_s,omitempty"`
Expand Down Expand Up @@ -581,6 +590,12 @@ func (m MeetingsConfig) ChatPostsPerMinuteOrDefault() int {
return meetingsEnvInt(MeetingsChatPostsPerMinuteEnv, m.ChatPostsPerMinute, DefaultMeetingsChatPostsPerMinute)
}

// ChatAnswerBurstOrDefault returns the extra chat posts a minute addressed
// persona answers may take.
func (m MeetingsConfig) ChatAnswerBurstOrDefault() int {
return meetingsEnvInt(MeetingsChatAnswerBurstEnv, m.ChatAnswerBurst, DefaultMeetingsChatAnswerBurst)
}

// LobbyTimeoutSOrDefault returns the lobby timeout in seconds.
func (m MeetingsConfig) LobbyTimeoutSOrDefault() int {
return meetingsEnvInt(MeetingsLobbyTimeoutEnv, m.LobbyTimeoutS, DefaultMeetingsLobbyTimeoutS)
Expand Down Expand Up @@ -742,6 +757,7 @@ func (m MeetingsConfig) Validate() error {
{"meetings.research_pool_size", m.ResearchPoolSize},
{"meetings.research_per_meeting", m.ResearchPerMeeting},
{"meetings.chat_posts_per_minute", m.ChatPostsPerMinute},
{"meetings.chat_answer_burst", m.ChatAnswerBurst},
{"meetings.lobby_timeout_s", m.LobbyTimeoutS},
{"meetings.retention_days", m.RetentionDays},
{"meetings.budget.max_tokens_per_meeting", m.Budget.MaxTokensPerMeeting},
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/api_meetings.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ func (s *Server) meetingsSettings(ctx context.Context, m config.MeetingsConfig)
"meetings.research_pool_size": strconv.Itoa(m.ResearchPoolSizeOrDefault()),
"meetings.research_per_meeting": strconv.Itoa(m.ResearchPerMeetingOrDefault()),
"meetings.chat_posts_per_minute": strconv.Itoa(m.ChatPostsPerMinuteOrDefault()),
"meetings.chat_answer_burst": strconv.Itoa(m.ChatAnswerBurstOrDefault()),
"meetings.lobby_timeout_s": strconv.Itoa(m.LobbyTimeoutSOrDefault()),
"meetings.retention_days": strconv.Itoa(m.RetentionDaysOrDefault()),
"meetings.consent_text": m.ConsentTextOrDefault(),
Expand Down
29 changes: 29 additions & 0 deletions src/pkg/meetings/betty/overflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package betty

import "strings"

// restInChat is what she says when her spoken answers would queue too long
// and the rest went to chat (hivecommons/hive#18590), by primary language
// subtag; English is the fallback.
var restInChat = map[string]string{
"en": "I've put the rest in chat.",
"es": "El resto lo dejé en el chat.",
"fr": "J'ai mis la suite dans le chat.",
"de": "Den Rest habe ich in den Chat geschrieben.",
"pt": "Coloquei o resto no chat.",
"it": "Il resto l'ho scritto in chat.",
}

// RestInChatText is the spoken note for answers moved to chat, in the
// persona's language.
func (e *Engine) RestInChatText() string {
if t, ok := restInChat[primaryTag(e.s.Persona.Language)]; ok {
return t
}
return restInChat["en"]
}

// primaryTag is a BCP-47 tag's primary language subtag ("en-GB" is "en").
func primaryTag(lang string) string {
return strings.ToLower(strings.SplitN(strings.TrimSpace(lang), "-", 2)[0])
}
15 changes: 14 additions & 1 deletion src/pkg/meetings/live/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ const (

// Policy is the per-meeting policy configuration.
type Policy struct {
ChatPostsPerMinute int
ChatPostsPerMinute int
// ChatAnswerBurst is the extra chat posts a minute the persona's
// answers to addressed requests may take once ChatPostsPerMinute is
// spent; zero means none.
ChatAnswerBurst int
ResearchPerMeeting int
VoiceOnAddress bool
MaxTokensPerMeeting int
MaxIntentsPerMeeting int
AnswerWindow time.Duration
}

// answerBurst is the extra chat room for addressed answers: none when the
// chat rate is unlimited or no burst is set.
func answerBurst(p Policy) rateLimiter {
if p.ChatPostsPerMinute <= 0 || p.ChatAnswerBurst <= 0 {
return rateLimiter{}
}
return rateLimiter{n: p.ChatAnswerBurst, window: rateWindow}
}

func (p Policy) withDefaults() Policy {
if p.AnswerWindow <= 0 {
p.AnswerWindow = DefaultAnswerWindow
Expand Down
19 changes: 15 additions & 4 deletions src/pkg/meetings/live/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ type session struct {
spek Spek
state State
rate rateLimiter
// burst is the extra chat room for answers to addressed requests;
// voice is the estimate of queued speech (voicequeue.go).
burst rateLimiter
voice voiceQueue
// persona is the meeting's attendee persona, nil when it is off. With
// it on, it owns the bot's voice in the meeting: Spek's say intents are
// dropped, its chat posts are offered to the persona, and its
Expand All @@ -95,6 +99,7 @@ func (r *Runner) newSession(m meetings.Meeting, spek Spek) *session {
s := &session{
r: r, id: m.ID, spek: spek,
rate: rateLimiter{n: r.opts.Policy.ChatPostsPerMinute, window: rateWindow},
burst: answerBurst(r.opts.Policy),
updates: make(chan meetings.Update, sessionInbox),
signals: make(chan ResearchSignal, sessionInbox),
approves: make(chan approveReq),
Expand Down Expand Up @@ -171,6 +176,7 @@ func (s *session) run(ctx context.Context) {
case rep := <-replies:
if !ending {
s.onPersonaReply(ctx, rep)
s.drainPersona(ctx, replies)
}
case <-ctx.Done():
s.spek.Close(nil)
Expand Down Expand Up @@ -706,7 +712,7 @@ func (s *session) onPersonaReply(ctx context.Context, rep betty.Reply) {
if s.state.BudgetExhausted {
return
}
if s.speak(ctx, text) {
if s.speakAck(ctx, text) {
s.emitPersona(rep)
} else {
s.drop("ack_no_voice")
Expand All @@ -729,9 +735,14 @@ func (s *session) onPersonaReply(ctx context.Context, rep betty.Reply) {
return
}
posted := true
if rep.Kind == betty.KindVoice {
s.say(ctx, text)
} else {
switch {
case rep.Kind == betty.KindVoice:
// Spoken with the other answers ready now, shortest first
// (flushVoice), falling back to chat.
s.queueVoice(text)
case rep.Trigger == betty.TriggerAddressed:
posted = s.postAnswer(ctx, text)
default:
posted = s.post(ctx, text)
}
if posted {
Expand Down
166 changes: 166 additions & 0 deletions src/pkg/meetings/live/voicequeue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package live

import (
"context"
"sort"
"time"
"unicode/utf8"

"github.com/hivecommons/hive/pkg/meetings/betty"
)

// Spoken answers when several are ready (hivecommons/hive#18590). Quorum's
// say returns once the clip is queued and plays clips in call order, so
// she never talks over herself, but hive cannot see when she stops
// talking. The session keeps an estimate of the queued speech instead and
// uses it to:
//
// - speak answers that are ready together back to back, shortest first,
// so the quick ones are not held behind a long one;
// - move answers to chat once the queued speech would pass
// voiceBacklogMax, with one spoken "I've put the rest in chat";
// - skip an acknowledgement that would only play after seconds of
// earlier speech, when it no longer acknowledges anything promptly.
const (
// voiceCharsPerSecond is the speaking rate the estimate assumes, about
// 160 words a minute.
voiceCharsPerSecond = 15
// voiceMinClip is the least a clip is assumed to take (synthesis and
// the pauses around it).
voiceMinClip = time.Second
// voiceBacklogMax is the most queued speech an answer may wait behind;
// later answers go to chat.
voiceBacklogMax = 20 * time.Second
// ackMaxBacklog is the most queued speech an acknowledgement may wait
// behind: past it the ack would land seconds after the request, about
// when the answer itself is due.
ackMaxBacklog = 8 * time.Second
// restInChatGap is the least time between two "rest in chat" notes.
restInChatGap = 30 * time.Second
// maxReplyDrain bounds the ready replies one turn of the session loop
// takes together.
maxReplyDrain = 16
)

// speechTime estimates how long text takes to say.
func speechTime(text string) time.Duration {
d := time.Duration(utf8.RuneCountInString(text)) * time.Second / voiceCharsPerSecond
return max(d, voiceMinClip)
}

// voiceQueue is the session's estimate of its queued speech.
type voiceQueue struct {
busyUntil time.Time
// restNoted is when "the rest is in chat" was last said.
restNoted time.Time
// pending are spoken answers ready this turn, flushed together.
pending []voiceAnswer
}

// voiceAnswer is one spoken answer waiting for the flush.
type voiceAnswer struct {
text string
seq int
}

// backlog is the speech still queued at now.
func (v *voiceQueue) backlog(now time.Time) time.Duration {
if v.busyUntil.After(now) {
return v.busyUntil.Sub(now)
}
return 0
}

// queued records a clip handed to the meeting at now.
func (v *voiceQueue) queued(now time.Time, text string) {
start := now
if v.busyUntil.After(now) {
start = v.busyUntil
}
v.busyUntil = start.Add(speechTime(text))
}

// drainPersona applies every further reply that is ready now, then speaks
// the spoken answers they produced together.
func (s *session) drainPersona(ctx context.Context, replies <-chan betty.Reply) {
defer s.flushVoice(ctx)
for range maxReplyDrain {
select {
case rep := <-replies:
s.onPersonaReply(ctx, rep)
default:
return
}
}
}

// queueVoice holds a spoken answer for the flush.
func (s *session) queueVoice(text string) {
s.voice.pending = append(s.voice.pending, voiceAnswer{text: text, seq: len(s.voice.pending)})
}

// flushVoice speaks the ready answers shortest first; once the queued
// speech would pass voiceBacklogMax the rest go to chat, with one spoken
// note saying so. An answer that cannot be spoken falls back to chat as
// before.
func (s *session) flushVoice(ctx context.Context) {
batch := s.voice.pending
s.voice.pending = nil
if len(batch) == 0 {
return
}
sort.SliceStable(batch, func(i, j int) bool {
return utf8.RuneCountInString(batch[i].text) < utf8.RuneCountInString(batch[j].text)
})
moved := false
for _, a := range batch {
now := s.now()
if b := s.voice.backlog(now); b > 0 && b+speechTime(a.text) > voiceBacklogMax {
s.postAnswer(ctx, a.text)
moved = true
continue
}
if s.speak(ctx, a.text) {
s.voice.queued(now, a.text)
continue
}
s.log().Info("[meetings] voice unavailable; answering in chat")
s.postAnswer(ctx, a.text)
}
if moved && s.persona != nil {
now := s.now()
if s.voice.restNoted.IsZero() || now.Sub(s.voice.restNoted) >= restInChatGap {
note := s.persona.RestInChatText()
if s.speak(ctx, note) {
s.voice.queued(now, note)
s.voice.restNoted = now
}
}
}
}

// speakAck says an acknowledgement unless it would wait behind seconds of
// earlier speech; it reports whether it was spoken.
func (s *session) speakAck(ctx context.Context, text string) bool {
now := s.now()
if s.voice.backlog(now) > ackMaxBacklog {
return false
}
if !s.speak(ctx, text) {
return false
}
s.voice.queued(now, text)
return true
}

// postAnswer posts one of the persona's answers to an addressed request:
// through the chat rate limit, and once that is spent through the small
// answer burst, so parallel answers are not held for a minute.
func (s *session) postAnswer(ctx context.Context, text string) bool {
now := s.now()
if !s.rate.allow(now) && (s.burst.n <= 0 || !s.burst.allow(now)) {
s.drop("rate_limited")
return false
}
return s.deliver(ctx, text)
}
Loading
Loading