aelios 0.1.1: skip DS Bot background memory reviews (#779)
aelios recall() skips a request whose last user text is a DS Bot background memory review (isMemoryReview: the "The Bot: …" / "The group chat: …" header, the "Its memory now (…; team: shared by every Bot):" block, "New in …, oldest first" and the closing "Write every new or changed entry in …." line), the same way it skips a secret. A person quoting or discussing it is still recalled and recorded. Version 0.1.1. Run at 19818b55 on mote (Bun 1.4.2, HOME=$(mktemp -d)): - bun test packages/aelios: 187 pass, 0 fail - bun scripts/check.mjs: exit 0 Broken by hand (each restored after): - isMemoryReview returns false: 6 fail - isMemoryReview checks the header only: 1 fail (a discussion case) - hook no longer calls isMemoryReview: 6 fail Not tried: the template was not checked against DS Bot's own source (not found publicly); a template change there makes the matcher miss, which keeps today's behaviour (the review is recalled as before).
This commit is contained in:
@@ -196,6 +196,12 @@ the completed reply's retained text or tool arguments still skips recording.
|
||||
The reply delivered to the client remains unchanged. Each
|
||||
record is sent once and never retried.
|
||||
|
||||
DS Bot's background memory reviews use the Bot's model but are not chat turns.
|
||||
When the current user item matches the complete DS Bot memory-review template,
|
||||
the plugin skips both recall and recording for that request and its reply.
|
||||
Normal conversation, tool continuations and messages discussing or quoting the
|
||||
review remain eligible. This filter does not remove previously recorded reviews.
|
||||
|
||||
## Things to know
|
||||
|
||||
- **Don't double up.** If an agent already uses an Aelios gateway as its
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
// the request (slim.mjs) and puts the memory it gets back after the last
|
||||
// user message. Anything that goes wrong leaves the request as it came.
|
||||
import { createHash } from "node:crypto"
|
||||
import { aeliosProtocol, appendPatch, hasSecret, humanTurn, lastUserText, serverState, slim, slimReply, spoken } from "./slim.mjs"
|
||||
import { aeliosProtocol, appendPatch, hasSecret, humanTurn, isMemoryReview, lastUserText, serverState, slim, slimReply, spoken } from "./slim.mjs"
|
||||
|
||||
const version = "0.1.0"
|
||||
const version = "0.1.1"
|
||||
const maxResponseBytes = 256 << 10
|
||||
const maxRecordBytes = 2 << 20
|
||||
const recordTimeoutMs = 10_000
|
||||
@@ -80,7 +80,8 @@ async function recall(body, ctx, o, report) {
|
||||
return
|
||||
}
|
||||
const slimmed = slim(body, protocol)
|
||||
if (hasSecret(lastUserText(slimmed, protocol))) {
|
||||
const userText = lastUserText(slimmed, protocol)
|
||||
if (isMemoryReview(userText) || hasSecret(userText)) {
|
||||
if (ctx.state) delete ctx.state.aelios
|
||||
report("skipped")
|
||||
return
|
||||
|
||||
@@ -215,6 +215,57 @@ for (const record of [false, true]) {
|
||||
})
|
||||
}
|
||||
|
||||
const memoryReview = (group = false) => [
|
||||
group ? 'The group chat: "Team", with the user and Writer (admin).' : 'The Bot: Writer, Assistant.',
|
||||
'',
|
||||
'MEMORY.md has 12 of 4000 characters (own) and 0 of 4000 (team).',
|
||||
'',
|
||||
group ? 'Its memory now (group: shared by the members of this group; team: shared by every Bot):' : "Its memory now (own: this Bot's; team: shared by every Bot):",
|
||||
'[1] (own) A synthetic fact.',
|
||||
'',
|
||||
'New in this chat, oldest first:',
|
||||
'User: hello',
|
||||
'Assistant: hi',
|
||||
'',
|
||||
'Write every new or changed entry in English.',
|
||||
].join('\n')
|
||||
|
||||
for (const protocol of ['anthropic', 'chat', 'responses']) {
|
||||
for (const group of [false, true]) {
|
||||
test(`${protocol}: DS Bot ${group ? 'group' : 'own'} memory review exports neither prompt nor reply`, async () => {
|
||||
mock()
|
||||
const [c, reports] = ctx(protocol, { options: { record: true } })
|
||||
c.state.aelios = { admitted: true, payload: { identity: 'default' } }
|
||||
const item = { role: 'user', content: [{ type: protocol === 'responses' ? 'input_text' : 'text', text: memoryReview(group) }] }
|
||||
const req = protocol === 'responses' ? { input: [item] } : { messages: [item] }
|
||||
const original = structuredClone(req)
|
||||
expect(await onRequest(req, c)).toBeUndefined()
|
||||
expect(req).toEqual(original)
|
||||
expect(c.state.aelios).toBeUndefined()
|
||||
onResponse({ choices: [{ message: { content: '{"changes":[]}' } }] }, { ...c, success: true })
|
||||
await flush()
|
||||
expect(calls).toHaveLength(0)
|
||||
expect(reports).toEqual([['skipped']])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for (const text of [
|
||||
`The Bot: Writer, Assistant.\n\nI want to change my bot's memory.`,
|
||||
`I found Aelios storing this:\n${memoryReview()}`,
|
||||
`\`\`\`\n${memoryReview()}\n\`\`\``,
|
||||
]) {
|
||||
test(`a person discussing a memory review is still recalled and recorded: ${text.slice(0, 40)}`, async () => {
|
||||
mock()
|
||||
const [c] = ctx('chat', { options: { record: true } })
|
||||
await onRequest({ messages: [{ role: 'user', content: text }] }, c)
|
||||
onResponse({ choices: [{ message: { content: 'Let us fix it.' } }] }, { ...c, success: true })
|
||||
await flush()
|
||||
expect(of('/v1/hook/recall')).toHaveLength(1)
|
||||
expect(of('/v1/hook/record')).toHaveLength(1)
|
||||
})
|
||||
}
|
||||
|
||||
test("transport-wrapped human speech reaches recall and receives memory", async () => {
|
||||
mock()
|
||||
const [c] = ctx("chat")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/gateway-aelios",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"description": "Aelios long-term memory for every agent behind magpie: recall before each turn, optional recording after it",
|
||||
"type": "module",
|
||||
"files": [
|
||||
|
||||
@@ -160,6 +160,17 @@ export function lastUserText(body, protocol) {
|
||||
return visible(last.content)
|
||||
}
|
||||
|
||||
// DS Bot sends background memory reviews through the Bot's own model. They
|
||||
// have a user role, but neither this prompt nor its JSON reply is conversation.
|
||||
// Require the whole template so a person quoting it to report a bug stays human.
|
||||
export function isMemoryReview(text) {
|
||||
const normalized = text.replace(/\r\n/g, "\n").trim()
|
||||
return /^(?:The Bot: [^\n]+\.|The group chat: [^\n]+\.)\n\n/.test(normalized) &&
|
||||
/\n\nIts memory now \((?:own: this Bot's|group: shared by the members of this group); team: shared by every Bot\):\n/.test(normalized) &&
|
||||
/\n\nNew in [^\n]+, oldest first(?: \(newer messages come in the next review\))?:\n/.test(normalized) &&
|
||||
/\n\nWrite every new or changed entry in [^\n]+\.$/.test(normalized)
|
||||
}
|
||||
|
||||
function visible(c) {
|
||||
if (typeof c === "string") return c
|
||||
if (!Array.isArray(c)) return ""
|
||||
|
||||
Reference in New Issue
Block a user