feat(memory): implement stability stage
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
64
apps/worker/src/memory-regression.test.ts
Normal file
64
apps/worker/src/memory-regression.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Character, PlayerIntent } from '@dng/shared'
|
||||
import { buildRoundContext } from './orchestration'
|
||||
|
||||
const hero: Character = {
|
||||
id: 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa',
|
||||
name: 'Mara Venn',
|
||||
concept: 'A careful investigator who remembers promises.',
|
||||
controller: 'human',
|
||||
userId: 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb',
|
||||
abilities: { str: 10, dex: 12, con: 10, int: 14, wis: 13, cha: 9 },
|
||||
hp: 10,
|
||||
maxHp: 10,
|
||||
defense: 12,
|
||||
proficiency: 2,
|
||||
inventory: [],
|
||||
statuses: [],
|
||||
}
|
||||
|
||||
const scenarios = Array.from({ length: 20 }, (_, index) => {
|
||||
const number = index + 1
|
||||
const tag = `clue-${number.toString().padStart(2, '0')}`
|
||||
return {
|
||||
name: `memory regression ${number.toString().padStart(2, '0')}`,
|
||||
tag,
|
||||
fact: `In the opening round, Mara promised the keeper to preserve ${tag}.`,
|
||||
action: `Mara invokes ${tag} and asks the keeper to honor their opening-round agreement.`,
|
||||
}
|
||||
})
|
||||
|
||||
describe('20-scenario AI memory context regression suite', () => {
|
||||
it.each(scenarios)('$name retrieves the expected early fact after twenty rounds', ({ tag, fact, action }) => {
|
||||
const intent: PlayerIntent = {
|
||||
id: 'cccccccc-cccc-4ccc-8ccc-cccccccccccc',
|
||||
roundId: 'dddddddd-dddd-4ddd-8ddd-dddddddddddd',
|
||||
memberId: 'eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee',
|
||||
characterId: hero.id,
|
||||
action,
|
||||
ready: true,
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
updatedAt: '2026-01-01T00:00:00.000Z',
|
||||
}
|
||||
const context = buildRoundContext({
|
||||
scene: `Round 21 returns to the keeper's chamber near ${tag}.`,
|
||||
storySummary: 'The party survived twenty rounds without replaying the full transcript.',
|
||||
recentRounds: Array.from({ length: 20 }, (_, round) => ({ number: round + 1, narration: `Resolved round ${round + 1}.` })),
|
||||
intents: [intent],
|
||||
characters: [hero],
|
||||
memories: [
|
||||
{ summary: fact, importance: 5, tags: [tag], entityIds: [] },
|
||||
...Array.from({ length: 24 }, (_, decoy) => ({
|
||||
summary: `Unrelated later observation ${decoy + 1}.`,
|
||||
importance: (decoy % 4) + 1,
|
||||
tags: [`decoy-${decoy + 1}`],
|
||||
entityIds: [],
|
||||
})),
|
||||
],
|
||||
})
|
||||
|
||||
expect(context.recentRounds.map(round => round.number)).toEqual([19, 20])
|
||||
expect(context.memories.map(memory => memory.summary)).toContain(fact)
|
||||
expect(context.memories).toHaveLength(8)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user