Replace heuristic room read with Ollama sidecar
This commit is contained in:
parent
ada64a1ad1
commit
8bd43c2c3a
14 changed files with 423 additions and 6 deletions
|
|
@ -11,6 +11,7 @@ import {
|
|||
import type { AppConfig } from "@voidbot/config";
|
||||
import {
|
||||
ContextBuilder,
|
||||
type OllamaSituationalSocialReadInferer,
|
||||
PermissionEngine,
|
||||
type AuditLog,
|
||||
type InteractionMemoryBank,
|
||||
|
|
@ -28,6 +29,7 @@ import {
|
|||
type Actor,
|
||||
type CommandName,
|
||||
type GuildContext,
|
||||
type InteractionMemoryProfile,
|
||||
type JobRecord,
|
||||
type ProviderName,
|
||||
type StylePack,
|
||||
|
|
@ -133,6 +135,7 @@ export interface PromptHandlerOptions {
|
|||
interactionMemory: InteractionMemoryBank;
|
||||
voidUsageRateLimiter: VoidUsageRateLimiter;
|
||||
providerRegistry: ProviderRegistry;
|
||||
situationalSocialReadInferer?: OllamaSituationalSocialReadInferer;
|
||||
stylePack?: StylePack;
|
||||
systemMessages: SystemMessageCatalog;
|
||||
forceProvider?: ProviderName;
|
||||
|
|
@ -217,6 +220,10 @@ export async function handlePrompt(options: PromptHandlerOptions): Promise<void>
|
|||
rememberedInteraction.totalInteractions > 0 ? rememberedInteraction : undefined;
|
||||
|
||||
const recentMessages = await getRecentMessages(options.channel, 10);
|
||||
const situationalSocialRead = await inferSituationalSocialRead(options, {
|
||||
recentMessages,
|
||||
interactionMemory,
|
||||
});
|
||||
const sourceGrounding = inferSourceGroundingHint(
|
||||
options.prompt,
|
||||
await options.sourceArchiveRepository.listRepoSummaries(),
|
||||
|
|
@ -238,6 +245,7 @@ export async function handlePrompt(options: PromptHandlerOptions): Promise<void>
|
|||
recentMessages,
|
||||
retrieval,
|
||||
interactionMemory,
|
||||
situationalSocialRead,
|
||||
sourceGrounding,
|
||||
stylePack: options.stylePack,
|
||||
});
|
||||
|
|
@ -629,3 +637,67 @@ async function postFinalResponse(client: Client, job: JobRecord, finalResponse:
|
|||
|
||||
await sendChunkedChannelMessage(channel, finalResponse);
|
||||
}
|
||||
|
||||
async function inferSituationalSocialRead(
|
||||
options: PromptHandlerOptions,
|
||||
input: {
|
||||
recentMessages: Awaited<ReturnType<typeof getRecentMessages>>;
|
||||
interactionMemory?: InteractionMemoryProfile;
|
||||
},
|
||||
) {
|
||||
if (!options.situationalSocialReadInferer) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const read = await options.situationalSocialReadInferer.infer({
|
||||
prompt: options.prompt,
|
||||
actor: options.actor,
|
||||
recentMessages: input.recentMessages,
|
||||
interactionMemory: input.interactionMemory,
|
||||
});
|
||||
|
||||
if (!read) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
await options.auditLog.record({
|
||||
type: "situational_social_read.inferred",
|
||||
actorId: options.actor.id,
|
||||
provider: "local_llm",
|
||||
details: {
|
||||
command: options.command,
|
||||
channelId: options.guildContext.channelId,
|
||||
channelName: options.guildContext.channelName ?? null,
|
||||
promptExcerpt: truncate(options.prompt, 280),
|
||||
recentMessageCount: input.recentMessages.length,
|
||||
model: options.config.localLlm.ollamaModel,
|
||||
summary: read.summary,
|
||||
roomTone: read.roomTone,
|
||||
speakerCurrentRead: read.speakerCurrentRead,
|
||||
socialFrame: read.socialFrame,
|
||||
responseGuidance: read.responseGuidance,
|
||||
supportingSignals: read.supportingSignals,
|
||||
},
|
||||
});
|
||||
|
||||
return read;
|
||||
} catch (error) {
|
||||
await options.auditLog.record({
|
||||
type: "situational_social_read.failed",
|
||||
actorId: options.actor.id,
|
||||
provider: "local_llm",
|
||||
details: {
|
||||
command: options.command,
|
||||
channelId: options.guildContext.channelId,
|
||||
channelName: options.guildContext.channelName ?? null,
|
||||
promptExcerpt: truncate(options.prompt, 280),
|
||||
model: options.config.localLlm.ollamaModel,
|
||||
errorMessage:
|
||||
error instanceof Error ? error.message : "Unexpected situational social read failure.",
|
||||
},
|
||||
});
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ export function convertDiscordMessageToSource(message: Message): SourceMessage {
|
|||
authorName: message.author.displayName ?? message.author.username,
|
||||
content: message.content,
|
||||
timestamp: message.createdAt.toISOString(),
|
||||
isBot: message.author.bot,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { loadConfig } from "@voidbot/config";
|
|||
import {
|
||||
buildVoidMcpServerConfig,
|
||||
ContextBuilder,
|
||||
OllamaSituationalSocialReadInferer,
|
||||
PermissionEngine,
|
||||
createStateStorage,
|
||||
loadStylePack,
|
||||
|
|
@ -146,6 +147,13 @@ export async function startBot(): Promise<void> {
|
|||
config.rateLimits,
|
||||
);
|
||||
const contextBuilder = new ContextBuilder();
|
||||
const situationalSocialReadInferer = new OllamaSituationalSocialReadInferer({
|
||||
ollamaBaseUrl: config.localLlm.ollamaBaseUrl,
|
||||
ollamaModel: config.localLlm.ollamaModel,
|
||||
ollamaTimeoutMs: config.localLlm.ollamaTimeoutMs,
|
||||
ollamaKeepAlive: config.localLlm.ollamaKeepAlive,
|
||||
ollamaNumCtx: config.localLlm.ollamaNumCtx,
|
||||
});
|
||||
const baseSystemMessagesPath = resolve("config/system-messages.json");
|
||||
let activeStylePack = await loadStylePack(config.stylePackPath);
|
||||
let activeSystemMessages = await loadSystemMessageCatalog(
|
||||
|
|
@ -359,6 +367,7 @@ export async function startBot(): Promise<void> {
|
|||
interactionMemory,
|
||||
voidUsageRateLimiter,
|
||||
providerRegistry,
|
||||
situationalSocialReadInferer,
|
||||
stylePack: activeStylePack,
|
||||
systemMessages: activeSystemMessages,
|
||||
silentOwnerQueueAck: !isDirectMessage,
|
||||
|
|
@ -441,6 +450,7 @@ export async function startBot(): Promise<void> {
|
|||
interactionMemory,
|
||||
voidUsageRateLimiter,
|
||||
providerRegistry,
|
||||
situationalSocialReadInferer,
|
||||
stylePack: activeStylePack,
|
||||
systemMessages: activeSystemMessages,
|
||||
forceProvider: requestedProvider,
|
||||
|
|
@ -470,6 +480,7 @@ export async function startBot(): Promise<void> {
|
|||
interactionMemory,
|
||||
voidUsageRateLimiter,
|
||||
providerRegistry,
|
||||
situationalSocialReadInferer,
|
||||
stylePack: activeStylePack,
|
||||
systemMessages: activeSystemMessages,
|
||||
forceProvider: "owner_codex",
|
||||
|
|
|
|||
Loading…
Reference in a new issue