@dungle-scrubs/hippo 0.1.0
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/LICENSE +21 -0
- package/README.md +439 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +559 -0
- package/dist/cli.js.map +1 -0
- package/dist/db.d.ts +45 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +80 -0
- package/dist/db.js.map +1 -0
- package/dist/extractor.d.ts +23 -0
- package/dist/extractor.d.ts.map +1 -0
- package/dist/extractor.js +121 -0
- package/dist/extractor.js.map +1 -0
- package/dist/hash.d.ts +11 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +14 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/embedding.d.ts +27 -0
- package/dist/providers/embedding.d.ts.map +1 -0
- package/dist/providers/embedding.js +41 -0
- package/dist/providers/embedding.js.map +1 -0
- package/dist/providers/llm.d.ts +29 -0
- package/dist/providers/llm.d.ts.map +1 -0
- package/dist/providers/llm.js +74 -0
- package/dist/providers/llm.js.map +1 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +78 -0
- package/dist/schema.js.map +1 -0
- package/dist/server/config.d.ts +38 -0
- package/dist/server/config.d.ts.map +1 -0
- package/dist/server/config.js +71 -0
- package/dist/server/config.js.map +1 -0
- package/dist/server/index.d.ts +13 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +372 -0
- package/dist/server/index.js.map +1 -0
- package/dist/similarity.d.ts +41 -0
- package/dist/similarity.d.ts.map +1 -0
- package/dist/similarity.js +70 -0
- package/dist/similarity.js.map +1 -0
- package/dist/strength.d.ts +59 -0
- package/dist/strength.d.ts.map +1 -0
- package/dist/strength.js +76 -0
- package/dist/strength.js.map +1 -0
- package/dist/tools/append-memory-block.d.ts +22 -0
- package/dist/tools/append-memory-block.d.ts.map +1 -0
- package/dist/tools/append-memory-block.js +45 -0
- package/dist/tools/append-memory-block.js.map +1 -0
- package/dist/tools/forget-memory.d.ts +31 -0
- package/dist/tools/forget-memory.d.ts.map +1 -0
- package/dist/tools/forget-memory.js +77 -0
- package/dist/tools/forget-memory.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/recall-conversation.d.ts +21 -0
- package/dist/tools/recall-conversation.d.ts.map +1 -0
- package/dist/tools/recall-conversation.js +93 -0
- package/dist/tools/recall-conversation.js.map +1 -0
- package/dist/tools/recall-memories.d.ts +29 -0
- package/dist/tools/recall-memories.d.ts.map +1 -0
- package/dist/tools/recall-memories.js +106 -0
- package/dist/tools/recall-memories.js.map +1 -0
- package/dist/tools/recall-memory-block.d.ts +21 -0
- package/dist/tools/recall-memory-block.d.ts.map +1 -0
- package/dist/tools/recall-memory-block.js +36 -0
- package/dist/tools/recall-memory-block.js.map +1 -0
- package/dist/tools/remember-facts.d.ts +30 -0
- package/dist/tools/remember-facts.d.ts.map +1 -0
- package/dist/tools/remember-facts.js +235 -0
- package/dist/tools/remember-facts.js.map +1 -0
- package/dist/tools/replace-memory-block.d.ts +25 -0
- package/dist/tools/replace-memory-block.d.ts.map +1 -0
- package/dist/tools/replace-memory-block.js +69 -0
- package/dist/tools/replace-memory-block.js.map +1 -0
- package/dist/tools/store-memory.d.ts +27 -0
- package/dist/tools/store-memory.d.ts.map +1 -0
- package/dist/tools/store-memory.js +129 -0
- package/dist/tools/store-memory.js.map +1 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ulid.d.ts +13 -0
- package/dist/ulid.d.ts.map +1 -0
- package/dist/ulid.js +39 -0
- package/dist/ulid.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall-memories.js","sourceRoot":"","sources":["../../src/tools/recall-memories.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAqB,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EACN,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,WAAW,GACX,MAAM,gBAAgB,CAAC;AAGxB,sEAAsE;AACtE,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,6DAA6D;AAC7D,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC,+EAA+E;AAC/E,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC,CAAC;AAEzE;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,GAAY;IACtC,OAAO,CACN,GAAG,YAAY,KAAK;QACpB,MAAM,IAAI,GAAG;QACb,sBAAsB,CAAC,GAAG,CAAE,GAAgC,CAAC,IAAI,CAAC,CAClE,CAAC;AACH,CAAC;AAED,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1B,KAAK,EAAE,IAAI,CAAC,QAAQ,CACnB,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,qCAAqC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAC/E;IACD,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;CACnE,CAAC,CAAC;AAaH;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACvC,IAA+B;IAE/B,OAAO;QACN,WAAW,EACV,6GAA6G;QAC9G,OAAO,EAAE,KAAK,EAAE,WAAW,EA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I,EAAE,MAAM,EAAE,CAAC;oBACvD,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;iBACxB,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;YAED,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAC3B,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CACzF,CAAC;YAEF,MAAM,MAAM,GAA0D;gBACrE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gBACnD,OAAO,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;aAChC,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;QACD,KAAK,EAAE,iBAAiB;QACxB,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE,MAAM;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { DbStatements } from "../db.js";
|
|
3
|
+
declare const Params: import("@sinclair/typebox").TObject<{
|
|
4
|
+
key: import("@sinclair/typebox").TString;
|
|
5
|
+
}>;
|
|
6
|
+
/** Options for creating the recall_memory_block tool. */
|
|
7
|
+
export interface RecallMemoryBlockToolOptions {
|
|
8
|
+
readonly agentId: string;
|
|
9
|
+
readonly stmts: DbStatements;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create the recall_memory_block tool.
|
|
13
|
+
*
|
|
14
|
+
* Returns the contents of a named memory block, or null if it doesn't exist.
|
|
15
|
+
*
|
|
16
|
+
* @param opts - Tool options
|
|
17
|
+
* @returns AgentTool instance
|
|
18
|
+
*/
|
|
19
|
+
export declare function createRecallMemoryBlockTool(opts: RecallMemoryBlockToolOptions): AgentTool<typeof Params>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=recall-memory-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall-memory-block.d.ts","sourceRoot":"","sources":["../../src/tools/recall-memory-block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,QAAA,MAAM,MAAM;;EAIV,CAAC;AAEH,yDAAyD;AACzD,MAAM,WAAW,4BAA4B;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAC1C,IAAI,EAAE,4BAA4B,GAChC,SAAS,CAAC,OAAO,MAAM,CAAC,CAsB1B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Type } from "@mariozechner/pi-ai";
|
|
2
|
+
const Params = Type.Object({
|
|
3
|
+
key: Type.String({
|
|
4
|
+
description: "Block name to retrieve (e.g. 'persona', 'human', 'objectives')",
|
|
5
|
+
}),
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Create the recall_memory_block tool.
|
|
9
|
+
*
|
|
10
|
+
* Returns the contents of a named memory block, or null if it doesn't exist.
|
|
11
|
+
*
|
|
12
|
+
* @param opts - Tool options
|
|
13
|
+
* @returns AgentTool instance
|
|
14
|
+
*/
|
|
15
|
+
export function createRecallMemoryBlockTool(opts) {
|
|
16
|
+
return {
|
|
17
|
+
description: "Retrieve the contents of a named memory block. Returns null if the block doesn't exist.",
|
|
18
|
+
execute: async (_toolCallId, params) => {
|
|
19
|
+
const row = opts.stmts.getBlockByKey.get(opts.agentId, params.key);
|
|
20
|
+
const result = {
|
|
21
|
+
content: [
|
|
22
|
+
{
|
|
23
|
+
text: row ? row.value : "null",
|
|
24
|
+
type: "text",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
details: { value: row?.value ?? null },
|
|
28
|
+
};
|
|
29
|
+
return result;
|
|
30
|
+
},
|
|
31
|
+
label: "Recall Memory Block",
|
|
32
|
+
name: "recall_memory_block",
|
|
33
|
+
parameters: Params,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=recall-memory-block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall-memory-block.js","sourceRoot":"","sources":["../../src/tools/recall-memory-block.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAI3C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1B,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;QAChB,WAAW,EAAE,gEAAgE;KAC7E,CAAC;CACF,CAAC,CAAC;AAQH;;;;;;;GAOG;AACH,MAAM,UAAU,2BAA2B,CAC1C,IAAkC;IAElC,OAAO;QACN,WAAW,EACV,yFAAyF;QAC1F,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE;YACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAA4B,CAAC;YAE9F,MAAM,MAAM,GAA8C;gBACzD,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM;wBAC9B,IAAI,EAAE,MAAM;qBACZ;iBACD;gBACD,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,IAAI,EAAE;aACtC,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;QACD,KAAK,EAAE,qBAAqB;QAC5B,IAAI,EAAE,qBAAqB;QAC3B,UAAU,EAAE,MAAM;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { Database } from "better-sqlite3";
|
|
3
|
+
import { type DbStatements } from "../db.js";
|
|
4
|
+
import type { EmbedFn, LlmClient } from "../types.js";
|
|
5
|
+
declare const Params: import("@sinclair/typebox").TObject<{
|
|
6
|
+
text: import("@sinclair/typebox").TString;
|
|
7
|
+
}>;
|
|
8
|
+
/** Options for creating the remember_facts tool. */
|
|
9
|
+
export interface RememberFactsToolOptions {
|
|
10
|
+
readonly agentId: string;
|
|
11
|
+
readonly db: Database;
|
|
12
|
+
readonly embed: EmbedFn;
|
|
13
|
+
readonly llm: LlmClient;
|
|
14
|
+
/** Max existing facts to load for conflict resolution (default: 10,000). */
|
|
15
|
+
readonly maxSearchFacts?: number;
|
|
16
|
+
/** Max input text length in characters (default: 10,000). */
|
|
17
|
+
readonly maxTextLength?: number;
|
|
18
|
+
readonly stmts: DbStatements;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create the remember_facts tool.
|
|
22
|
+
*
|
|
23
|
+
* Full pipeline: extract → embed → conflict check → insert/replace/strengthen.
|
|
24
|
+
*
|
|
25
|
+
* @param opts - Tool options
|
|
26
|
+
* @returns AgentTool instance
|
|
27
|
+
*/
|
|
28
|
+
export declare function createRememberFactsTool(opts: RememberFactsToolOptions): AgentTool<typeof Params>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=remember-facts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remember-facts.d.ts","sourceRoot":"","sources":["../../src/tools/remember-facts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,UAAU,CAAC;AAI9D,OAAO,KAAK,EAEX,OAAO,EACP,SAAS,EAGT,MAAM,aAAa,CAAC;AAgBrB,QAAA,MAAM,MAAM;;EAIV,CAAC;AAEH,oDAAoD;AACpD,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,wBAAwB,GAAG,SAAS,CAAC,OAAO,MAAM,CAAC,CAkEhG"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { Type } from "@mariozechner/pi-ai";
|
|
2
|
+
import { getActiveChunks } from "../db.js";
|
|
3
|
+
import { classifyConflict, extractFacts } from "../extractor.js";
|
|
4
|
+
import { chunkEmbedding, cosineSimilarity, embeddingToBuffer } from "../similarity.js";
|
|
5
|
+
import { updatedIntensity } from "../strength.js";
|
|
6
|
+
import { ulid } from "../ulid.js";
|
|
7
|
+
/** Similarity thresholds for auto-classification. */
|
|
8
|
+
const DUPLICATE_THRESHOLD = 0.93;
|
|
9
|
+
const AMBIGUOUS_THRESHOLD = 0.78;
|
|
10
|
+
/** Top N existing chunks to compare against. */
|
|
11
|
+
const TOP_K_CANDIDATES = 5;
|
|
12
|
+
/** Default max existing facts to load for conflict resolution. */
|
|
13
|
+
const DEFAULT_MAX_SEARCH_FACTS = 10_000;
|
|
14
|
+
/** Maximum input text length in characters (default 10KB). */
|
|
15
|
+
const MAX_TEXT_LENGTH = 10_000;
|
|
16
|
+
const Params = Type.Object({
|
|
17
|
+
text: Type.String({
|
|
18
|
+
description: "Text containing facts to extract and remember",
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Create the remember_facts tool.
|
|
23
|
+
*
|
|
24
|
+
* Full pipeline: extract → embed → conflict check → insert/replace/strengthen.
|
|
25
|
+
*
|
|
26
|
+
* @param opts - Tool options
|
|
27
|
+
* @returns AgentTool instance
|
|
28
|
+
*/
|
|
29
|
+
export function createRememberFactsTool(opts) {
|
|
30
|
+
return {
|
|
31
|
+
description: "Extract discrete facts from text, rate their intensity, check for conflicts with existing knowledge, and store. Handles duplicates, supersession, and new facts.",
|
|
32
|
+
execute: async (_toolCallId, params, signal) => {
|
|
33
|
+
const maxLen = opts.maxTextLength ?? MAX_TEXT_LENGTH;
|
|
34
|
+
if (params.text.length > maxLen) {
|
|
35
|
+
throw new Error(`Input text too long (${params.text.length} chars, max ${maxLen}). Summarize or chunk the text first.`);
|
|
36
|
+
}
|
|
37
|
+
const extracted = await extractFacts(params.text, opts.llm, signal);
|
|
38
|
+
if (extracted.length === 0) {
|
|
39
|
+
const result = {
|
|
40
|
+
content: [{ text: "No facts extracted.", type: "text" }],
|
|
41
|
+
details: { facts: [] },
|
|
42
|
+
};
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
const actions = [];
|
|
46
|
+
// No transaction wrapper — intentional. Each fact is independently meaningful,
|
|
47
|
+
// so partial insertion on mid-batch failure is acceptable. The alternative
|
|
48
|
+
// (all-or-nothing) would discard successfully processed facts on a transient
|
|
49
|
+
// embed/LLM error, which is worse for the user.
|
|
50
|
+
//
|
|
51
|
+
// Load facts once — processFact maintains this array across iterations
|
|
52
|
+
// for intra-batch visibility (e.g., dedup between extracted facts).
|
|
53
|
+
const maxFacts = opts.maxSearchFacts ?? DEFAULT_MAX_SEARCH_FACTS;
|
|
54
|
+
const existingFacts = getActiveChunks(opts.stmts, opts.agentId, "fact", maxFacts);
|
|
55
|
+
for (const { fact, intensity } of extracted) {
|
|
56
|
+
const action = await processFact(fact, intensity, existingFacts, opts, signal);
|
|
57
|
+
actions.push(action);
|
|
58
|
+
}
|
|
59
|
+
const summary = actions
|
|
60
|
+
.map((a) => {
|
|
61
|
+
switch (a.action) {
|
|
62
|
+
case "inserted":
|
|
63
|
+
return `New: "${a.content}" (intensity: ${a.intensity.toFixed(2)})`;
|
|
64
|
+
case "reinforced":
|
|
65
|
+
return `Reinforced: "${a.content}" (${a.oldIntensity.toFixed(2)} → ${a.newIntensity.toFixed(2)})`;
|
|
66
|
+
case "superseded":
|
|
67
|
+
return `Superseded: "${a.oldContent}" → "${a.content}"`;
|
|
68
|
+
default: {
|
|
69
|
+
const _exhaustive = a;
|
|
70
|
+
return _exhaustive;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.join("\n");
|
|
75
|
+
const result = {
|
|
76
|
+
content: [{ text: `Processed ${actions.length} facts:\n${summary}`, type: "text" }],
|
|
77
|
+
details: { facts: actions },
|
|
78
|
+
};
|
|
79
|
+
return result;
|
|
80
|
+
},
|
|
81
|
+
label: "Remember Facts",
|
|
82
|
+
name: "remember_facts",
|
|
83
|
+
parameters: Params,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Process a single extracted fact through the conflict resolution pipeline.
|
|
88
|
+
*
|
|
89
|
+
* Mutates `existingFacts` to reflect inserts, reinforcements, and supersessions
|
|
90
|
+
* so subsequent facts in the same batch see up-to-date state without re-querying.
|
|
91
|
+
*
|
|
92
|
+
* @param fact - Extracted fact text
|
|
93
|
+
* @param intensity - Rated intensity [0, 1]
|
|
94
|
+
* @param existingFacts - Mutable array of active fact chunks (updated in place)
|
|
95
|
+
* @param opts - Tool options
|
|
96
|
+
* @param signal - Optional abort signal
|
|
97
|
+
* @returns Action taken for this fact
|
|
98
|
+
*/
|
|
99
|
+
async function processFact(fact, intensity, existingFacts, opts, signal) {
|
|
100
|
+
const now = new Date().toISOString();
|
|
101
|
+
const embedding = await opts.embed(fact, signal);
|
|
102
|
+
const embeddingBuf = embeddingToBuffer(embedding);
|
|
103
|
+
// Find top candidates by similarity
|
|
104
|
+
const candidates = findTopCandidates(embedding, existingFacts, TOP_K_CANDIDATES);
|
|
105
|
+
// Check best candidate for conflict
|
|
106
|
+
const best = candidates[0];
|
|
107
|
+
if (!best || best.similarity < AMBIGUOUS_THRESHOLD) {
|
|
108
|
+
// NEW — no similar existing fact
|
|
109
|
+
const chunk = {
|
|
110
|
+
access_count: 0,
|
|
111
|
+
agent_id: opts.agentId,
|
|
112
|
+
content: fact,
|
|
113
|
+
content_hash: null,
|
|
114
|
+
created_at: now,
|
|
115
|
+
embedding: embeddingBuf,
|
|
116
|
+
encounter_count: 1,
|
|
117
|
+
id: ulid(),
|
|
118
|
+
kind: "fact",
|
|
119
|
+
last_accessed_at: now,
|
|
120
|
+
metadata: null,
|
|
121
|
+
running_intensity: intensity,
|
|
122
|
+
superseded_by: null,
|
|
123
|
+
};
|
|
124
|
+
opts.stmts.insertChunk.run(chunk);
|
|
125
|
+
existingFacts.push(chunk);
|
|
126
|
+
return { action: "inserted", content: fact, intensity };
|
|
127
|
+
}
|
|
128
|
+
// Determine classification
|
|
129
|
+
let classification;
|
|
130
|
+
if (best.similarity > DUPLICATE_THRESHOLD) {
|
|
131
|
+
classification = "DUPLICATE";
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// Ambiguous band — ask LLM
|
|
135
|
+
classification = await classifyConflict(fact, best.chunk.content, opts.llm, signal);
|
|
136
|
+
}
|
|
137
|
+
switch (classification) {
|
|
138
|
+
case "DUPLICATE": {
|
|
139
|
+
const newIntensity = updatedIntensity(best.chunk.running_intensity, best.chunk.encounter_count, intensity);
|
|
140
|
+
opts.stmts.reinforceChunk.run({
|
|
141
|
+
id: best.chunk.id,
|
|
142
|
+
last_accessed_at: now,
|
|
143
|
+
running_intensity: newIntensity,
|
|
144
|
+
});
|
|
145
|
+
// Update in-memory entry so subsequent facts see current values
|
|
146
|
+
const idx = existingFacts.indexOf(best.chunk);
|
|
147
|
+
if (idx !== -1) {
|
|
148
|
+
existingFacts[idx] = {
|
|
149
|
+
...best.chunk,
|
|
150
|
+
access_count: best.chunk.access_count + 1,
|
|
151
|
+
encounter_count: best.chunk.encounter_count + 1,
|
|
152
|
+
last_accessed_at: now,
|
|
153
|
+
running_intensity: newIntensity,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
action: "reinforced",
|
|
158
|
+
content: best.chunk.content,
|
|
159
|
+
newIntensity,
|
|
160
|
+
oldIntensity: best.chunk.running_intensity,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
case "SUPERSEDES": {
|
|
164
|
+
const newId = ulid();
|
|
165
|
+
const chunk = {
|
|
166
|
+
access_count: 0,
|
|
167
|
+
agent_id: opts.agentId,
|
|
168
|
+
content: fact,
|
|
169
|
+
content_hash: null,
|
|
170
|
+
created_at: now,
|
|
171
|
+
embedding: embeddingBuf,
|
|
172
|
+
encounter_count: 1,
|
|
173
|
+
id: newId,
|
|
174
|
+
kind: "fact",
|
|
175
|
+
last_accessed_at: now,
|
|
176
|
+
metadata: null,
|
|
177
|
+
running_intensity: intensity,
|
|
178
|
+
superseded_by: null,
|
|
179
|
+
};
|
|
180
|
+
// Atomic: insert replacement then mark old as superseded.
|
|
181
|
+
// If either fails, neither commits — no dangling superseded_by refs.
|
|
182
|
+
opts.db.transaction(() => {
|
|
183
|
+
opts.stmts.insertChunk.run(chunk);
|
|
184
|
+
opts.stmts.supersedeChunk.run(newId, best.chunk.id);
|
|
185
|
+
})();
|
|
186
|
+
// Update in-memory array after successful commit
|
|
187
|
+
const idx = existingFacts.indexOf(best.chunk);
|
|
188
|
+
if (idx !== -1)
|
|
189
|
+
existingFacts.splice(idx, 1);
|
|
190
|
+
existingFacts.push(chunk);
|
|
191
|
+
return {
|
|
192
|
+
action: "superseded",
|
|
193
|
+
content: fact,
|
|
194
|
+
oldContent: best.chunk.content,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
case "DISTINCT": {
|
|
198
|
+
const chunk = {
|
|
199
|
+
access_count: 0,
|
|
200
|
+
agent_id: opts.agentId,
|
|
201
|
+
content: fact,
|
|
202
|
+
content_hash: null,
|
|
203
|
+
created_at: now,
|
|
204
|
+
embedding: embeddingBuf,
|
|
205
|
+
encounter_count: 1,
|
|
206
|
+
id: ulid(),
|
|
207
|
+
kind: "fact",
|
|
208
|
+
last_accessed_at: now,
|
|
209
|
+
metadata: null,
|
|
210
|
+
running_intensity: intensity,
|
|
211
|
+
superseded_by: null,
|
|
212
|
+
};
|
|
213
|
+
opts.stmts.insertChunk.run(chunk);
|
|
214
|
+
existingFacts.push(chunk);
|
|
215
|
+
return { action: "inserted", content: fact, intensity };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Find the top K most similar existing chunks to a query embedding.
|
|
221
|
+
*
|
|
222
|
+
* @param queryEmbedding - The new fact's embedding
|
|
223
|
+
* @param existingChunks - All active chunks to search
|
|
224
|
+
* @param topK - Number of candidates to return
|
|
225
|
+
* @returns Sorted candidates (highest similarity first)
|
|
226
|
+
*/
|
|
227
|
+
function findTopCandidates(queryEmbedding, existingChunks, topK) {
|
|
228
|
+
const scored = existingChunks.map((chunk) => ({
|
|
229
|
+
chunk,
|
|
230
|
+
similarity: cosineSimilarity(queryEmbedding, chunkEmbedding(chunk)),
|
|
231
|
+
}));
|
|
232
|
+
scored.sort((a, b) => b.similarity - a.similarity);
|
|
233
|
+
return scored.slice(0, topK);
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=remember-facts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remember-facts.js","sourceRoot":"","sources":["../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GAOG;AACH,SAAS,iBAAiB,CACzB,cAA4B,EAC5B,cAAgC,EAChC,IAAY;IAEZ,MAAM,MAAM,GAAsB,cAAc,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAChE,KAAK;QACL,UAAU,EAAE,gBAAgB,CAAC,cAAc,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;KACnE,CAAC,CAAC,CAAC;IAEJ,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { DbStatements } from "../db.js";
|
|
3
|
+
declare const Params: import("@sinclair/typebox").TObject<{
|
|
4
|
+
key: import("@sinclair/typebox").TString;
|
|
5
|
+
newText: import("@sinclair/typebox").TString;
|
|
6
|
+
oldText: import("@sinclair/typebox").TString;
|
|
7
|
+
}>;
|
|
8
|
+
/** Options for creating the replace_memory_block tool. */
|
|
9
|
+
export interface ReplaceMemoryBlockToolOptions {
|
|
10
|
+
readonly agentId: string;
|
|
11
|
+
readonly stmts: DbStatements;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create the replace_memory_block tool.
|
|
15
|
+
*
|
|
16
|
+
* Performs find/replace on a named memory block. Replaces all occurrences.
|
|
17
|
+
* Returns a structured error (not a throw) if the block doesn't exist or
|
|
18
|
+
* the search text isn't found.
|
|
19
|
+
*
|
|
20
|
+
* @param opts - Tool options
|
|
21
|
+
* @returns AgentTool instance
|
|
22
|
+
*/
|
|
23
|
+
export declare function createReplaceMemoryBlockTool(opts: ReplaceMemoryBlockToolOptions): AgentTool<typeof Params>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=replace-memory-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-memory-block.d.ts","sourceRoot":"","sources":["../../src/tools/replace-memory-block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,QAAA,MAAM,MAAM;;;;EAIV,CAAC;AAEH,0DAA0D;AAC1D,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC3C,IAAI,EAAE,6BAA6B,GACjC,SAAS,CAAC,OAAO,MAAM,CAAC,CA0D1B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Type } from "@mariozechner/pi-ai";
|
|
2
|
+
const Params = Type.Object({
|
|
3
|
+
key: Type.String({ description: "Block name (e.g. 'persona', 'human')" }),
|
|
4
|
+
newText: Type.String({ description: "Replacement text" }),
|
|
5
|
+
oldText: Type.String({ description: "Text to find and replace" }),
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Create the replace_memory_block tool.
|
|
9
|
+
*
|
|
10
|
+
* Performs find/replace on a named memory block. Replaces all occurrences.
|
|
11
|
+
* Returns a structured error (not a throw) if the block doesn't exist or
|
|
12
|
+
* the search text isn't found.
|
|
13
|
+
*
|
|
14
|
+
* @param opts - Tool options
|
|
15
|
+
* @returns AgentTool instance
|
|
16
|
+
*/
|
|
17
|
+
export function createReplaceMemoryBlockTool(opts) {
|
|
18
|
+
return {
|
|
19
|
+
description: "Find and replace text in a named memory block. Replaces all occurrences. Returns error if block doesn't exist or text not found.",
|
|
20
|
+
execute: async (_toolCallId, params) => {
|
|
21
|
+
if (params.oldText.length === 0) {
|
|
22
|
+
const result = {
|
|
23
|
+
content: [{ text: "Error: oldText must not be empty", type: "text" }],
|
|
24
|
+
details: { error: "empty_old_text" },
|
|
25
|
+
};
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
const row = opts.stmts.getBlockByKey.get(opts.agentId, params.key);
|
|
29
|
+
if (!row) {
|
|
30
|
+
const result = {
|
|
31
|
+
content: [{ text: `Error: block "${params.key}" does not exist`, type: "text" }],
|
|
32
|
+
details: { error: "block_not_found" },
|
|
33
|
+
};
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
if (!row.value.includes(params.oldText)) {
|
|
37
|
+
const result = {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
text: `Error: text not found in block "${params.key}"`,
|
|
41
|
+
type: "text",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
details: { error: "text_not_found" },
|
|
45
|
+
};
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
const newValue = row.value.replaceAll(params.oldText, params.newText);
|
|
49
|
+
const now = new Date().toISOString();
|
|
50
|
+
opts.stmts.upsertBlock.run({
|
|
51
|
+
agent_id: opts.agentId,
|
|
52
|
+
key: params.key,
|
|
53
|
+
updated_at: now,
|
|
54
|
+
value: newValue,
|
|
55
|
+
});
|
|
56
|
+
const result = {
|
|
57
|
+
content: [{ text: `Updated block "${params.key}"`, type: "text" }],
|
|
58
|
+
details: {
|
|
59
|
+
replacements: row.value.split(params.oldText).length - 1,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
return result;
|
|
63
|
+
},
|
|
64
|
+
label: "Replace Memory Block",
|
|
65
|
+
name: "replace_memory_block",
|
|
66
|
+
parameters: Params,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=replace-memory-block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-memory-block.js","sourceRoot":"","sources":["../../src/tools/replace-memory-block.ts"],"names":[],"m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C,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzC,MAAM,MAAM,GAAuC;oBAClD,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,mCAAmC,MAAM,CAAC,GAAG,GAAG;4BACtD,IAAI,EAAE,MAAM;yBACZ;qBACD;oBACD,OAAO,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;iBACpC,CAAC;gBACF,OAAO,MAAM,CAAC;YACf,CAAC;YAED,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YACtE,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YAErC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC;gBAC1B,QAAQ,EAAE,IAAI,CAAC,OAAO;gBACtB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,UAAU,EAAE,GAAG;gBACf,KAAK,EAAE,QAAQ;aACf,CAAC,CAAC;YAEH,MAAM,MAAM,GAA8C;gBACzD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,kBAAkB,MAAM,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gBAClE,OAAO,EAAE;oBACR,YAAY,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC;iBACxD;aACD,CAAC;YACF,OAAO,MAAM,CAAC;QACf,CAAC;QACD,KAAK,EAAE,sBAAsB;QAC7B,IAAI,EAAE,sBAAsB;QAC5B,UAAU,EAAE,MAAM;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { DbStatements } from "../db.js";
|
|
3
|
+
import type { EmbedFn } from "../types.js";
|
|
4
|
+
declare const Params: import("@sinclair/typebox").TObject<{
|
|
5
|
+
content: import("@sinclair/typebox").TString;
|
|
6
|
+
metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
|
+
}>;
|
|
8
|
+
/** Options for creating the store_memory tool. */
|
|
9
|
+
export interface StoreMemoryToolOptions {
|
|
10
|
+
readonly agentId: string;
|
|
11
|
+
readonly embed: EmbedFn;
|
|
12
|
+
/** Max content length in characters (default: 50,000). */
|
|
13
|
+
readonly maxContentLength?: number;
|
|
14
|
+
readonly stmts: DbStatements;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create the store_memory tool.
|
|
18
|
+
*
|
|
19
|
+
* Embeds content, deduplicates by content hash, and inserts or strengthens.
|
|
20
|
+
* Verbatim duplicates are strengthened (encounter_count + 1), not re-inserted.
|
|
21
|
+
*
|
|
22
|
+
* @param opts - Tool options
|
|
23
|
+
* @returns AgentTool instance
|
|
24
|
+
*/
|
|
25
|
+
export declare function createStoreMemoryTool(opts: StoreMemoryToolOptions): AgentTool<typeof Params>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=store-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-memory.d.ts","sourceRoot":"","sources":["../../src/tools/store-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI7C,OAAO,KAAK,EAAS,OAAO,EAAE,MAAM,aAAa,CAAC;AAMlD,QAAA,MAAM,MAAM;;;EAOV,CAAC;AAEH,kDAAkD;AAClD,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC7B;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,sBAAsB,GAAG,SAAS,CAAC,OAAO,MAAM,CAAC,CAgH5F"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Type } from "@mariozechner/pi-ai";
|
|
2
|
+
import { contentHash } from "../hash.js";
|
|
3
|
+
import { embeddingToBuffer } from "../similarity.js";
|
|
4
|
+
import { updatedIntensity } from "../strength.js";
|
|
5
|
+
import { ulid } from "../ulid.js";
|
|
6
|
+
/** Maximum content length in characters (default 50KB). */
|
|
7
|
+
const MAX_CONTENT_LENGTH = 50_000;
|
|
8
|
+
const Params = Type.Object({
|
|
9
|
+
content: Type.String({ description: "Content to store as a memory" }),
|
|
10
|
+
metadata: Type.Optional(Type.String({
|
|
11
|
+
description: 'Optional JSON metadata (e.g. {"source": "pdf", "tags": ["auth"]})',
|
|
12
|
+
})),
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Check if an error is a SQLite UNIQUE constraint violation.
|
|
16
|
+
*
|
|
17
|
+
* @param err - Unknown error value
|
|
18
|
+
* @returns True if this is a UNIQUE constraint error
|
|
19
|
+
*/
|
|
20
|
+
function isSqliteConstraintUnique(err) {
|
|
21
|
+
return (err instanceof Error &&
|
|
22
|
+
"code" in err &&
|
|
23
|
+
err.code === "SQLITE_CONSTRAINT_UNIQUE");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create the store_memory tool.
|
|
27
|
+
*
|
|
28
|
+
* Embeds content, deduplicates by content hash, and inserts or strengthens.
|
|
29
|
+
* Verbatim duplicates are strengthened (encounter_count + 1), not re-inserted.
|
|
30
|
+
*
|
|
31
|
+
* @param opts - Tool options
|
|
32
|
+
* @returns AgentTool instance
|
|
33
|
+
*/
|
|
34
|
+
export function createStoreMemoryTool(opts) {
|
|
35
|
+
return {
|
|
36
|
+
description: "Store a raw memory (document chunk, experience, decision). Deduplicates by content hash — identical content strengthens the existing memory.",
|
|
37
|
+
execute: async (_toolCallId, params, signal) => {
|
|
38
|
+
const maxLen = opts.maxContentLength ?? MAX_CONTENT_LENGTH;
|
|
39
|
+
if (params.content.length > maxLen) {
|
|
40
|
+
throw new Error(`Content too long (${params.content.length} chars, max ${maxLen}). Chunk the content before storing.`);
|
|
41
|
+
}
|
|
42
|
+
if (params.metadata !== undefined) {
|
|
43
|
+
try {
|
|
44
|
+
JSON.parse(params.metadata);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error(`Invalid JSON in metadata parameter: ${params.metadata.slice(0, 100)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const now = new Date().toISOString();
|
|
51
|
+
const hash = contentHash(params.content);
|
|
52
|
+
// Check for verbatim duplicate using the content_hash index
|
|
53
|
+
const existing = opts.stmts.getMemoryByHash.get(opts.agentId, hash);
|
|
54
|
+
if (existing) {
|
|
55
|
+
// Strengthen existing memory — treat re-encounter at default intensity (0.5)
|
|
56
|
+
const newIntensity = updatedIntensity(existing.running_intensity, existing.encounter_count, 0.5);
|
|
57
|
+
opts.stmts.reinforceChunk.run({
|
|
58
|
+
id: existing.id,
|
|
59
|
+
last_accessed_at: now,
|
|
60
|
+
running_intensity: newIntensity,
|
|
61
|
+
});
|
|
62
|
+
const result = {
|
|
63
|
+
content: [
|
|
64
|
+
{
|
|
65
|
+
text: `Memory already exists (strengthened, encounters: ${existing.encounter_count + 1})`,
|
|
66
|
+
type: "text",
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
details: { action: "strengthened" },
|
|
70
|
+
};
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
// New memory — embed and insert
|
|
74
|
+
const embedding = await opts.embed(params.content, signal);
|
|
75
|
+
try {
|
|
76
|
+
opts.stmts.insertChunk.run({
|
|
77
|
+
access_count: 0,
|
|
78
|
+
agent_id: opts.agentId,
|
|
79
|
+
content: params.content,
|
|
80
|
+
content_hash: hash,
|
|
81
|
+
created_at: now,
|
|
82
|
+
embedding: embeddingToBuffer(embedding),
|
|
83
|
+
encounter_count: 1,
|
|
84
|
+
id: ulid(),
|
|
85
|
+
kind: "memory",
|
|
86
|
+
last_accessed_at: now,
|
|
87
|
+
metadata: params.metadata ?? null,
|
|
88
|
+
running_intensity: 0.5,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
// TOCTOU: another call inserted the same content between our hash check
|
|
93
|
+
// and this insert (the await embed() yields the event loop). Fall back to strengthen.
|
|
94
|
+
if (isSqliteConstraintUnique(err)) {
|
|
95
|
+
const race = opts.stmts.getMemoryByHash.get(opts.agentId, hash);
|
|
96
|
+
if (race) {
|
|
97
|
+
const newIntensity = updatedIntensity(race.running_intensity, race.encounter_count, 0.5);
|
|
98
|
+
opts.stmts.reinforceChunk.run({
|
|
99
|
+
id: race.id,
|
|
100
|
+
last_accessed_at: now,
|
|
101
|
+
running_intensity: newIntensity,
|
|
102
|
+
});
|
|
103
|
+
const result = {
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
text: `Memory already exists (strengthened, encounters: ${race.encounter_count + 1})`,
|
|
107
|
+
type: "text",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
details: { action: "strengthened" },
|
|
111
|
+
};
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
const preview = params.content.length > 80 ? `${params.content.slice(0, 80)}...` : params.content;
|
|
118
|
+
const result = {
|
|
119
|
+
content: [{ text: `Stored memory: "${preview}"`, type: "text" }],
|
|
120
|
+
details: { action: "stored" },
|
|
121
|
+
};
|
|
122
|
+
return result;
|
|
123
|
+
},
|
|
124
|
+
label: "Store Memory",
|
|
125
|
+
name: "store_memory",
|
|
126
|
+
parameters: Params,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=store-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-memory.js","sourceRoot":"","sources":["../../src/tools/store-memory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,2DAA2D;AAC3D,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;IACrE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CACtB,IAAI,CAAC,MAAM,CAAC;QACX,WAAW,EAAE,mEAAmE;KAChF,CAAC,CACF;CACD,CAAC,CAAC;AAWH;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,GAAY;IAC7C,OAAO,CACN,GAAG,YAAY,KAAK;QACpB,MAAM,IAAI,GAAG;QACZ,GAAgC,CAAC,IAAI,KAAK,0BAA0B,CACrE,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAA4B;IACjE,OAAO;QACN,WAAW,EACV,8IAA8I;QAC/I,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,IAAI,kBAAkB,CAAC;YAC3D,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CACd,qBAAqB,MAAM,CAAC,OAAO,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