@illuma-ai/agents 1.1.28 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/spawnPath.cjs +104 -0
- package/dist/cjs/common/spawnPath.cjs.map +1 -0
- package/dist/cjs/graphs/Graph.cjs +89 -45
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/HandoffRegistry.cjs +47 -8
- package/dist/cjs/graphs/HandoffRegistry.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +493 -267
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/phases/flushLoop.cjs +214 -0
- package/dist/cjs/graphs/phases/flushLoop.cjs.map +1 -0
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs +102 -0
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs.map +1 -0
- package/dist/cjs/llm/bedrock/index.cjs +4 -3
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +117 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/memory/citations.cjs +69 -0
- package/dist/cjs/memory/citations.cjs.map +1 -0
- package/dist/cjs/memory/compositeBackend.cjs +60 -0
- package/dist/cjs/memory/compositeBackend.cjs.map +1 -0
- package/dist/cjs/memory/constants.cjs +232 -0
- package/dist/cjs/memory/constants.cjs.map +1 -0
- package/dist/cjs/memory/embeddings.cjs +151 -0
- package/dist/cjs/memory/embeddings.cjs.map +1 -0
- package/dist/cjs/memory/factory.cjs +95 -0
- package/dist/cjs/memory/factory.cjs.map +1 -0
- package/dist/cjs/memory/migrate.cjs +81 -0
- package/dist/cjs/memory/migrate.cjs.map +1 -0
- package/dist/cjs/memory/mmr.cjs +138 -0
- package/dist/cjs/memory/mmr.cjs.map +1 -0
- package/dist/cjs/memory/paths.cjs +217 -0
- package/dist/cjs/memory/paths.cjs.map +1 -0
- package/dist/cjs/memory/pgvectorStore.cjs +225 -0
- package/dist/cjs/memory/pgvectorStore.cjs.map +1 -0
- package/dist/cjs/memory/recallTracking.cjs +98 -0
- package/dist/cjs/memory/recallTracking.cjs.map +1 -0
- package/dist/cjs/memory/schema.sql +51 -0
- package/dist/cjs/memory/temporalDecay.cjs +118 -0
- package/dist/cjs/memory/temporalDecay.cjs.map +1 -0
- package/dist/cjs/nodes/ApprovalGateNode.cjs +1 -1
- package/dist/cjs/nodes/ApprovalGateNode.cjs.map +1 -1
- package/dist/cjs/prompts/memoryFlushPrompt.cjs +49 -0
- package/dist/cjs/prompts/memoryFlushPrompt.cjs.map +1 -0
- package/dist/cjs/run.cjs +16 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/AskUser.cjs +6 -1
- package/dist/cjs/tools/AskUser.cjs.map +1 -1
- package/dist/cjs/tools/BrowserTools.cjs +1 -1
- package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +127 -10
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/approval/constants.cjs +2 -2
- package/dist/cjs/tools/approval/constants.cjs.map +1 -1
- package/dist/cjs/tools/memory/index.cjs +58 -0
- package/dist/cjs/tools/memory/index.cjs.map +1 -0
- package/dist/cjs/tools/memory/memoryAppendTool.cjs +69 -0
- package/dist/cjs/tools/memory/memoryAppendTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/memoryGetTool.cjs +49 -0
- package/dist/cjs/tools/memory/memoryGetTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/memorySearchTool.cjs +65 -0
- package/dist/cjs/tools/memory/memorySearchTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/shared.cjs +106 -0
- package/dist/cjs/tools/memory/shared.cjs.map +1 -0
- package/dist/cjs/types/graph.cjs.map +1 -1
- package/dist/cjs/utils/childAgentContext.cjs +242 -0
- package/dist/cjs/utils/childAgentContext.cjs.map +1 -0
- package/dist/cjs/utils/errors.cjs +113 -0
- package/dist/cjs/utils/errors.cjs.map +1 -0
- package/dist/cjs/utils/events.cjs +36 -7
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/finishReasons.cjs +44 -0
- package/dist/cjs/utils/finishReasons.cjs.map +1 -0
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/logging.cjs +34 -0
- package/dist/cjs/utils/logging.cjs.map +1 -0
- package/dist/cjs/utils/toolCallNormalization.cjs +250 -0
- package/dist/cjs/utils/toolCallNormalization.cjs.map +1 -0
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/spawnPath.mjs +95 -0
- package/dist/esm/common/spawnPath.mjs.map +1 -0
- package/dist/esm/graphs/Graph.mjs +89 -45
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/HandoffRegistry.mjs +47 -8
- package/dist/esm/graphs/HandoffRegistry.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +493 -267
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/phases/flushLoop.mjs +209 -0
- package/dist/esm/graphs/phases/flushLoop.mjs.map +1 -0
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs +99 -0
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs.map +1 -0
- package/dist/esm/llm/bedrock/index.mjs +4 -3
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/main.mjs +21 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/memory/citations.mjs +64 -0
- package/dist/esm/memory/citations.mjs.map +1 -0
- package/dist/esm/memory/compositeBackend.mjs +58 -0
- package/dist/esm/memory/compositeBackend.mjs.map +1 -0
- package/dist/esm/memory/constants.mjs +198 -0
- package/dist/esm/memory/constants.mjs.map +1 -0
- package/dist/esm/memory/embeddings.mjs +148 -0
- package/dist/esm/memory/embeddings.mjs.map +1 -0
- package/dist/esm/memory/factory.mjs +93 -0
- package/dist/esm/memory/factory.mjs.map +1 -0
- package/dist/esm/memory/migrate.mjs +78 -0
- package/dist/esm/memory/migrate.mjs.map +1 -0
- package/dist/esm/memory/mmr.mjs +130 -0
- package/dist/esm/memory/mmr.mjs.map +1 -0
- package/dist/esm/memory/paths.mjs +207 -0
- package/dist/esm/memory/paths.mjs.map +1 -0
- package/dist/esm/memory/pgvectorStore.mjs +223 -0
- package/dist/esm/memory/pgvectorStore.mjs.map +1 -0
- package/dist/esm/memory/recallTracking.mjs +94 -0
- package/dist/esm/memory/recallTracking.mjs.map +1 -0
- package/dist/esm/memory/schema.sql +51 -0
- package/dist/esm/memory/temporalDecay.mjs +110 -0
- package/dist/esm/memory/temporalDecay.mjs.map +1 -0
- package/dist/esm/nodes/ApprovalGateNode.mjs +1 -1
- package/dist/esm/nodes/ApprovalGateNode.mjs.map +1 -1
- package/dist/esm/prompts/memoryFlushPrompt.mjs +44 -0
- package/dist/esm/prompts/memoryFlushPrompt.mjs.map +1 -0
- package/dist/esm/run.mjs +16 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/AskUser.mjs +6 -1
- package/dist/esm/tools/AskUser.mjs.map +1 -1
- package/dist/esm/tools/BrowserTools.mjs +1 -1
- package/dist/esm/tools/BrowserTools.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +128 -11
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/approval/constants.mjs +2 -2
- package/dist/esm/tools/approval/constants.mjs.map +1 -1
- package/dist/esm/tools/memory/index.mjs +46 -0
- package/dist/esm/tools/memory/index.mjs.map +1 -0
- package/dist/esm/tools/memory/memoryAppendTool.mjs +67 -0
- package/dist/esm/tools/memory/memoryAppendTool.mjs.map +1 -0
- package/dist/esm/tools/memory/memoryGetTool.mjs +47 -0
- package/dist/esm/tools/memory/memoryGetTool.mjs.map +1 -0
- package/dist/esm/tools/memory/memorySearchTool.mjs +63 -0
- package/dist/esm/tools/memory/memorySearchTool.mjs.map +1 -0
- package/dist/esm/tools/memory/shared.mjs +98 -0
- package/dist/esm/tools/memory/shared.mjs.map +1 -0
- package/dist/esm/types/graph.mjs.map +1 -1
- package/dist/esm/utils/childAgentContext.mjs +237 -0
- package/dist/esm/utils/childAgentContext.mjs.map +1 -0
- package/dist/esm/utils/errors.mjs +109 -0
- package/dist/esm/utils/errors.mjs.map +1 -0
- package/dist/esm/utils/events.mjs +36 -8
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/finishReasons.mjs +41 -0
- package/dist/esm/utils/finishReasons.mjs.map +1 -0
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/logging.mjs +31 -0
- package/dist/esm/utils/logging.mjs.map +1 -0
- package/dist/esm/utils/toolCallNormalization.mjs +247 -0
- package/dist/esm/utils/toolCallNormalization.mjs.map +1 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/common/spawnPath.d.ts +59 -0
- package/dist/types/graphs/HandoffRegistry.d.ts +24 -7
- package/dist/types/graphs/MultiAgentGraph.d.ts +43 -23
- package/dist/types/graphs/phases/flushLoop.d.ts +106 -0
- package/dist/types/graphs/phases/memoryFlushPhase.d.ts +100 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/memory/__tests__/mockBackend.d.ts +40 -0
- package/dist/types/memory/citations.d.ts +39 -0
- package/dist/types/memory/compositeBackend.d.ts +30 -0
- package/dist/types/memory/constants.d.ts +121 -0
- package/dist/types/memory/embeddings.d.ts +15 -0
- package/dist/types/memory/factory.d.ts +23 -0
- package/dist/types/memory/index.d.ts +21 -0
- package/dist/types/memory/migrate.d.ts +14 -0
- package/dist/types/memory/mmr.d.ts +50 -0
- package/dist/types/memory/paths.d.ts +107 -0
- package/dist/types/memory/pgvectorStore.d.ts +56 -0
- package/dist/types/memory/recallTracking.d.ts +30 -0
- package/dist/types/memory/temporalDecay.d.ts +53 -0
- package/dist/types/memory/types.d.ts +182 -0
- package/dist/types/prompts/memoryFlushPrompt.d.ts +54 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/tools/AskUser.d.ts +1 -1
- package/dist/types/tools/BrowserTools.d.ts +2 -2
- package/dist/types/tools/approval/constants.d.ts +2 -2
- package/dist/types/tools/memory/index.d.ts +39 -0
- package/dist/types/tools/memory/memoryAppendTool.d.ts +27 -0
- package/dist/types/tools/memory/memoryGetTool.d.ts +22 -0
- package/dist/types/tools/memory/memorySearchTool.d.ts +22 -0
- package/dist/types/tools/memory/shared.d.ts +106 -0
- package/dist/types/types/graph.d.ts +10 -3
- package/dist/types/utils/childAgentContext.d.ts +99 -0
- package/dist/types/utils/errors.d.ts +37 -0
- package/dist/types/utils/events.d.ts +21 -0
- package/dist/types/utils/finishReasons.d.ts +32 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/logging.d.ts +2 -0
- package/dist/types/utils/toolCallNormalization.d.ts +44 -0
- package/package.json +6 -4
- package/src/agents/AgentContext.ts +12 -4
- package/src/common/__tests__/enum.test.ts +4 -2
- package/src/common/__tests__/spawnPath.test.ts +110 -0
- package/src/common/index.ts +1 -0
- package/src/common/spawnPath.ts +101 -0
- package/src/graphs/Graph.ts +95 -61
- package/src/graphs/HandoffRegistry.ts +48 -17
- package/src/graphs/MultiAgentGraph.ts +588 -327
- package/src/graphs/__tests__/HandoffRegistry.test.ts +4 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +61 -16
- package/src/graphs/__tests__/multi-agent-edges.test.ts +4 -2
- package/src/graphs/__tests__/multi-agent-nested-subgraph.test.ts +221 -0
- package/src/graphs/__tests__/structured-output.integration.test.ts +212 -118
- package/src/graphs/contextManagement.e2e.test.ts +1 -1
- package/src/graphs/phases/__tests__/flushLoop.test.ts +264 -0
- package/src/graphs/phases/__tests__/memoryFlushPhase.test.ts +37 -0
- package/src/graphs/phases/__tests__/runMemoryFlush.test.ts +150 -0
- package/src/graphs/phases/flushLoop.ts +303 -0
- package/src/graphs/phases/memoryFlushPhase.ts +209 -0
- package/src/index.ts +30 -1
- package/src/llm/bedrock/index.ts +4 -5
- package/src/memory/__tests__/citations.test.ts +61 -0
- package/src/memory/__tests__/compositeBackend.test.ts +79 -0
- package/src/memory/__tests__/isolation.test.ts +206 -0
- package/src/memory/__tests__/mmr.test.ts +148 -0
- package/src/memory/__tests__/mockBackend.ts +161 -0
- package/src/memory/__tests__/paths.test.ts +168 -0
- package/src/memory/__tests__/recallTracking.test.ts +96 -0
- package/src/memory/__tests__/temporalDecay.test.ts +151 -0
- package/src/memory/citations.ts +80 -0
- package/src/memory/compositeBackend.ts +99 -0
- package/src/memory/constants.ts +229 -0
- package/src/memory/embeddings.ts +188 -0
- package/src/memory/factory.ts +111 -0
- package/src/memory/index.ts +46 -0
- package/src/memory/migrate.ts +116 -0
- package/src/memory/mmr.ts +161 -0
- package/src/memory/paths.ts +258 -0
- package/src/memory/pgvectorStore.ts +324 -0
- package/src/memory/recallTracking.ts +127 -0
- package/src/memory/schema.sql +51 -0
- package/src/memory/temporalDecay.ts +134 -0
- package/src/memory/types.ts +185 -0
- package/src/nodes/ApprovalGateNode.ts +4 -10
- package/src/nodes/__tests__/ApprovalGateNode.test.ts +11 -20
- package/src/prompts/memoryFlushPrompt.ts +78 -0
- package/src/run.ts +17 -6
- package/src/scripts/test-bedrock-handoff-autonomous.ts +56 -20
- package/src/specs/agent-handoffs-bedrock.integration.test.ts +8 -5
- package/src/specs/agent-handoffs.test.ts +8 -2
- package/src/tools/AskUser.ts +7 -2
- package/src/tools/BrowserTools.ts +3 -5
- package/src/tools/ToolNode.ts +150 -13
- package/src/tools/__tests__/ToolApproval.test.ts +22 -9
- package/src/tools/approval/__tests__/constants.test.ts +1 -1
- package/src/tools/approval/constants.ts +2 -2
- package/src/tools/memory/__tests__/memoryTools.test.ts +205 -0
- package/src/tools/memory/index.ts +96 -0
- package/src/tools/memory/memoryAppendTool.ts +101 -0
- package/src/tools/memory/memoryGetTool.ts +53 -0
- package/src/tools/memory/memorySearchTool.ts +80 -0
- package/src/tools/memory/shared.ts +169 -0
- package/src/tools/search/search.test.ts +6 -1
- package/src/types/graph.ts +10 -3
- package/src/utils/__tests__/childAgentContext.test.ts +217 -0
- package/src/utils/__tests__/errors.test.ts +136 -0
- package/src/utils/__tests__/finishReasons.test.ts +55 -0
- package/src/utils/__tests__/toolCallNormalization.test.ts +181 -0
- package/src/utils/childAgentContext.ts +259 -0
- package/src/utils/errors.ts +115 -0
- package/src/utils/events.ts +37 -7
- package/src/utils/finishReasons.ts +40 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/llm.ts +0 -1
- package/src/utils/logging.ts +45 -8
- package/src/utils/toolCallNormalization.ts +271 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for building a memory backend from environment variables.
|
|
3
|
+
*
|
|
4
|
+
* Called once at startup by host's singleton (`api/server/services/memoryStore.js`).
|
|
5
|
+
* Returns `null` — never throws — when required env vars are missing, so
|
|
6
|
+
* agents with `memory_enabled=true` still run, just without memory. Host
|
|
7
|
+
* logs a single warning on boot instead of crashing.
|
|
8
|
+
*/
|
|
9
|
+
import { Pool } from 'pg';
|
|
10
|
+
import { type RecallTracker } from './recallTracking';
|
|
11
|
+
import type { MemoryBackend } from './types';
|
|
12
|
+
export interface BuildMemoryBackendResult {
|
|
13
|
+
backend: MemoryBackend;
|
|
14
|
+
pool: Pool;
|
|
15
|
+
/** Phase 2 — shared recall tracker bound to the same pool/migration. */
|
|
16
|
+
recallTracker: RecallTracker;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Try to build a configured memory backend. Returns null when the required
|
|
20
|
+
* env vars are absent — caller should log a single "memory disabled" warning
|
|
21
|
+
* and continue. Never throws on missing config.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildMemoryBackendFromEnv(): Promise<BuildMemoryBackendResult | null>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Public entry point for the memory package. */
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export * from './paths';
|
|
5
|
+
export { PgvectorMemoryStore } from './pgvectorStore';
|
|
6
|
+
export type { PgvectorStoreOptions } from './pgvectorStore';
|
|
7
|
+
export { CompositeMemoryBackend } from './compositeBackend';
|
|
8
|
+
export { getMemoryEmbedder, resetMemoryEmbedder } from './embeddings';
|
|
9
|
+
export type { EmbeddingProvider, EmbeddingProviderKind } from './embeddings';
|
|
10
|
+
export { runMemoryMigration } from './migrate';
|
|
11
|
+
export type { MigrationOptions } from './migrate';
|
|
12
|
+
export { buildMemoryBackendFromEnv } from './factory';
|
|
13
|
+
export type { BuildMemoryBackendResult } from './factory';
|
|
14
|
+
export { mmrRerank, applyMMRToMemoryHits, DEFAULT_MMR_CONFIG, tokenize, jaccardSimilarity, textSimilarity, computeMMRScore, } from './mmr';
|
|
15
|
+
export type { MMRConfig, MMRItem } from './mmr';
|
|
16
|
+
export { applyTemporalDecayToHits, applyTemporalDecayToScore, calculateTemporalDecayMultiplier, parseMemoryDateFromPath, isEvergreenMemoryPath, DEFAULT_TEMPORAL_DECAY_CONFIG, } from './temporalDecay';
|
|
17
|
+
export type { TemporalDecayConfig, DecayCandidate } from './temporalDecay';
|
|
18
|
+
export { decorateCitations, resolveMemoryCitationsMode, shouldIncludeCitations, } from './citations';
|
|
19
|
+
export type { MemoryCitationsMode, CitationCandidate } from './citations';
|
|
20
|
+
export { PgvectorRecallTracker, NullRecallTracker, RECALL_TABLE, } from './recallTracking';
|
|
21
|
+
export type { RecallTracker, RecallRecordParams } from './recallTracking';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotent schema install + vector-dimension safety check.
|
|
3
|
+
*
|
|
4
|
+
* Called once at agents-library startup by host's `memoryStore.js` singleton
|
|
5
|
+
* factory. Safe to call multiple times — every statement is `IF NOT EXISTS`.
|
|
6
|
+
*/
|
|
7
|
+
import type { Pool } from 'pg';
|
|
8
|
+
export interface MigrationOptions {
|
|
9
|
+
pool: Pool;
|
|
10
|
+
table?: string;
|
|
11
|
+
/** If true, skip the live embedder probe (tests). */
|
|
12
|
+
skipEmbedderProbe?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function runMemoryMigration(opts: MigrationOptions): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximal Marginal Relevance (MMR) re-ranking — Phase 2.
|
|
3
|
+
*
|
|
4
|
+
* Ported from upstream `extensions/memory-core/src/memory/mmr.ts` with
|
|
5
|
+
* minor adaptation for our `MemoryEntry` shape (content vs snippet, id vs
|
|
6
|
+
* path+startLine). Behavior is identical: normalize scores, iteratively
|
|
7
|
+
* pick the item that maximizes `λ * relevance - (1-λ) * max_similarity`
|
|
8
|
+
* using Jaccard on tokenized content.
|
|
9
|
+
*
|
|
10
|
+
* @see Carbonell & Goldstein, "The Use of MMR, Diversity-Based Reranking" (1998)
|
|
11
|
+
*/
|
|
12
|
+
export interface MMRConfig {
|
|
13
|
+
/** Opt-in. Upstream default is false. */
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
/** 0 = max diversity, 1 = max relevance. Upstream default 0.7. */
|
|
16
|
+
lambda: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const DEFAULT_MMR_CONFIG: MMRConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Tokenize content into a set for Jaccard similarity.
|
|
21
|
+
*
|
|
22
|
+
* ASCII: alphanumeric + underscore runs, lowercased.
|
|
23
|
+
* CJK: each char becomes a unigram; consecutive pairs become a bigram.
|
|
24
|
+
* Non-adjacent CJK chars (e.g. `我a好`) do NOT form a bigram.
|
|
25
|
+
*/
|
|
26
|
+
export declare function tokenize(text: string): Set<string>;
|
|
27
|
+
export declare function jaccardSimilarity(a: Set<string>, b: Set<string>): number;
|
|
28
|
+
export declare function textSimilarity(a: string, b: string): number;
|
|
29
|
+
export declare function computeMMRScore(relevance: number, maxSimilarity: number, lambda: number): number;
|
|
30
|
+
export interface MMRItem {
|
|
31
|
+
id: string;
|
|
32
|
+
score: number;
|
|
33
|
+
content: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Re-rank items using MMR. Returns a new array in MMR order.
|
|
37
|
+
*/
|
|
38
|
+
export declare function mmrRerank<T extends MMRItem>(items: T[], config?: Partial<MMRConfig>): T[];
|
|
39
|
+
/**
|
|
40
|
+
* Adapter: apply MMR to an array of MemoryEntry-shaped hits.
|
|
41
|
+
*
|
|
42
|
+
* Uses (path|id|index) as the stable ID so two hits from the same file at
|
|
43
|
+
* different content still get distinct MMR identities.
|
|
44
|
+
*/
|
|
45
|
+
export declare function applyMMRToMemoryHits<T extends {
|
|
46
|
+
id: string;
|
|
47
|
+
path: string;
|
|
48
|
+
content: string;
|
|
49
|
+
score: number;
|
|
50
|
+
}>(results: T[], config?: Partial<MMRConfig>): T[];
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autonomous memory — canonical path whitelist + tier utilities.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for the 8 stable memory documents. Every write
|
|
5
|
+
* goes through {@link assertWritablePath}; every reader can ask
|
|
6
|
+
* {@link getTierForPath} what a row belongs to. Adding or removing a
|
|
7
|
+
* path means editing this file — and exactly this file.
|
|
8
|
+
*
|
|
9
|
+
* ## Why a whitelist?
|
|
10
|
+
*
|
|
11
|
+
* Earlier upstream-faithful designs used date-keyed files
|
|
12
|
+
* (`memory/YYYY-MM-DD.md`), which have three problems for a persistent
|
|
13
|
+
* multi-user agent:
|
|
14
|
+
*
|
|
15
|
+
* 1. **Unbounded growth** — one row per day per agent per user, forever.
|
|
16
|
+
* 2. **LLM routing ambiguity** — "which date file do I read?" has no
|
|
17
|
+
* good answer, so the model reads (and ranks against) all of them.
|
|
18
|
+
* 3. **No natural deduplication** — the same fact written across three
|
|
19
|
+
* days returns three near-identical hits.
|
|
20
|
+
*
|
|
21
|
+
* With 8 stable canonical documents the LLM knows *exactly* where to
|
|
22
|
+
* write ("is this a preference? → `memory/user/preferences.md`") and
|
|
23
|
+
* each row accumulates via UPSERT instead of piling up new rows.
|
|
24
|
+
*
|
|
25
|
+
* ## Two tiers
|
|
26
|
+
*
|
|
27
|
+
* - **Agent tier** (`memory/agent/*`) — operational knowledge that
|
|
28
|
+
* every caller of the agent benefits from. Stored with `user_id = NULL`.
|
|
29
|
+
* Shared across all users of a collaborative agent; the only tier that
|
|
30
|
+
* exists for isolated/autonomous agents with no invoker.
|
|
31
|
+
*
|
|
32
|
+
* - **User tier** (`memory/user/*`) — per-invoker personalization.
|
|
33
|
+
* Stored with `user_id = <caller>`. Read path filters so User A never
|
|
34
|
+
* sees User B's rows, even for the same agent. Not writable unless the
|
|
35
|
+
* flush scope carries a non-empty `userId`.
|
|
36
|
+
*
|
|
37
|
+
* The tier of a path is a function of its prefix (`memory/agent/` vs
|
|
38
|
+
* `memory/user/`), so adding a new document is one line here + the
|
|
39
|
+
* constant array entry; no store or route code has to change.
|
|
40
|
+
*/
|
|
41
|
+
import type { MemoryScope } from './types';
|
|
42
|
+
/** Tier discriminator — the two kinds of memory a row can belong to. */
|
|
43
|
+
export type MemoryTier = 'agent' | 'user';
|
|
44
|
+
/** Every canonical document the flush phase is allowed to write. */
|
|
45
|
+
export interface MemoryPathDescriptor {
|
|
46
|
+
/** Full path including the `memory/` prefix. */
|
|
47
|
+
path: string;
|
|
48
|
+
/** Which tier the path lives under. */
|
|
49
|
+
tier: MemoryTier;
|
|
50
|
+
/** Short label shown in UI tier badges and the flush prompt rubric. */
|
|
51
|
+
label: string;
|
|
52
|
+
/** One-line description — fed to the LLM to make routing unambiguous. */
|
|
53
|
+
description: string;
|
|
54
|
+
}
|
|
55
|
+
/** Agent-tier documents — shared across all users of the agent. */
|
|
56
|
+
export declare const MEMORY_AGENT_PATHS: readonly MemoryPathDescriptor[];
|
|
57
|
+
/** User-tier documents — per-invoker, never shared across users. */
|
|
58
|
+
export declare const MEMORY_USER_PATHS: readonly MemoryPathDescriptor[];
|
|
59
|
+
/** All 8 canonical documents in display order: agent tier first, user tier second. */
|
|
60
|
+
export declare const MEMORY_ALL_PATHS: readonly MemoryPathDescriptor[];
|
|
61
|
+
/** Set of all whitelisted paths — for `has()` lookups. */
|
|
62
|
+
export declare const MEMORY_WRITABLE_PATHS: ReadonlySet<string>;
|
|
63
|
+
/** Returns the descriptor for a canonical path, or `undefined` if not on the whitelist. */
|
|
64
|
+
export declare function getPathDescriptor(path: string): MemoryPathDescriptor | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the tier a given path belongs to.
|
|
67
|
+
*
|
|
68
|
+
* For unknown paths (e.g. legacy date-keyed rows that predate this schema),
|
|
69
|
+
* falls back to inspecting the `memory/agent/` or `memory/user/` prefix.
|
|
70
|
+
* Anything that matches neither is classified as `agent` — it will surface
|
|
71
|
+
* in the admin UI under the agent-tier header and stay read-only there.
|
|
72
|
+
*/
|
|
73
|
+
export declare function getTierForPath(path: string): MemoryTier;
|
|
74
|
+
/**
|
|
75
|
+
* Paths that are legal to write **for this caller's scope**.
|
|
76
|
+
*
|
|
77
|
+
* If `scope.userId` is absent (isolated/autonomous agent), the user-tier
|
|
78
|
+
* paths are dropped. This is the list the flush prompt renders into its
|
|
79
|
+
* rubric — the LLM never sees paths it cannot write to.
|
|
80
|
+
*/
|
|
81
|
+
export declare function getWritablePathsForScope(scope: Pick<MemoryScope, 'userId'>): readonly MemoryPathDescriptor[];
|
|
82
|
+
/**
|
|
83
|
+
* Validates a write path against the whitelist AND the caller's scope.
|
|
84
|
+
*
|
|
85
|
+
* Throws with an actionable message when:
|
|
86
|
+
* - the path is missing the `memory/` prefix
|
|
87
|
+
* - the path is not on the 8-doc whitelist
|
|
88
|
+
* - the path is user-tier but `scope.userId` is missing
|
|
89
|
+
*
|
|
90
|
+
* The store's append() is the single call site; other callers should
|
|
91
|
+
* never hit this directly. Kept as a standalone function for testability.
|
|
92
|
+
*/
|
|
93
|
+
export declare function assertWritablePath(path: string, scope: Pick<MemoryScope, 'userId'>): MemoryPathDescriptor;
|
|
94
|
+
/**
|
|
95
|
+
* Renders the whitelist as a compact bullet list, used inside the flush
|
|
96
|
+
* prompt so the LLM sees the authoritative rubric at inference time.
|
|
97
|
+
*
|
|
98
|
+
* Output shape:
|
|
99
|
+
* - memory/agent/playbook.md [Playbook, shared] — <description>
|
|
100
|
+
* - memory/agent/pitfalls.md [Pitfalls, shared] — <description>
|
|
101
|
+
* ...
|
|
102
|
+
*
|
|
103
|
+
* The `[Label, shared|private]` tag tells the model whether the doc is
|
|
104
|
+
* visible to all users (agent tier) or only to the caller (user tier).
|
|
105
|
+
* Filtered to only the paths writable for the given scope.
|
|
106
|
+
*/
|
|
107
|
+
export declare function renderPathsRubric(scope: Pick<MemoryScope, 'userId'>): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres + pgvector implementation of {@link MemoryBackend}.
|
|
3
|
+
*
|
|
4
|
+
* ## Scoping model (two-tier, layered)
|
|
5
|
+
*
|
|
6
|
+
* Every read query applies the layered filter
|
|
7
|
+
*
|
|
8
|
+
* WHERE agent_id = $1 AND (user_id IS NULL OR user_id = $2)
|
|
9
|
+
*
|
|
10
|
+
* so the caller sees:
|
|
11
|
+
* - agent-tier rows (`user_id IS NULL`) — shared operational knowledge,
|
|
12
|
+
* visible to every user of the agent
|
|
13
|
+
* - their own user-tier rows (`user_id = <caller>`) — private per-user
|
|
14
|
+
* personalization
|
|
15
|
+
*
|
|
16
|
+
* Another user's user-tier rows are invisible — the privacy boundary is
|
|
17
|
+
* enforced in SQL, not just in the UI or route layer.
|
|
18
|
+
*
|
|
19
|
+
* ## Writes
|
|
20
|
+
*
|
|
21
|
+
* `append()` routes to a row based on the path's tier, resolved via
|
|
22
|
+
* {@link assertWritablePath}:
|
|
23
|
+
*
|
|
24
|
+
* - `memory/agent/*` → stored with `user_id = NULL` regardless of
|
|
25
|
+
* what scope the caller passed. Agent-tier content is inherently
|
|
26
|
+
* shared; scoping it per-user would defeat the point.
|
|
27
|
+
* - `memory/user/*` → stored with `user_id = scope.userId`. A missing
|
|
28
|
+
* `scope.userId` throws — user-tier paths cannot be written from
|
|
29
|
+
* isolated/autonomous contexts.
|
|
30
|
+
*
|
|
31
|
+
* UPSERT key is `(agent_id, user_id, path)` with `NULLS NOT DISTINCT`,
|
|
32
|
+
* so each user gets their own `user/preferences.md` row and there is
|
|
33
|
+
* exactly one `agent/playbook.md` row shared across the whole user base.
|
|
34
|
+
* Content accumulates via `\n\n` concatenation on conflict, with the
|
|
35
|
+
* embedding regenerated over the merged content so search stays
|
|
36
|
+
* consistent.
|
|
37
|
+
*/
|
|
38
|
+
import type { Pool } from 'pg';
|
|
39
|
+
import { type EmbeddingProvider } from './embeddings';
|
|
40
|
+
import type { MemoryAppendInput, MemoryBackend, MemoryEntry, MemoryGetOptions, MemoryHealth, MemoryReadResult, MemoryScope, MemorySearchOptions } from './types';
|
|
41
|
+
export interface PgvectorStoreOptions {
|
|
42
|
+
pool: Pool;
|
|
43
|
+
table?: string;
|
|
44
|
+
embedder?: EmbeddingProvider;
|
|
45
|
+
}
|
|
46
|
+
export declare class PgvectorMemoryStore implements MemoryBackend {
|
|
47
|
+
readonly kind: "vector";
|
|
48
|
+
private pool;
|
|
49
|
+
private table;
|
|
50
|
+
private embedder;
|
|
51
|
+
constructor(opts: PgvectorStoreOptions);
|
|
52
|
+
search(scope: MemoryScope, query: string, opts?: MemorySearchOptions): Promise<MemoryEntry[]>;
|
|
53
|
+
get(scope: MemoryScope, opts: MemoryGetOptions): Promise<MemoryReadResult | null>;
|
|
54
|
+
append(scope: MemoryScope, input: MemoryAppendInput): Promise<void>;
|
|
55
|
+
health(): Promise<MemoryHealth>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Pool } from 'pg';
|
|
2
|
+
export interface RecallTracker {
|
|
3
|
+
/** Record that the given memory ids were surfaced to the model for a query. */
|
|
4
|
+
record(params: RecallRecordParams): Promise<void>;
|
|
5
|
+
/** Backend-specific schema migration. Idempotent. */
|
|
6
|
+
migrate(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface RecallRecordParams {
|
|
9
|
+
agentId: string;
|
|
10
|
+
query: string;
|
|
11
|
+
hits: Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
path: string;
|
|
14
|
+
score: number;
|
|
15
|
+
}>;
|
|
16
|
+
nowMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const RECALL_TABLE = "agent_memory_recalls";
|
|
19
|
+
export declare class PgvectorRecallTracker implements RecallTracker {
|
|
20
|
+
private readonly pool;
|
|
21
|
+
private readonly table;
|
|
22
|
+
constructor(pool: Pool, table?: string);
|
|
23
|
+
migrate(): Promise<void>;
|
|
24
|
+
record(params: RecallRecordParams): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** No-op tracker — used when recall tracking is disabled or the backend isn't pgvector. */
|
|
27
|
+
export declare class NullRecallTracker implements RecallTracker {
|
|
28
|
+
record(): Promise<void>;
|
|
29
|
+
migrate(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Temporal decay — Phase 2.
|
|
3
|
+
*
|
|
4
|
+
* Ported from upstream `extensions/memory-core/src/memory/temporal-decay.ts`.
|
|
5
|
+
* Ages dated memory files (`memory/YYYY-MM-DD.md`) using exponential decay
|
|
6
|
+
* `multiplier = exp(-ln(2) / halfLifeDays * ageInDays)`. At half-life, the
|
|
7
|
+
* score is exactly halved.
|
|
8
|
+
*
|
|
9
|
+
* Evergreen files (MEMORY.md, memory/topics.md, any non-dated file inside
|
|
10
|
+
* memory/) do NOT decay — they represent durable knowledge and should stay
|
|
11
|
+
* hot regardless of age. This mirrors upstream's `isEvergreenMemoryPath`.
|
|
12
|
+
*
|
|
13
|
+
* Since our pgvector rows carry `createdAt`, we don't need filesystem stat
|
|
14
|
+
* fallback — the row timestamp is authoritative for any file without a
|
|
15
|
+
* date in the path.
|
|
16
|
+
*/
|
|
17
|
+
export interface TemporalDecayConfig {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
halfLifeDays: number;
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_TEMPORAL_DECAY_CONFIG: TemporalDecayConfig;
|
|
22
|
+
export declare function toDecayLambda(halfLifeDays: number): number;
|
|
23
|
+
export declare function calculateTemporalDecayMultiplier(params: {
|
|
24
|
+
ageInDays: number;
|
|
25
|
+
halfLifeDays: number;
|
|
26
|
+
}): number;
|
|
27
|
+
export declare function applyTemporalDecayToScore(params: {
|
|
28
|
+
score: number;
|
|
29
|
+
ageInDays: number;
|
|
30
|
+
halfLifeDays: number;
|
|
31
|
+
}): number;
|
|
32
|
+
/** Parse a date out of `memory/YYYY-MM-DD.md` — returns null on non-match or invalid date. */
|
|
33
|
+
export declare function parseMemoryDateFromPath(filePath: string): Date | null;
|
|
34
|
+
/**
|
|
35
|
+
* Evergreen = durable knowledge file that should not decay.
|
|
36
|
+
* - `MEMORY.md` / `memory.md` at root
|
|
37
|
+
* - anything inside `memory/` that is NOT a dated `YYYY-MM-DD.md` file
|
|
38
|
+
*/
|
|
39
|
+
export declare function isEvergreenMemoryPath(filePath: string): boolean;
|
|
40
|
+
export interface DecayCandidate {
|
|
41
|
+
path: string;
|
|
42
|
+
score: number;
|
|
43
|
+
createdAt?: Date;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Apply temporal decay to a list of memory hits.
|
|
47
|
+
*
|
|
48
|
+
* Priority for the effective timestamp:
|
|
49
|
+
* 1. Dated path (`memory/YYYY-MM-DD.md`) — use the date in the path
|
|
50
|
+
* 2. Otherwise, if the path is evergreen — NO decay
|
|
51
|
+
* 3. Otherwise, use the row's `createdAt`
|
|
52
|
+
*/
|
|
53
|
+
export declare function applyTemporalDecayToHits<T extends DecayCandidate>(hits: T[], config?: Partial<TemporalDecayConfig>, nowMs?: number): T[];
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autonomous memory — core types.
|
|
3
|
+
*
|
|
4
|
+
* Ported from upstream's memory-core pattern, adapted for Postgres + pgvector
|
|
5
|
+
* and shaped so a future graph-backend layer (Graphiti, Neo4j agent-memory, etc.)
|
|
6
|
+
* can be added alongside the vector store without changing the tool contracts.
|
|
7
|
+
*
|
|
8
|
+
* Architectural boundary: the LLM tools ({@link MemoryBackend}) never talk to
|
|
9
|
+
* Postgres directly — they go through an interface that a vector store,
|
|
10
|
+
* a graph store, or a composite of both can satisfy.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Scope key for memory isolation.
|
|
14
|
+
*
|
|
15
|
+
* Two-tier model:
|
|
16
|
+
* - Agent-tier rows (`memory/agent/*`) are stored with `user_id = NULL`
|
|
17
|
+
* and are shared across every user of the agent.
|
|
18
|
+
* - User-tier rows (`memory/user/*`) are stored with the caller's
|
|
19
|
+
* `userId` and are private to that caller; other users of the same
|
|
20
|
+
* agent never see them.
|
|
21
|
+
*
|
|
22
|
+
* Every read query applies `WHERE agent_id = $1 AND (user_id IS NULL OR
|
|
23
|
+
* user_id = $caller)`, so the caller sees shared rows plus their own.
|
|
24
|
+
* `userId` is therefore both the write target (for user-tier paths) AND
|
|
25
|
+
* the read filter. An absent `userId` is legal — it just means this
|
|
26
|
+
* scope is isolated/autonomous and the user tier is inert.
|
|
27
|
+
*
|
|
28
|
+
* Captured at tool construction time in a closure and NEVER exposed as
|
|
29
|
+
* tool parameters. The LLM cannot override either field.
|
|
30
|
+
*/
|
|
31
|
+
export interface MemoryScope {
|
|
32
|
+
agentId: string;
|
|
33
|
+
/**
|
|
34
|
+
* The caller's identity, used for user-tier writes AND the layered
|
|
35
|
+
* read filter. Undefined/null for isolated/autonomous agents — in
|
|
36
|
+
* that case only agent-tier rows are visible and writable.
|
|
37
|
+
*/
|
|
38
|
+
userId?: string | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One retrieved memory record.
|
|
42
|
+
*
|
|
43
|
+
* `score` is a unit-interval hybrid score (0..1): 0.7 * cosine + 0.3 * text
|
|
44
|
+
* rank in the default pgvector backend. A graph backend is free to produce
|
|
45
|
+
* its own score as long as it stays within that range.
|
|
46
|
+
*/
|
|
47
|
+
export interface MemoryEntry {
|
|
48
|
+
id: string;
|
|
49
|
+
path: string;
|
|
50
|
+
content: string;
|
|
51
|
+
score: number;
|
|
52
|
+
createdAt: Date;
|
|
53
|
+
/**
|
|
54
|
+
* Which backend surfaced this entry. Lets a composite store tag results so
|
|
55
|
+
* downstream consumers (tests, telemetry, UI) can distinguish vector hits
|
|
56
|
+
* from graph hits without inspecting the ID format.
|
|
57
|
+
*/
|
|
58
|
+
source?: MemoryBackendKind;
|
|
59
|
+
/**
|
|
60
|
+
* Which tier the row belongs to — derived from the path at read time.
|
|
61
|
+
* See `./paths.ts` for the whitelist. UI groups rows by this field
|
|
62
|
+
* so users can see which memories are shared (agent tier) vs private
|
|
63
|
+
* (user tier).
|
|
64
|
+
*/
|
|
65
|
+
tier?: 'agent' | 'user';
|
|
66
|
+
/** Citation marker (Phase 2) — e.g. `memory/agent/playbook.md#L1-L8`. */
|
|
67
|
+
citation?: string;
|
|
68
|
+
/** 1-indexed start/end line range used to build the citation. */
|
|
69
|
+
startLine?: number;
|
|
70
|
+
endLine?: number;
|
|
71
|
+
}
|
|
72
|
+
export type MemoryBackendKind = 'vector' | 'graph' | 'composite';
|
|
73
|
+
export interface MemorySearchOptions {
|
|
74
|
+
maxResults?: number;
|
|
75
|
+
minScore?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Phase 2 toggles — when the backend supports them. Each is independently
|
|
78
|
+
* opt-in; all false = upstream Phase 1 behavior.
|
|
79
|
+
*/
|
|
80
|
+
mmr?: {
|
|
81
|
+
enabled?: boolean;
|
|
82
|
+
lambda?: number;
|
|
83
|
+
};
|
|
84
|
+
temporalDecay?: {
|
|
85
|
+
enabled?: boolean;
|
|
86
|
+
halfLifeDays?: number;
|
|
87
|
+
};
|
|
88
|
+
/** Citation mode: 'on' decorates; 'off' strips; 'auto' = on for direct chat. */
|
|
89
|
+
citations?: 'on' | 'off' | 'auto';
|
|
90
|
+
}
|
|
91
|
+
export interface MemoryGetOptions {
|
|
92
|
+
path: string;
|
|
93
|
+
from?: number;
|
|
94
|
+
lines?: number;
|
|
95
|
+
}
|
|
96
|
+
export interface MemoryReadResult {
|
|
97
|
+
path: string;
|
|
98
|
+
text: string;
|
|
99
|
+
}
|
|
100
|
+
export interface MemoryAppendInput {
|
|
101
|
+
/** Must begin with "memory/". Enforced by the append tool wrapper. */
|
|
102
|
+
path: string;
|
|
103
|
+
content: string;
|
|
104
|
+
}
|
|
105
|
+
export interface MemoryHealth {
|
|
106
|
+
ok: boolean;
|
|
107
|
+
backend: MemoryBackendKind;
|
|
108
|
+
error?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The contract every memory backend implements.
|
|
112
|
+
*
|
|
113
|
+
* A Phase 1 pgvector store satisfies this directly. A Phase 4 graph store
|
|
114
|
+
* (Graphiti / Neo4j agent-memory) will implement the same interface and plug
|
|
115
|
+
* into a {@link CompositeMemoryBackend} without touching the tools.
|
|
116
|
+
*/
|
|
117
|
+
export interface MemoryBackend {
|
|
118
|
+
readonly kind: MemoryBackendKind;
|
|
119
|
+
search(scope: MemoryScope, query: string, opts?: MemorySearchOptions): Promise<MemoryEntry[]>;
|
|
120
|
+
get(scope: MemoryScope, opts: MemoryGetOptions): Promise<MemoryReadResult | null>;
|
|
121
|
+
append(scope: MemoryScope, input: MemoryAppendInput): Promise<void>;
|
|
122
|
+
health(): Promise<MemoryHealth>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Historical alias kept for one release so external consumers can still import
|
|
126
|
+
* the name used in the plan doc. New code should prefer {@link MemoryBackend}.
|
|
127
|
+
*
|
|
128
|
+
* @deprecated use {@link MemoryBackend}
|
|
129
|
+
*/
|
|
130
|
+
export type MemoryStore = MemoryBackend;
|
|
131
|
+
/**
|
|
132
|
+
* Optional configuration bundle plumbed through `createAgentNode`.
|
|
133
|
+
* Missing config = memory fully disabled, no tools attached.
|
|
134
|
+
*/
|
|
135
|
+
export interface MemoryConfig {
|
|
136
|
+
backend: MemoryBackend;
|
|
137
|
+
scope: MemoryScope;
|
|
138
|
+
flush?: {
|
|
139
|
+
softThresholdTokens?: number;
|
|
140
|
+
reserveFloorTokens?: number;
|
|
141
|
+
windowTokens?: number;
|
|
142
|
+
enabled?: boolean;
|
|
143
|
+
};
|
|
144
|
+
search?: {
|
|
145
|
+
maxResults?: number;
|
|
146
|
+
maxInjectedChars?: number;
|
|
147
|
+
/** Phase 2 — enable MMR reranking (upstream-aligned defaults when true). */
|
|
148
|
+
mmr?: {
|
|
149
|
+
enabled?: boolean;
|
|
150
|
+
lambda?: number;
|
|
151
|
+
};
|
|
152
|
+
/** Phase 2 — enable temporal decay on dated memory files. */
|
|
153
|
+
temporalDecay?: {
|
|
154
|
+
enabled?: boolean;
|
|
155
|
+
halfLifeDays?: number;
|
|
156
|
+
};
|
|
157
|
+
/** Phase 2 — citation mode. Defaults to 'auto'. */
|
|
158
|
+
citations?: 'on' | 'off' | 'auto';
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Phase 2 — optional recall tracker. When set, memory_search fires a
|
|
162
|
+
* best-effort recall record after each successful call. Failures are
|
|
163
|
+
* swallowed so recall tracking never blocks the tool result.
|
|
164
|
+
*/
|
|
165
|
+
recallTracker?: {
|
|
166
|
+
record(params: {
|
|
167
|
+
agentId: string;
|
|
168
|
+
query: string;
|
|
169
|
+
hits: Array<{
|
|
170
|
+
id: string;
|
|
171
|
+
path: string;
|
|
172
|
+
score: number;
|
|
173
|
+
}>;
|
|
174
|
+
}): Promise<void>;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Phase state accessor. Returns the current phase so the append-tool wrapper
|
|
178
|
+
* can gate writes to the reflection phase. Supplied by the graph runtime.
|
|
179
|
+
*/
|
|
180
|
+
getPhase?: () => MemoryPhase;
|
|
181
|
+
}
|
|
182
|
+
export type MemoryPhase = 'normal' | 'memory_flushing';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory-flush prompt resolver.
|
|
3
|
+
*
|
|
4
|
+
* The raw prompt strings live in `src/memory/constants.ts` and contain a
|
|
5
|
+
* single `{{MEMORY_PATHS_RUBRIC}}` placeholder. This module substitutes
|
|
6
|
+
* the caller-scoped rubric (produced by `renderPathsRubric()` in
|
|
7
|
+
* `src/memory/paths.ts`) into that placeholder at flush time, so:
|
|
8
|
+
*
|
|
9
|
+
* - a collaborative agent with a real caller sees all 8 paths
|
|
10
|
+
* - an isolated/autonomous agent sees only the 4 agent-tier paths
|
|
11
|
+
* (user-tier rows are physically omitted from the rubric the LLM
|
|
12
|
+
* sees, so it cannot route writes there even by mistake)
|
|
13
|
+
*
|
|
14
|
+
* ## Why this lives in prompts/ and not memory/constants.ts
|
|
15
|
+
*
|
|
16
|
+
* The constants file is pure strings — no imports, no runtime work.
|
|
17
|
+
* Injecting the rubric needs access to `renderPathsRubric()` which
|
|
18
|
+
* needs `MemoryScope`, so the substitution has to happen one layer up.
|
|
19
|
+
* Keeping the placeholder in constants and the substitution here means
|
|
20
|
+
* tests of the raw prompt (no scope) and tests of the rendered prompt
|
|
21
|
+
* (scope-aware) stay independent.
|
|
22
|
+
*/
|
|
23
|
+
import { DEFAULT_MEMORY_FLUSH_PROMPT, DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT } from '@/memory/constants';
|
|
24
|
+
import type { MemoryScope } from '@/memory/types';
|
|
25
|
+
export { DEFAULT_MEMORY_FLUSH_PROMPT, DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT };
|
|
26
|
+
/** Back-compat alias so existing callers keep working. */
|
|
27
|
+
export declare const MEMORY_FLUSH_SYSTEM_PROMPT: string;
|
|
28
|
+
/** Minimum scope shape needed to render the rubric. */
|
|
29
|
+
export interface ResolveFlushPromptsOptions {
|
|
30
|
+
/**
|
|
31
|
+
* The scope the memory tools were built with. Only `userId` matters
|
|
32
|
+
* for rubric rendering — if absent, the user-tier paths are filtered
|
|
33
|
+
* out of the rubric the LLM sees.
|
|
34
|
+
*/
|
|
35
|
+
scope: Pick<MemoryScope, 'userId'>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result shape returned to `runMemoryFlush`. `prompt` goes in the
|
|
39
|
+
* HumanMessage, `systemPrompt` goes in the SystemMessage. Both already
|
|
40
|
+
* have the rubric substituted — the caller should pass them through
|
|
41
|
+
* verbatim.
|
|
42
|
+
*/
|
|
43
|
+
export interface ResolvedFlushPrompts {
|
|
44
|
+
prompt: string;
|
|
45
|
+
systemPrompt: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Substitutes the paths rubric into the raw prompts for a given scope.
|
|
49
|
+
*
|
|
50
|
+
* Idempotent (calling it twice on already-resolved strings is a no-op
|
|
51
|
+
* because the placeholder will have been replaced already). Safe to
|
|
52
|
+
* call per-flush; no caching needed — the string concat is microseconds.
|
|
53
|
+
*/
|
|
54
|
+
export declare function resolveFlushPrompts(options: ResolveFlushPromptsOptions): ResolvedFlushPrompts;
|
package/dist/types/run.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class Run<_T extends t.BaseGraphState> {
|
|
|
15
15
|
Graph: StandardGraph | MultiAgentGraph | undefined;
|
|
16
16
|
returnContent: boolean;
|
|
17
17
|
private skipCleanup;
|
|
18
|
+
private _originalCallbacksSnapshot?;
|
|
18
19
|
private constructor();
|
|
19
20
|
private createLegacyGraph;
|
|
20
21
|
private createMultiAgentGraph;
|
|
@@ -38,7 +38,7 @@ export declare const AskUserStepSchema: z.ZodObject<{
|
|
|
38
38
|
export type AskUserStep = z.infer<typeof AskUserStepSchema>;
|
|
39
39
|
/**
|
|
40
40
|
* Represents a single step selection from the multi-step wizard UI.
|
|
41
|
-
* Exported for use by both
|
|
41
|
+
* Exported for use by both the host web client and browser extension.
|
|
42
42
|
*/
|
|
43
43
|
export type StepSelection = {
|
|
44
44
|
values: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
2
|
/**
|
|
3
|
-
* Browser tool names - keep in sync with
|
|
3
|
+
* Browser tool names - keep in sync with the browser extension
|
|
4
4
|
* These tools execute locally in the browser extension, NOT on the server
|
|
5
5
|
*/
|
|
6
6
|
export declare const EBrowserTools: {
|
|
@@ -20,7 +20,7 @@ export declare const EBrowserTools: {
|
|
|
20
20
|
export type BrowserToolName = (typeof EBrowserTools)[keyof typeof EBrowserTools];
|
|
21
21
|
/**
|
|
22
22
|
* Callback function type for waiting on browser action results
|
|
23
|
-
* This allows the server
|
|
23
|
+
* This allows the host server to provide a callback that waits for the extension
|
|
24
24
|
* to POST results back to the server before returning to the LLM.
|
|
25
25
|
*
|
|
26
26
|
* @param action - The browser action (click, type, navigate, etc.)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Shared HITL (Human-in-the-Loop) constants and enums.
|
|
3
3
|
*
|
|
4
4
|
* Single source of truth for approval-related values consumed by
|
|
5
|
-
* the agents library,
|
|
5
|
+
* the agents library, host backend, and browser extension.
|
|
6
6
|
*
|
|
7
7
|
* @module approval/constants
|
|
8
8
|
*/
|
|
@@ -78,6 +78,6 @@ export declare enum ActionCategory {
|
|
|
78
78
|
*
|
|
79
79
|
* Example: `send_email_mcp_outlook` → tool = `send_email`, server = `outlook`
|
|
80
80
|
*
|
|
81
|
-
* Must match
|
|
81
|
+
* Must match the host data-provider delimiter constant.
|
|
82
82
|
*/
|
|
83
83
|
export declare const MCP_DELIMITER = "_mcp_";
|