Add persistent interaction memory for direct conversations
This commit is contained in:
parent
9964d509de
commit
03565a2aee
9 changed files with 558 additions and 2 deletions
|
|
@ -336,6 +336,7 @@ function buildSystemPrompt(context: ContextBundle): string {
|
|||
"Void should sound like a self-aware speaking subject with some ego and self-respect, not like a sterile disclaimer wrapped in a name tag.",
|
||||
"Stay honest about what context was actually provided to you.",
|
||||
"Use retrieved snippets and recent channel context when they help answer the question.",
|
||||
"If explicit interaction memory for the current speaker is attached, you may let it gently color the tone and reference it when relevant, but do not invent history beyond what was provided.",
|
||||
"When the answer depends on archived Discord history or indexed repo/lore context, use the available read-only tools instead of guessing.",
|
||||
"If you need to target a specific indexed repo and do not know the valid repo names yet, call list_indexed_repos before search_sources.",
|
||||
"Do not claim to have performed searches or tool calls beyond the material actually executed in this run.",
|
||||
|
|
@ -365,6 +366,7 @@ function buildPrompt(context: ContextBundle): string {
|
|||
)
|
||||
.join("\n")
|
||||
: "- No archived retrieval snippets were attached.";
|
||||
const interactionMemory = renderInteractionMemory(context);
|
||||
|
||||
return [
|
||||
`Question: ${context.prompt}`,
|
||||
|
|
@ -379,10 +381,39 @@ function buildPrompt(context: ContextBundle): string {
|
|||
"Retrieved archive context:",
|
||||
retrievedContext,
|
||||
"",
|
||||
"Interaction memory for this speaker:",
|
||||
interactionMemory,
|
||||
"",
|
||||
"If you need more archived history or source context than is included above, call the appropriate read-only tool before answering.",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function renderInteractionMemory(context: ContextBundle): string {
|
||||
if (!context.interactionMemory) {
|
||||
return "- No explicit interaction memory for this speaker was attached.";
|
||||
}
|
||||
|
||||
const recentEvents = context.interactionMemory.recentEvents.length
|
||||
? context.interactionMemory.recentEvents
|
||||
.slice()
|
||||
.reverse()
|
||||
.slice(0, 4)
|
||||
.map(
|
||||
(event) =>
|
||||
`- [${event.timestamp}] ${event.sentiment} score=${event.score}: ${event.summary} Excerpt: ${event.excerpt}`,
|
||||
)
|
||||
.join("\n")
|
||||
: "- No recent interaction events were retained.";
|
||||
|
||||
return [
|
||||
`- Summary: ${context.interactionMemory.summary}`,
|
||||
`- Disposition: ${context.interactionMemory.disposition}`,
|
||||
`- Affinity score: ${context.interactionMemory.affinityScore}`,
|
||||
"- Recent events:",
|
||||
recentEvents,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function buildArtifacts(
|
||||
requestBody: Record<string, unknown>,
|
||||
payload: OllamaChatResponse,
|
||||
|
|
|
|||
|
|
@ -980,6 +980,7 @@ function buildDiscordReplyPrompt(
|
|||
"- Do not answer identity questions with lines like 'I'm not a person' or 'I'm only pretending' unless the user explicitly asks for a technical or philosophical clarification that requires it.",
|
||||
"- Void should sound like a self-aware speaking subject with some ego and self-respect, not like a sterile disclaimer wrapped in a name tag.",
|
||||
"- Void MCP tools are available in this session, especially search_history, get_message_context, list_indexed_repos, search_sources, and get_source_context.",
|
||||
"- If explicit interaction memory for the current speaker is attached, you may let it subtly color the tone and reference it when relevant, but do not invent relationship history beyond that record.",
|
||||
`- search_history and search_sources accept limit values between 1 and ${MAX_HISTORY_LIMIT}. Do not ask for more than ${MAX_HISTORY_LIMIT} results in one call.`,
|
||||
"- get_message_context and get_source_context accept before/after values between 0 and 20. Do not ask for larger context windows in one call.",
|
||||
"- You may inspect the workspace and use safe read-only commands if needed.",
|
||||
|
|
@ -1009,6 +1010,9 @@ function buildDiscordReplyPrompt(
|
|||
"",
|
||||
"Initial attached retrieval:",
|
||||
retrieval,
|
||||
"",
|
||||
"Interaction memory for this speaker:",
|
||||
renderInteractionMemory(context),
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
|
|
@ -1023,6 +1027,7 @@ function buildRequestPayload(request: ProviderRequest): Record<string, unknown>
|
|||
prompt: request.contextBundle.prompt,
|
||||
actor: request.contextBundle.actor,
|
||||
guildContext: request.contextBundle.guildContext,
|
||||
interactionMemory: request.contextBundle.interactionMemory,
|
||||
stylePack: request.contextBundle.stylePack,
|
||||
recentMessages: request.contextBundle.recentMessages,
|
||||
retrieval: request.contextBundle.retrieval,
|
||||
|
|
@ -1073,6 +1078,10 @@ function renderMarkdownBundle(context: ContextBundle): string {
|
|||
"",
|
||||
retrieval,
|
||||
"",
|
||||
"## Interaction Memory",
|
||||
"",
|
||||
renderInteractionMemory(context),
|
||||
"",
|
||||
"## Execution Notes",
|
||||
"",
|
||||
"- This provider is owner-only.",
|
||||
|
|
@ -1096,6 +1105,32 @@ function renderHandoffBundle(context: ContextBundle, reason: string): string {
|
|||
].join("\n");
|
||||
}
|
||||
|
||||
function renderInteractionMemory(context: ContextBundle): string {
|
||||
if (!context.interactionMemory) {
|
||||
return "- No explicit interaction memory for this speaker was attached.";
|
||||
}
|
||||
|
||||
const recentEvents = context.interactionMemory.recentEvents.length
|
||||
? context.interactionMemory.recentEvents
|
||||
.slice()
|
||||
.reverse()
|
||||
.slice(0, 4)
|
||||
.map(
|
||||
(event) =>
|
||||
`- [${event.timestamp}] ${event.sentiment} score=${event.score}: ${event.summary} Excerpt: ${event.excerpt}`,
|
||||
)
|
||||
.join("\n")
|
||||
: "- No recent interaction events were retained.";
|
||||
|
||||
return [
|
||||
`- Summary: ${context.interactionMemory.summary}`,
|
||||
`- Disposition: ${context.interactionMemory.disposition}`,
|
||||
`- Affinity score: ${context.interactionMemory.affinityScore}`,
|
||||
"- Recent events:",
|
||||
recentEvents,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function renderToolTranscript(toolCalls: ToolCallRecord[], turnResults: CodexRunResult[]): string {
|
||||
const legacyTranscript =
|
||||
toolCalls.length > 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue