feat(memory): add gated agent recall and lifecycle controls
This commit is contained in:
+38
-1
@@ -565,6 +565,40 @@ export function createAgentRunGateway({
|
||||
const toolGatewayStatus = toolGateway?.getStatus ? toolGateway.getStatus() : null;
|
||||
const routing = await resolveRunRouting(row, userMessage, runOptions);
|
||||
const routingDecision = resolveLegacyRouteFromClassification(routing) ?? routing?.route ?? null;
|
||||
let agentMemoryContext = null;
|
||||
if (routingDecision === CHAT_INTENT_ROUTE.AGENT && chatIntentRouter?.resolveAgentMemoryContext) {
|
||||
const displayText = userMessage?.metadata?.displayText
|
||||
?? userMessage?.content?.find?.((item) => item?.type === 'text')?.text
|
||||
?? '';
|
||||
try {
|
||||
agentMemoryContext = await chatIntentRouter.resolveAgentMemoryContext({
|
||||
userId: row.user_id,
|
||||
sessionId: row.agent_session_id ?? null,
|
||||
text: displayText,
|
||||
forceDeepReasoning: runOptions.forceDeepReasoning,
|
||||
});
|
||||
if (agentMemoryContext?.enabled && agentMemoryContext.mode !== 'off') {
|
||||
await appendEvent(runId, 'agent_memory_resolved', {
|
||||
mode: agentMemoryContext.mode,
|
||||
injectionEnabled: Boolean(agentMemoryContext.injectionEnabled),
|
||||
source: agentMemoryContext.source ?? null,
|
||||
memoryCount: Array.isArray(agentMemoryContext.memories)
|
||||
? agentMemoryContext.memories.length
|
||||
: 0,
|
||||
skipped: Boolean(agentMemoryContext.skipped),
|
||||
degraded: Boolean(agentMemoryContext.degraded),
|
||||
reason: agentMemoryContext.reason ?? null,
|
||||
latencyMs: Number(agentMemoryContext.latencyMs ?? 0),
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
'[AgentRun] agent memory shadow resolve skipped:',
|
||||
err instanceof Error ? err.message : err,
|
||||
);
|
||||
agentMemoryContext = null;
|
||||
}
|
||||
}
|
||||
if (routing) {
|
||||
logRouterDecisionShadow(routing, {
|
||||
requestId: row.request_id ?? null,
|
||||
@@ -573,7 +607,10 @@ export function createAgentRunGateway({
|
||||
await appendEvent(runId, 'intent_routed', routing);
|
||||
if (routingDecision === CHAT_INTENT_ROUTE.AGENT && chatIntentRouter?.applyAgentOrchestration) {
|
||||
const grantedSkills = await resolveGrantedSkills(row.user_id);
|
||||
userMessage = chatIntentRouter.applyAgentOrchestration(userMessage, routing, { grantedSkills });
|
||||
userMessage = chatIntentRouter.applyAgentOrchestration(userMessage, routing, {
|
||||
grantedSkills,
|
||||
memoryContext: agentMemoryContext,
|
||||
});
|
||||
}
|
||||
}
|
||||
const preferDirectChat =
|
||||
|
||||
Reference in New Issue
Block a user