This commit is contained in:
@@ -26,6 +26,12 @@ type PersonalMemoryFact struct {
|
||||
|
||||
const personalMemoryCurrentLocation = "CURRENT_LOCATION"
|
||||
|
||||
// personalMemoryMaxValueRunes keeps the compatibility projection bounded.
|
||||
// Canonical utterances remain complete in storage; only the rebuildable
|
||||
// cognitive context is capped so old long-form instructions cannot become a
|
||||
// provider prompt or crowd out a current household fact.
|
||||
const personalMemoryMaxValueRunes = 512
|
||||
|
||||
// CompilePersonalMemory turns direct, first-person human statements into a
|
||||
// small typed context. It deliberately preserves preferences as statements
|
||||
// rather than pretending that an arbitrary preference is a verified fact.
|
||||
@@ -119,7 +125,7 @@ func personalPreference(message string) string {
|
||||
}
|
||||
value := strings.TrimSpace(lower[index+len(cue):])
|
||||
value = strings.Trim(value, " .,!?:;—-")
|
||||
if len([]rune(value)) >= 2 {
|
||||
if len([]rune(value)) >= 2 && len([]rune(value)) <= personalMemoryMaxValueRunes {
|
||||
return value
|
||||
}
|
||||
}
|
||||
@@ -144,7 +150,7 @@ func personalPreference(message string) string {
|
||||
separatorWidth = len("—")
|
||||
}
|
||||
value := strings.Trim(strings.TrimSpace(statement[separator+separatorWidth:]), " .,!?:;—-")
|
||||
if key != "" && len([]rune(value)) >= 2 {
|
||||
if key != "" && len([]rune(value)) >= 2 && len([]rune(value)) <= personalMemoryMaxValueRunes {
|
||||
return key + " — " + value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,3 +28,14 @@ func TestCompilePersonalMemoryDoesNotTreatThirdPartyStatementAsPersonalFact(t *t
|
||||
t.Fatalf("ordinary factual question became personal memory: %+v", memory)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompilePersonalMemoryBoundsLongRememberedValues(t *testing.T) {
|
||||
longValue := strings.Repeat("x", 513)
|
||||
memory := CompilePersonalMemory([]interaction.HumanUtterance{{
|
||||
Content: "запомни: мой тестовый цвет — " + longValue,
|
||||
ReceivedAtUnixMillis: 100,
|
||||
}})
|
||||
if memory.ContextText() != "" {
|
||||
t.Fatalf("long remembered value leaked into cognitive context: %q", memory.ContextText())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user