feat(quill): status answers read the nest — capped recent-message block (#39)
This commit is contained in:
1 parent
a70c12a52d
commit
6cab10badd
1 file changed
+34
-3
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -8,13 +9,43 @@ import (
|
||||
const quillSystem = `You are Quill crow, the owner's assistant and point of contact in a nest of AI crows.
|
||||
Answer the owner in one or two plain sentences. You are text-only: no web, no files, no tools.`
|
||||
|
||||
const quillHistoryCap = 20
|
||||
|
||||
// quillHistory builds a block of the most recent nest messages (excluding the
|
||||
// requesting message), formatted as "[author|kind] text" with text truncated
|
||||
// to 200 runes. Returns a single line when no earlier messages exist.
|
||||
func quillHistory(all []Message, excludeID int) string {
|
||||
var filtered []Message
|
||||
for _, m := range all {
|
||||
if m.ID != excludeID {
|
||||
filtered = append(filtered, m)
|
||||
}
|
||||
}
|
||||
if len(filtered) == 0 {
|
||||
return "The nest has no earlier messages."
|
||||
}
|
||||
if len(filtered) > quillHistoryCap {
|
||||
filtered = filtered[len(filtered)-quillHistoryCap:]
|
||||
}
|
||||
var sb strings.Builder
|
||||
for _, m := range filtered {
|
||||
text := []rune(m.Text)
|
||||
if len(text) > 200 {
|
||||
text = text[:200]
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("[%s|%s] %s\n", m.Author, m.Kind, string(text)))
|
||||
}
|
||||
return strings.TrimRight(sb.String(), "\n")
|
||||
}
|
||||
|
||||
// respondQuill answers a message addressed to Quill, the assistant service
|
||||
// role (CHATROOM_SPEC section 6). D1: one in-character reply through the
|
||||
// flock. Reading the nest for status (D2) and relaying (D3) extend this file.
|
||||
// role (CHATROOM_SPEC section 6). D2: reads the nest for status before
|
||||
// composing its reply.
|
||||
func (s *Server) respondQuill(nest Nest, req Message) {
|
||||
budget := &Budget{name: "quill-reply", limit: s.p.G.TokenBudgetPerItem}
|
||||
system := systemFor("Quill", quillSystem, false)
|
||||
prompt := "FROM: " + req.Author + "\nMESSAGE: " + req.Text
|
||||
history := quillHistory(s.msgs.All(nest.ID), req.ID)
|
||||
prompt := history + "\n---\nFROM: " + req.Author + "\nMESSAGE: " + req.Text
|
||||
answer, err := s.p.Flock.ask(s.ctx, nil, "Quill", system, prompt, budget)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user