agentfootprint 7.19.1 → 7.20.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/AGENTS.md +2 -1
- package/ai-instructions/claude-code/SKILL.md +2 -1
- package/ai-instructions/clinerules +1 -1
- package/ai-instructions/copilot-instructions.md +1 -1
- package/ai-instructions/cursor/agentfootprint.md +1 -1
- package/ai-instructions/kiro/agentfootprint.md +1 -1
- package/ai-instructions/windsurfrules +1 -1
- package/dist/esm/lib/rag/defineRAG.d.ts +4 -19
- package/dist/esm/lib/rag/defineRAG.js +9 -4
- package/dist/esm/lib/rag/defineRAG.js.map +1 -1
- package/dist/esm/memory/asRoleRefusal.d.ts +43 -0
- package/dist/esm/memory/asRoleRefusal.js +55 -0
- package/dist/esm/memory/asRoleRefusal.js.map +1 -0
- package/dist/esm/memory/define.d.ts +2 -1
- package/dist/esm/memory/define.js +7 -20
- package/dist/esm/memory/define.js.map +1 -1
- package/dist/esm/memory/define.types.d.ts +3 -5
- package/dist/esm/memory/define.types.js +3 -1
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/stages/formatDefault.js +17 -7
- package/dist/esm/memory/stages/formatDefault.js.map +1 -1
- package/dist/lib/rag/defineRAG.js +9 -4
- package/dist/lib/rag/defineRAG.js.map +1 -1
- package/dist/memory/asRoleRefusal.js +60 -0
- package/dist/memory/asRoleRefusal.js.map +1 -0
- package/dist/memory/define.js +7 -20
- package/dist/memory/define.js.map +1 -1
- package/dist/memory/define.types.js +3 -1
- package/dist/memory/define.types.js.map +1 -1
- package/dist/memory/stages/formatDefault.js +17 -7
- package/dist/memory/stages/formatDefault.js.map +1 -1
- package/dist/types/lib/rag/defineRAG.d.ts +4 -19
- package/dist/types/lib/rag/defineRAG.d.ts.map +1 -1
- package/dist/types/memory/asRoleRefusal.d.ts +44 -0
- package/dist/types/memory/asRoleRefusal.d.ts.map +1 -0
- package/dist/types/memory/define.d.ts +2 -1
- package/dist/types/memory/define.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +3 -5
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/memory/stages/formatDefault.d.ts.map +1 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -138,8 +138,9 @@ const docs = defineRAG({
|
|
|
138
138
|
store, embedder,
|
|
139
139
|
topK: 3,
|
|
140
140
|
threshold: 0.7, // STRICT — no fallback when nothing matches
|
|
141
|
-
asRole: 'user', // chunks land as user-role context (RAG default)
|
|
142
141
|
});
|
|
142
|
+
// Retrieved chunks land in the SYSTEM-PROMPT slot, as one system message.
|
|
143
|
+
// `asRole` was removed in 7.20.0 — it was never read, and passing it throws.
|
|
143
144
|
|
|
144
145
|
// Wire to agent — `.rag()` is an alias for `.memory()`, same plumbing
|
|
145
146
|
agent.rag(docs);
|
|
@@ -294,8 +294,9 @@ const docs = defineRAG({
|
|
|
294
294
|
store, embedder,
|
|
295
295
|
topK: 3,
|
|
296
296
|
threshold: 0.7, // STRICT — no fallback when nothing matches
|
|
297
|
-
asRole: 'user', // chunks land as user-role context
|
|
298
297
|
});
|
|
298
|
+
// Retrieved chunks land in the SYSTEM-PROMPT slot, as one system message.
|
|
299
|
+
// `asRole` was removed in 7.20.0 — it was never read, and passing it throws.
|
|
299
300
|
|
|
300
301
|
// Wire — `.rag()` is alias for `.memory()`, same plumbing
|
|
301
302
|
agent.rag(docs);
|
|
@@ -171,7 +171,7 @@ const docs = defineRAG({ id: 'docs', store, embedder, topK: 3, threshold: 0.7 })
|
|
|
171
171
|
agent.rag(docs); // alias for .memory(), same plumbing
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (
|
|
174
|
+
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (topK=3, threshold=0.7). Same engine, clearer intent.
|
|
175
175
|
|
|
176
176
|
### Multi-agent via control flow (no `MultiAgentSystem` class)
|
|
177
177
|
|
|
@@ -171,7 +171,7 @@ const docs = defineRAG({ id: 'docs', store, embedder, topK: 3, threshold: 0.7 })
|
|
|
171
171
|
agent.rag(docs); // alias for .memory(), same plumbing
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (
|
|
174
|
+
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (topK=3, threshold=0.7). Same engine, clearer intent.
|
|
175
175
|
|
|
176
176
|
### Multi-agent via control flow (no `MultiAgentSystem` class)
|
|
177
177
|
|
|
@@ -171,7 +171,7 @@ const docs = defineRAG({ id: 'docs', store, embedder, topK: 3, threshold: 0.7 })
|
|
|
171
171
|
agent.rag(docs); // alias for .memory(), same plumbing
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (
|
|
174
|
+
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (topK=3, threshold=0.7). Same engine, clearer intent.
|
|
175
175
|
|
|
176
176
|
### Multi-agent via control flow (no `MultiAgentSystem` class)
|
|
177
177
|
|
|
@@ -171,7 +171,7 @@ const docs = defineRAG({ id: 'docs', store, embedder, topK: 3, threshold: 0.7 })
|
|
|
171
171
|
agent.rag(docs); // alias for .memory(), same plumbing
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (
|
|
174
|
+
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (topK=3, threshold=0.7). Same engine, clearer intent.
|
|
175
175
|
|
|
176
176
|
### Multi-agent via control flow (no `MultiAgentSystem` class)
|
|
177
177
|
|
|
@@ -171,7 +171,7 @@ const docs = defineRAG({ id: 'docs', store, embedder, topK: 3, threshold: 0.7 })
|
|
|
171
171
|
agent.rag(docs); // alias for .memory(), same plumbing
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (
|
|
174
|
+
`defineRAG` is sugar over `defineMemory({ type: SEMANTIC, strategy: TOP_K })` with RAG-friendly defaults (topK=3, threshold=0.7). Same engine, clearer intent.
|
|
175
175
|
|
|
176
176
|
### Multi-agent via control flow (no `MultiAgentSystem` class)
|
|
177
177
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* RAG is a context-engineering flavor: embed the user's question,
|
|
5
5
|
* retrieve top-K semantically similar chunks from a vector store,
|
|
6
|
-
* inject those chunks into the
|
|
6
|
+
* inject those chunks into the system-prompt slot of the next LLM call.
|
|
7
7
|
* It's the same plumbing as `defineMemory({ type: SEMANTIC,
|
|
8
8
|
* strategy: TOP_K })` — the rename is for intent + ergonomics.
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* └─► CAUSAL (footprintjs decision snapshots)
|
|
14
14
|
*
|
|
15
15
|
* defineRAG ─► SEMANTIC + TOP_K with RAG-specific defaults
|
|
16
|
-
* (
|
|
16
|
+
* (topK=3, threshold=0.7, no LLM-extract)
|
|
17
17
|
*
|
|
18
18
|
* Pattern: Composition over duplication — defineRAG returns a
|
|
19
19
|
* MemoryDefinition produced by defineMemory. No new engine
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Emits: Indirectly — the underlying memory pipeline emits
|
|
29
29
|
* `agentfootprint.context.injected` when retrieved chunks
|
|
30
|
-
* land in the
|
|
30
|
+
* land in the system-prompt slot.
|
|
31
31
|
*
|
|
32
32
|
* @see ./indexDocuments.ts for the seeding helper
|
|
33
33
|
* @see ../../memory/define.ts for the underlying factory
|
|
34
|
+
* @see ../../memory/asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
34
35
|
*
|
|
35
36
|
* @example Basic usage
|
|
36
37
|
* ```ts
|
|
@@ -61,7 +62,6 @@ import { mock } from 'agentfootprint/llm-providers';
|
|
|
61
62
|
* .build();
|
|
62
63
|
* ```
|
|
63
64
|
*/
|
|
64
|
-
import type { ContextRole } from '../../events/types.js';
|
|
65
65
|
import type { Embedder } from '../../memory/embedding/index.js';
|
|
66
66
|
import type { MemoryStore } from '../../memory/store/index.js';
|
|
67
67
|
import type { MemoryDefinition } from '../../memory/define.types.js';
|
|
@@ -112,21 +112,6 @@ export interface DefineRAGOptions {
|
|
|
112
112
|
* sit comfortably with 0.7.
|
|
113
113
|
*/
|
|
114
114
|
readonly threshold?: number;
|
|
115
|
-
/**
|
|
116
|
-
* Role to use when injecting retrieved chunks into the messages
|
|
117
|
-
* slot. Default `'user'`.
|
|
118
|
-
*
|
|
119
|
-
* Why `'user'`: in tool-using ReAct loops, retrieved chunks
|
|
120
|
-
* conceptually "augment what the user asked." Anthropic's tool-use
|
|
121
|
-
* cookbook and OpenAI's RAG cookbook both show retrieved context
|
|
122
|
-
* inside user-turn messages.
|
|
123
|
-
*
|
|
124
|
-
* Use `'system'` for authoritative reference docs that should
|
|
125
|
-
* outweigh user instruction (policy / compliance / brand-voice
|
|
126
|
-
* corpora). Use `'assistant'` only if you've persisted prior agent
|
|
127
|
-
* turns as context — rare.
|
|
128
|
-
*/
|
|
129
|
-
readonly asRole?: ContextRole;
|
|
130
115
|
}
|
|
131
116
|
/**
|
|
132
117
|
* Build a RAG context-engineering definition. The returned
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* RAG is a context-engineering flavor: embed the user's question,
|
|
5
5
|
* retrieve top-K semantically similar chunks from a vector store,
|
|
6
|
-
* inject those chunks into the
|
|
6
|
+
* inject those chunks into the system-prompt slot of the next LLM call.
|
|
7
7
|
* It's the same plumbing as `defineMemory({ type: SEMANTIC,
|
|
8
8
|
* strategy: TOP_K })` — the rename is for intent + ergonomics.
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* └─► CAUSAL (footprintjs decision snapshots)
|
|
14
14
|
*
|
|
15
15
|
* defineRAG ─► SEMANTIC + TOP_K with RAG-specific defaults
|
|
16
|
-
* (
|
|
16
|
+
* (topK=3, threshold=0.7, no LLM-extract)
|
|
17
17
|
*
|
|
18
18
|
* Pattern: Composition over duplication — defineRAG returns a
|
|
19
19
|
* MemoryDefinition produced by defineMemory. No new engine
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Emits: Indirectly — the underlying memory pipeline emits
|
|
29
29
|
* `agentfootprint.context.injected` when retrieved chunks
|
|
30
|
-
* land in the
|
|
30
|
+
* land in the system-prompt slot.
|
|
31
31
|
*
|
|
32
32
|
* @see ./indexDocuments.ts for the seeding helper
|
|
33
33
|
* @see ../../memory/define.ts for the underlying factory
|
|
34
|
+
* @see ../../memory/asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
34
35
|
*
|
|
35
36
|
* @example Basic usage
|
|
36
37
|
* ```ts
|
|
@@ -63,6 +64,7 @@ import { mock } from 'agentfootprint/llm-providers';
|
|
|
63
64
|
*/
|
|
64
65
|
import { MEMORY_TYPES, MEMORY_STRATEGIES } from '../../memory/define.types.js';
|
|
65
66
|
import { defineMemory } from '../../memory/define.js';
|
|
67
|
+
import { refuseAsRole } from '../../memory/asRoleRefusal.js';
|
|
66
68
|
/**
|
|
67
69
|
* Build a RAG context-engineering definition. The returned
|
|
68
70
|
* `MemoryDefinition` is registered on the Agent via `.rag(definition)`
|
|
@@ -75,6 +77,10 @@ export function defineRAG(opts) {
|
|
|
75
77
|
if (!opts.id || opts.id.trim() === '') {
|
|
76
78
|
throw new Error('defineRAG: `id` is required and must be non-empty.');
|
|
77
79
|
}
|
|
80
|
+
// `asRole` no longer type-checks; this catches JavaScript callers and
|
|
81
|
+
// casts. Refused here rather than only inside `defineMemory` so the
|
|
82
|
+
// message names the factory the caller actually wrote.
|
|
83
|
+
refuseAsRole(opts, `defineRAG('${opts.id}')`);
|
|
78
84
|
if (!opts.store) {
|
|
79
85
|
throw new Error(`defineRAG[${opts.id}]: \`store\` is required.`);
|
|
80
86
|
}
|
|
@@ -96,7 +102,6 @@ export function defineRAG(opts) {
|
|
|
96
102
|
embedder: opts.embedder,
|
|
97
103
|
},
|
|
98
104
|
store: opts.store,
|
|
99
|
-
asRole: opts.asRole ?? 'user',
|
|
100
105
|
});
|
|
101
106
|
}
|
|
102
107
|
//# sourceMappingURL=defineRAG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineRAG.js","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"defineRAG.js","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AAKH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAkE7D;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,IAAsB;IAC9C,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,sEAAsE;IACtE,oEAAoE;IACpE,uDAAuD;IACvD,YAAY,CAAC,IAAI,EAAE,cAAc,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,EAAE,2BAA2B,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,EAAE,8BAA8B,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,CAAC,EAAE,oCAAoC;YACtD,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IAED,OAAO,YAAY,CAAC;QAClB,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;QACxE,IAAI,EAAE,YAAY,CAAC,QAAQ;QAC3B,QAAQ,EAAE;YACR,IAAI,EAAE,iBAAiB,CAAC,KAAK;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;YACpB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,GAAG;YAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;QACD,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `asRole` refusal — one sentence, said in every place the option
|
|
3
|
+
* could be declared.
|
|
4
|
+
*
|
|
5
|
+
* WHY this exists at all: `defineMemory({ asRole })` and
|
|
6
|
+
* `defineRAG({ asRole })` accepted a role, stored it on the returned
|
|
7
|
+
* `MemoryDefinition`, and NOTHING ever read it. Every formatter this
|
|
8
|
+
* library ships writes `role: 'system'` — `formatDefault`, `formatFacts`,
|
|
9
|
+
* `formatAsNarrative`, the causal `loadSnapshot`, and the auto pipeline —
|
|
10
|
+
* so recall has always been injected as system, whatever the option said.
|
|
11
|
+
* `defineRAG` even defaulted it to `'user'` and documented why, which made
|
|
12
|
+
* the lie legible: a reader could pick a role, read it back off the
|
|
13
|
+
* definition, and be told a role the run would never use.
|
|
14
|
+
*
|
|
15
|
+
* Delivering it instead is not a one-line change. Role-differentiated
|
|
16
|
+
* recall means putting non-system content into the message list, and the
|
|
17
|
+
* messages slot does not reach the model today (see
|
|
18
|
+
* `lib/injection-engine/messagesSlotRefusal.ts`): it is the observability
|
|
19
|
+
* projection of the conversation, not a wire. Honouring `asRole: 'user'`
|
|
20
|
+
* would have to route through that slot, which would trade a dead option
|
|
21
|
+
* for a recorded-and-dropped one — strictly worse, because the recording
|
|
22
|
+
* would then claim delivery.
|
|
23
|
+
*
|
|
24
|
+
* So the option is refused where it is written, and the refusal points at
|
|
25
|
+
* the feature that would make it real: role-differentiated recall arrives
|
|
26
|
+
* with messages delivery, if field evidence asks for it.
|
|
27
|
+
*
|
|
28
|
+
* A throw where there was a silent lie is a fix, not a break: nothing that
|
|
29
|
+
* worked stops working, and something that never worked stops pretending.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* The refusal text, addressed from `site` (e.g. `defineRAG('product-docs')`).
|
|
33
|
+
* States the truth (never read; always system) and names what would change
|
|
34
|
+
* it, because a refusal that does not teach just moves the puzzle.
|
|
35
|
+
*/
|
|
36
|
+
export declare function asRoleRefusal(site: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Throw the refusal when a caller passed `asRole`. Presence, not value —
|
|
39
|
+
* an explicit `asRole: 'system'` was just as unread as `asRole: 'user'`,
|
|
40
|
+
* and letting the "harmless" one through would teach that the option
|
|
41
|
+
* works.
|
|
42
|
+
*/
|
|
43
|
+
export declare function refuseAsRole(options: object, site: string): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `asRole` refusal — one sentence, said in every place the option
|
|
3
|
+
* could be declared.
|
|
4
|
+
*
|
|
5
|
+
* WHY this exists at all: `defineMemory({ asRole })` and
|
|
6
|
+
* `defineRAG({ asRole })` accepted a role, stored it on the returned
|
|
7
|
+
* `MemoryDefinition`, and NOTHING ever read it. Every formatter this
|
|
8
|
+
* library ships writes `role: 'system'` — `formatDefault`, `formatFacts`,
|
|
9
|
+
* `formatAsNarrative`, the causal `loadSnapshot`, and the auto pipeline —
|
|
10
|
+
* so recall has always been injected as system, whatever the option said.
|
|
11
|
+
* `defineRAG` even defaulted it to `'user'` and documented why, which made
|
|
12
|
+
* the lie legible: a reader could pick a role, read it back off the
|
|
13
|
+
* definition, and be told a role the run would never use.
|
|
14
|
+
*
|
|
15
|
+
* Delivering it instead is not a one-line change. Role-differentiated
|
|
16
|
+
* recall means putting non-system content into the message list, and the
|
|
17
|
+
* messages slot does not reach the model today (see
|
|
18
|
+
* `lib/injection-engine/messagesSlotRefusal.ts`): it is the observability
|
|
19
|
+
* projection of the conversation, not a wire. Honouring `asRole: 'user'`
|
|
20
|
+
* would have to route through that slot, which would trade a dead option
|
|
21
|
+
* for a recorded-and-dropped one — strictly worse, because the recording
|
|
22
|
+
* would then claim delivery.
|
|
23
|
+
*
|
|
24
|
+
* So the option is refused where it is written, and the refusal points at
|
|
25
|
+
* the feature that would make it real: role-differentiated recall arrives
|
|
26
|
+
* with messages delivery, if field evidence asks for it.
|
|
27
|
+
*
|
|
28
|
+
* A throw where there was a silent lie is a fix, not a break: nothing that
|
|
29
|
+
* worked stops working, and something that never worked stops pretending.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* The refusal text, addressed from `site` (e.g. `defineRAG('product-docs')`).
|
|
33
|
+
* States the truth (never read; always system) and names what would change
|
|
34
|
+
* it, because a refusal that does not teach just moves the puzzle.
|
|
35
|
+
*/
|
|
36
|
+
export function asRoleRefusal(site) {
|
|
37
|
+
return (`${site}: \`asRole\` has never been read. Every formatter this library ships ` +
|
|
38
|
+
`writes \`role: 'system'\`, so recall is always injected as system — the option ` +
|
|
39
|
+
`was stored on the definition and ignored by the run. It is removed rather than ` +
|
|
40
|
+
`honoured, because honouring it means putting recall into the messages slot, ` +
|
|
41
|
+
`which does not reach the model. Role-differentiated recall arrives with the ` +
|
|
42
|
+
`messages-delivery feature, if field evidence asks for it. Drop the option: ` +
|
|
43
|
+
`the behaviour you already had does not change.`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Throw the refusal when a caller passed `asRole`. Presence, not value —
|
|
47
|
+
* an explicit `asRole: 'system'` was just as unread as `asRole: 'user'`,
|
|
48
|
+
* and letting the "harmless" one through would teach that the option
|
|
49
|
+
* works.
|
|
50
|
+
*/
|
|
51
|
+
export function refuseAsRole(options, site) {
|
|
52
|
+
if ('asRole' in options)
|
|
53
|
+
throw new Error(asRoleRefusal(site));
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=asRoleRefusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asRoleRefusal.js","sourceRoot":"","sources":["../../../src/memory/asRoleRefusal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,CACL,GAAG,IAAI,uEAAuE;QAC9E,iFAAiF;QACjF,iFAAiF;QACjF,8EAA8E;QAC9E,8EAA8E;QAC9E,6EAA6E;QAC7E,gDAAgD,CACjD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,IAAY;IACxD,IAAI,QAAQ,IAAI,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -21,9 +21,10 @@
|
|
|
21
21
|
*
|
|
22
22
|
* Emits: Indirectly — the compiled subflows emit
|
|
23
23
|
* `agentfootprint.context.injected` with `source: 'memory'`
|
|
24
|
-
* when their formatter writes to the
|
|
24
|
+
* when their formatter writes to the system-prompt slot.
|
|
25
25
|
*
|
|
26
26
|
* @see ./define.types.ts for the const-objects + types
|
|
27
|
+
* @see ./asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
27
28
|
* @see ./pipeline/*.ts for the existing pipeline factories this dispatches to
|
|
28
29
|
*/
|
|
29
30
|
import { type DefineMemoryOptions } from './define.types.js';
|
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
*
|
|
22
22
|
* Emits: Indirectly — the compiled subflows emit
|
|
23
23
|
* `agentfootprint.context.injected` with `source: 'memory'`
|
|
24
|
-
* when their formatter writes to the
|
|
24
|
+
* when their formatter writes to the system-prompt slot.
|
|
25
25
|
*
|
|
26
26
|
* @see ./define.types.ts for the const-objects + types
|
|
27
|
+
* @see ./asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
27
28
|
* @see ./pipeline/*.ts for the existing pipeline factories this dispatches to
|
|
28
29
|
*/
|
|
30
|
+
import { refuseAsRole } from './asRoleRefusal.js';
|
|
29
31
|
import { defaultPipeline } from './pipeline/default.js';
|
|
30
32
|
import { ephemeralPipeline } from './pipeline/ephemeral.js';
|
|
31
33
|
import { semanticPipeline } from './pipeline/semantic.js';
|
|
@@ -70,7 +72,6 @@ export function defineMemory(options) {
|
|
|
70
72
|
read: brandPipeline(pipeline.read),
|
|
71
73
|
...(pipeline.write !== undefined && { write: brandPipeline(pipeline.write) }),
|
|
72
74
|
timing: options.timing ?? MEMORY_TIMING.TURN_START,
|
|
73
|
-
asRole: options.asRole ?? defaultRoleFor(options),
|
|
74
75
|
...(options.redact !== undefined && { redact: options.redact }),
|
|
75
76
|
...(options.type === MEMORY_TYPES.CAUSAL &&
|
|
76
77
|
options.projection !== undefined && {
|
|
@@ -84,6 +85,10 @@ function validate(options) {
|
|
|
84
85
|
if (!options.id || options.id.trim() === '') {
|
|
85
86
|
throw new Error('defineMemory: `id` is required and must be non-empty.');
|
|
86
87
|
}
|
|
88
|
+
// `asRole` no longer type-checks; this catches JavaScript callers and
|
|
89
|
+
// casts. Refused before anything else is validated so the message is
|
|
90
|
+
// about the option the caller actually wrote.
|
|
91
|
+
refuseAsRole(options, `defineMemory('${options.id}')`);
|
|
87
92
|
if (!options.store) {
|
|
88
93
|
throw new Error(`defineMemory[id=${options.id}]: \`store\` is required. ` +
|
|
89
94
|
'Pass `new InMemoryStore()` for dev/tests, or a backed store for production.');
|
|
@@ -273,24 +278,6 @@ function buildCausalPipeline(options) {
|
|
|
273
278
|
return snapshotPipeline(config);
|
|
274
279
|
}
|
|
275
280
|
// ─── Helpers ───────────────────────────────────────────────────────
|
|
276
|
-
/**
|
|
277
|
-
* Default `asRole` per type — system for behavior-shaping memory,
|
|
278
|
-
* user for retrieved facts (so the LLM treats them as context, not
|
|
279
|
-
* instruction).
|
|
280
|
-
*/
|
|
281
|
-
function defaultRoleFor(options) {
|
|
282
|
-
switch (options.type) {
|
|
283
|
-
case MEMORY_TYPES.EPISODIC:
|
|
284
|
-
case MEMORY_TYPES.NARRATIVE:
|
|
285
|
-
return 'system';
|
|
286
|
-
case MEMORY_TYPES.SEMANTIC:
|
|
287
|
-
return 'system';
|
|
288
|
-
case MEMORY_TYPES.CAUSAL:
|
|
289
|
-
return 'system';
|
|
290
|
-
default:
|
|
291
|
-
return 'system';
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
281
|
/**
|
|
295
282
|
* The factory hands back an opaque `ReadonlyMemoryFlowChart<T>` brand
|
|
296
283
|
* to keep consumers from reaching into the FlowChart shape directly —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,eAAe,EAA8B,MAAM,uB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AI,EAAE,CAAC,CAAC,IAAI;QACZ,GAAG,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;QAC3D,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;KAC5E,CAAC;IACF,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,sEAAsE;AAEtE;;;;GAIG;AACH,SAAS,aAAa,CAAI,EAAW;IACnC,OAAO,EAAgC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAI,OAAmC;IAC1E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,kEAAkE;AAClE,sDAAsD;AACtD,KAAK,iBAAiB,CAAC;AACvB,iEAAiE;AACjE,KAAM,IAA4B,CAAC"}
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
*
|
|
31
31
|
* Emits: Indirectly — every memory pipeline emits the unified
|
|
32
32
|
* `agentfootprint.context.injected` event with `source: 'memory'`
|
|
33
|
-
* when its read subflow places content into the
|
|
33
|
+
* when its read subflow places content into the system-prompt
|
|
34
|
+
* slot (every shipped formatter writes `role: 'system'`, and
|
|
35
|
+
* system-role recall composes into `inject.systemPrompt`).
|
|
34
36
|
*
|
|
35
37
|
* @see ./define.ts for the `defineMemory()` factory itself
|
|
36
38
|
* @see ../../docs-next for guides + the 7 strategy examples
|
|
37
39
|
* @see MEMORY.md for the load-bearing design memory
|
|
38
40
|
*/
|
|
39
41
|
import type { LLMProvider } from '../adapters/types.js';
|
|
40
|
-
import type { ContextRole } from '../events/types.js';
|
|
41
42
|
import type { Embedder } from './embedding/index.js';
|
|
42
43
|
import type { MemoryStore } from './store/index.js';
|
|
43
44
|
/**
|
|
@@ -217,8 +218,6 @@ export interface MemoryDefinition<T = unknown> {
|
|
|
217
218
|
readonly write?: ReadonlyMemoryFlowChart<T>;
|
|
218
219
|
/** When `read` runs. Default `TURN_START`. */
|
|
219
220
|
readonly timing: MemoryTiming;
|
|
220
|
-
/** Role to use when injecting formatted content into the messages slot. */
|
|
221
|
-
readonly asRole: ContextRole;
|
|
222
221
|
/** Reserved for a future release — patterns to redact before write. */
|
|
223
222
|
readonly redact?: MemoryRedactionPolicy;
|
|
224
223
|
/** Snapshot projection — only meaningful when `type === CAUSAL`. */
|
|
@@ -244,7 +243,6 @@ export interface DefineMemoryOptionsBase {
|
|
|
244
243
|
readonly store: MemoryStore;
|
|
245
244
|
readonly strategy: Strategy;
|
|
246
245
|
readonly timing?: MemoryTiming;
|
|
247
|
-
readonly asRole?: ContextRole;
|
|
248
246
|
readonly redact?: MemoryRedactionPolicy;
|
|
249
247
|
}
|
|
250
248
|
export interface DefineEpisodicOptions extends DefineMemoryOptionsBase {
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
*
|
|
31
31
|
* Emits: Indirectly — every memory pipeline emits the unified
|
|
32
32
|
* `agentfootprint.context.injected` event with `source: 'memory'`
|
|
33
|
-
* when its read subflow places content into the
|
|
33
|
+
* when its read subflow places content into the system-prompt
|
|
34
|
+
* slot (every shipped formatter writes `role: 'system'`, and
|
|
35
|
+
* system-role recall composes into `inject.systemPrompt`).
|
|
34
36
|
*
|
|
35
37
|
* @see ./define.ts for the `defineMemory()` factory itself
|
|
36
38
|
* @see ../../docs-next for guides + the 7 strategy examples
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.types.js","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"define.types.js","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAMH,uEAAuE;AAEvE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,QA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AAC,MAAM,2BAA2B,GAAG,kBAA2B,CAAC;AAEvE,MAAM,UAAU,kBAAkB,CAAC,EAAU;IAC3C,OAAO,GAAG,2BAA2B,GAAG,EAAE,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,OAAO,GAAG,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -33,17 +33,27 @@ export function formatDefault(config = {}) {
|
|
|
33
33
|
const blocks = selected.map(renderEntry).join('\n\n');
|
|
34
34
|
const content = (header ? `${header}\n\n` : '') + blocks + (footer ? `\n\n${footer}` : '');
|
|
35
35
|
scope.formatted = [{ role: 'system', content }];
|
|
36
|
-
// Context-engineering emit: memory formatted N entries into
|
|
37
|
-
// system message
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
36
|
+
// Context-engineering emit: memory formatted N entries into one
|
|
37
|
+
// system-role message.
|
|
38
|
+
//
|
|
39
|
+
// LAW: this event must name the slot the content actually lands in.
|
|
40
|
+
// It says `'system-prompt'` because that is where it goes, and it is
|
|
41
|
+
// checkable end to end — `memoryRecallInjections` routes system-role
|
|
42
|
+
// recall to `inject.systemPrompt`, `buildSystemPromptSlot` records it
|
|
43
|
+
// as a `slot: 'system-prompt'` injection, and the request carries it
|
|
44
|
+
// in `systemPrompt`. Two events describing one piece of content must
|
|
45
|
+
// not disagree: `context.memory.injected` and `context.injected` name
|
|
46
|
+
// the same slot for the same bytes.
|
|
47
|
+
//
|
|
48
|
+
// Until 7.20.0 this said `'messages'`, which was never true of this
|
|
49
|
+
// stage — `scope.formatted` above is unconditionally role `'system'`.
|
|
50
|
+
// A consumer branching on the old value was branching on a lie.
|
|
41
51
|
if (typeof scope.$emit === 'function') {
|
|
42
52
|
scope.$emit('agentfootprint.context.memory.injected', {
|
|
43
|
-
slot: '
|
|
53
|
+
slot: 'system-prompt',
|
|
44
54
|
// Memory injects ONE system-role message containing every selected
|
|
45
55
|
// entry as a citation block (see DEFAULT_HEADER + renderEntry).
|
|
46
|
-
// The downstream
|
|
56
|
+
// The downstream delta is therefore +1 system fragment, regardless
|
|
47
57
|
// of how many memory entries it carries.
|
|
48
58
|
role: 'system',
|
|
49
59
|
deltaCount: { system: 1 },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDefault.js","sourceRoot":"","sources":["../../../../src/memory/stages/formatDefault.ts"],"names":[],"mappings":"AAiEA,MAAM,cAAc,GAClB,uFAAuF,CAAC;AAE1F;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,kBAAkB,CAAC,KAA2B;IACrD,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC;IACxB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACxF,MAAM,WAAW,GACf,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAE/F,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;IAE/B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC;IACnC,OAAO,iBAAiB,IAAI,IAAI,QAAQ,GAAG,WAAW,MAAM,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC;AACjG,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,SAA8B,EAAE;IAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,cAAc,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,CA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,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAE3F,KAAK,CAAC,SAAS,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAEhD,gEAAgE;QAChE,uBAAuB;QACvB,EAAE;QACF,oEAAoE;QACpE,qEAAqE;QACrE,qEAAqE;QACrE,sEAAsE;QACtE,qEAAqE;QACrE,qEAAqE;QACrE,sEAAsE;QACtE,oCAAoC;QACpC,EAAE;QACF,oEAAoE;QACpE,sEAAsE;QACtE,gEAAgE;QAChE,IAAI,OAAQ,KAAwC,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YAC1E,KAAK,CAAC,KAAK,CAAC,wCAAwC,EAAE;gBACpD,IAAI,EAAE,eAAe;gBACrB,mEAAmE;gBACnE,gEAAgE;gBAChE,mEAAmE;gBACnE,yCAAyC;gBACzC,IAAI,EAAE,QAAiB;gBACvB,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE;gBACzB,KAAK,EAAE,QAAQ,CAAC,MAAM;gBACtB,0EAA0E;gBAC1E,iDAAiD;gBACjD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;aACxE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* RAG is a context-engineering flavor: embed the user's question,
|
|
6
6
|
* retrieve top-K semantically similar chunks from a vector store,
|
|
7
|
-
* inject those chunks into the
|
|
7
|
+
* inject those chunks into the system-prompt slot of the next LLM call.
|
|
8
8
|
* It's the same plumbing as `defineMemory({ type: SEMANTIC,
|
|
9
9
|
* strategy: TOP_K })` — the rename is for intent + ergonomics.
|
|
10
10
|
*
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* └─► CAUSAL (footprintjs decision snapshots)
|
|
15
15
|
*
|
|
16
16
|
* defineRAG ─► SEMANTIC + TOP_K with RAG-specific defaults
|
|
17
|
-
* (
|
|
17
|
+
* (topK=3, threshold=0.7, no LLM-extract)
|
|
18
18
|
*
|
|
19
19
|
* Pattern: Composition over duplication — defineRAG returns a
|
|
20
20
|
* MemoryDefinition produced by defineMemory. No new engine
|
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
*
|
|
29
29
|
* Emits: Indirectly — the underlying memory pipeline emits
|
|
30
30
|
* `agentfootprint.context.injected` when retrieved chunks
|
|
31
|
-
* land in the
|
|
31
|
+
* land in the system-prompt slot.
|
|
32
32
|
*
|
|
33
33
|
* @see ./indexDocuments.ts for the seeding helper
|
|
34
34
|
* @see ../../memory/define.ts for the underlying factory
|
|
35
|
+
* @see ../../memory/asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
35
36
|
*
|
|
36
37
|
* @example Basic usage
|
|
37
38
|
* ```ts
|
|
@@ -66,6 +67,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
66
67
|
exports.defineRAG = void 0;
|
|
67
68
|
const define_types_js_1 = require("../../memory/define.types.js");
|
|
68
69
|
const define_js_1 = require("../../memory/define.js");
|
|
70
|
+
const asRoleRefusal_js_1 = require("../../memory/asRoleRefusal.js");
|
|
69
71
|
/**
|
|
70
72
|
* Build a RAG context-engineering definition. The returned
|
|
71
73
|
* `MemoryDefinition` is registered on the Agent via `.rag(definition)`
|
|
@@ -78,6 +80,10 @@ function defineRAG(opts) {
|
|
|
78
80
|
if (!opts.id || opts.id.trim() === '') {
|
|
79
81
|
throw new Error('defineRAG: `id` is required and must be non-empty.');
|
|
80
82
|
}
|
|
83
|
+
// `asRole` no longer type-checks; this catches JavaScript callers and
|
|
84
|
+
// casts. Refused here rather than only inside `defineMemory` so the
|
|
85
|
+
// message names the factory the caller actually wrote.
|
|
86
|
+
(0, asRoleRefusal_js_1.refuseAsRole)(opts, `defineRAG('${opts.id}')`);
|
|
81
87
|
if (!opts.store) {
|
|
82
88
|
throw new Error(`defineRAG[${opts.id}]: \`store\` is required.`);
|
|
83
89
|
}
|
|
@@ -99,7 +105,6 @@ function defineRAG(opts) {
|
|
|
99
105
|
embedder: opts.embedder,
|
|
100
106
|
},
|
|
101
107
|
store: opts.store,
|
|
102
|
-
asRole: opts.asRole ?? 'user',
|
|
103
108
|
});
|
|
104
109
|
}
|
|
105
110
|
exports.defineRAG = defineRAG;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineRAG.js","sourceRoot":"","sources":["../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"defineRAG.js","sourceRoot":"","sources":["../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;;;AAKH,kEAA+E;AAC/E,sDAAsD;AACtD,oEAA6D;AAkE7D;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAC,IAAsB;IAC9C,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,sEAAsE;IACtE,oEAAoE;IACpE,uDAAuD;IACvD,IAAA,+BAAY,EAAC,IAAI,EAAE,cAAc,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,EAAE,2BAA2B,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,EAAE,8BAA8B,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,CAAC,EAAE,oCAAoC;YACtD,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IAED,OAAO,IAAA,wBAAY,EAAC;QAClB,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;QACxE,IAAI,EAAE,8BAAY,CAAC,QAAQ;QAC3B,QAAQ,EAAE;YACR,IAAI,EAAE,mCAAiB,CAAC,KAAK;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;YACpB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,GAAG;YAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;QACD,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;AACL,CAAC;AAjCD,8BAiCC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The `asRole` refusal — one sentence, said in every place the option
|
|
4
|
+
* could be declared.
|
|
5
|
+
*
|
|
6
|
+
* WHY this exists at all: `defineMemory({ asRole })` and
|
|
7
|
+
* `defineRAG({ asRole })` accepted a role, stored it on the returned
|
|
8
|
+
* `MemoryDefinition`, and NOTHING ever read it. Every formatter this
|
|
9
|
+
* library ships writes `role: 'system'` — `formatDefault`, `formatFacts`,
|
|
10
|
+
* `formatAsNarrative`, the causal `loadSnapshot`, and the auto pipeline —
|
|
11
|
+
* so recall has always been injected as system, whatever the option said.
|
|
12
|
+
* `defineRAG` even defaulted it to `'user'` and documented why, which made
|
|
13
|
+
* the lie legible: a reader could pick a role, read it back off the
|
|
14
|
+
* definition, and be told a role the run would never use.
|
|
15
|
+
*
|
|
16
|
+
* Delivering it instead is not a one-line change. Role-differentiated
|
|
17
|
+
* recall means putting non-system content into the message list, and the
|
|
18
|
+
* messages slot does not reach the model today (see
|
|
19
|
+
* `lib/injection-engine/messagesSlotRefusal.ts`): it is the observability
|
|
20
|
+
* projection of the conversation, not a wire. Honouring `asRole: 'user'`
|
|
21
|
+
* would have to route through that slot, which would trade a dead option
|
|
22
|
+
* for a recorded-and-dropped one — strictly worse, because the recording
|
|
23
|
+
* would then claim delivery.
|
|
24
|
+
*
|
|
25
|
+
* So the option is refused where it is written, and the refusal points at
|
|
26
|
+
* the feature that would make it real: role-differentiated recall arrives
|
|
27
|
+
* with messages delivery, if field evidence asks for it.
|
|
28
|
+
*
|
|
29
|
+
* A throw where there was a silent lie is a fix, not a break: nothing that
|
|
30
|
+
* worked stops working, and something that never worked stops pretending.
|
|
31
|
+
*/
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.refuseAsRole = exports.asRoleRefusal = void 0;
|
|
34
|
+
/**
|
|
35
|
+
* The refusal text, addressed from `site` (e.g. `defineRAG('product-docs')`).
|
|
36
|
+
* States the truth (never read; always system) and names what would change
|
|
37
|
+
* it, because a refusal that does not teach just moves the puzzle.
|
|
38
|
+
*/
|
|
39
|
+
function asRoleRefusal(site) {
|
|
40
|
+
return (`${site}: \`asRole\` has never been read. Every formatter this library ships ` +
|
|
41
|
+
`writes \`role: 'system'\`, so recall is always injected as system — the option ` +
|
|
42
|
+
`was stored on the definition and ignored by the run. It is removed rather than ` +
|
|
43
|
+
`honoured, because honouring it means putting recall into the messages slot, ` +
|
|
44
|
+
`which does not reach the model. Role-differentiated recall arrives with the ` +
|
|
45
|
+
`messages-delivery feature, if field evidence asks for it. Drop the option: ` +
|
|
46
|
+
`the behaviour you already had does not change.`);
|
|
47
|
+
}
|
|
48
|
+
exports.asRoleRefusal = asRoleRefusal;
|
|
49
|
+
/**
|
|
50
|
+
* Throw the refusal when a caller passed `asRole`. Presence, not value —
|
|
51
|
+
* an explicit `asRole: 'system'` was just as unread as `asRole: 'user'`,
|
|
52
|
+
* and letting the "harmless" one through would teach that the option
|
|
53
|
+
* works.
|
|
54
|
+
*/
|
|
55
|
+
function refuseAsRole(options, site) {
|
|
56
|
+
if ('asRole' in options)
|
|
57
|
+
throw new Error(asRoleRefusal(site));
|
|
58
|
+
}
|
|
59
|
+
exports.refuseAsRole = refuseAsRole;
|
|
60
|
+
//# sourceMappingURL=asRoleRefusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asRoleRefusal.js","sourceRoot":"","sources":["../../src/memory/asRoleRefusal.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;AAEH;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAY;IACxC,OAAO,CACL,GAAG,IAAI,uEAAuE;QAC9E,iFAAiF;QACjF,iFAAiF;QACjF,8EAA8E;QAC9E,8EAA8E;QAC9E,6EAA6E;QAC7E,gDAAgD,CACjD,CAAC;AACJ,CAAC;AAVD,sCAUC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,OAAe,EAAE,IAAY;IACxD,IAAI,QAAQ,IAAI,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AAChE,CAAC;AAFD,oCAEC"}
|
package/dist/memory/define.js
CHANGED
|
@@ -22,13 +22,15 @@
|
|
|
22
22
|
*
|
|
23
23
|
* Emits: Indirectly — the compiled subflows emit
|
|
24
24
|
* `agentfootprint.context.injected` with `source: 'memory'`
|
|
25
|
-
* when their formatter writes to the
|
|
25
|
+
* when their formatter writes to the system-prompt slot.
|
|
26
26
|
*
|
|
27
27
|
* @see ./define.types.ts for the const-objects + types
|
|
28
|
+
* @see ./asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
28
29
|
* @see ./pipeline/*.ts for the existing pipeline factories this dispatches to
|
|
29
30
|
*/
|
|
30
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
32
|
exports.unwrapMemoryFlowChart = exports.defineMemory = void 0;
|
|
33
|
+
const asRoleRefusal_js_1 = require("./asRoleRefusal.js");
|
|
32
34
|
const default_js_1 = require("./pipeline/default.js");
|
|
33
35
|
const ephemeral_js_1 = require("./pipeline/ephemeral.js");
|
|
34
36
|
const semantic_js_1 = require("./pipeline/semantic.js");
|
|
@@ -73,7 +75,6 @@ function defineMemory(options) {
|
|
|
73
75
|
read: brandPipeline(pipeline.read),
|
|
74
76
|
...(pipeline.write !== undefined && { write: brandPipeline(pipeline.write) }),
|
|
75
77
|
timing: options.timing ?? define_types_js_1.MEMORY_TIMING.TURN_START,
|
|
76
|
-
asRole: options.asRole ?? defaultRoleFor(options),
|
|
77
78
|
...(options.redact !== undefined && { redact: options.redact }),
|
|
78
79
|
...(options.type === define_types_js_1.MEMORY_TYPES.CAUSAL &&
|
|
79
80
|
options.projection !== undefined && {
|
|
@@ -88,6 +89,10 @@ function validate(options) {
|
|
|
88
89
|
if (!options.id || options.id.trim() === '') {
|
|
89
90
|
throw new Error('defineMemory: `id` is required and must be non-empty.');
|
|
90
91
|
}
|
|
92
|
+
// `asRole` no longer type-checks; this catches JavaScript callers and
|
|
93
|
+
// casts. Refused before anything else is validated so the message is
|
|
94
|
+
// about the option the caller actually wrote.
|
|
95
|
+
(0, asRoleRefusal_js_1.refuseAsRole)(options, `defineMemory('${options.id}')`);
|
|
91
96
|
if (!options.store) {
|
|
92
97
|
throw new Error(`defineMemory[id=${options.id}]: \`store\` is required. ` +
|
|
93
98
|
'Pass `new InMemoryStore()` for dev/tests, or a backed store for production.');
|
|
@@ -277,24 +282,6 @@ function buildCausalPipeline(options) {
|
|
|
277
282
|
return (0, index_js_1.snapshotPipeline)(config);
|
|
278
283
|
}
|
|
279
284
|
// ─── Helpers ───────────────────────────────────────────────────────
|
|
280
|
-
/**
|
|
281
|
-
* Default `asRole` per type — system for behavior-shaping memory,
|
|
282
|
-
* user for retrieved facts (so the LLM treats them as context, not
|
|
283
|
-
* instruction).
|
|
284
|
-
*/
|
|
285
|
-
function defaultRoleFor(options) {
|
|
286
|
-
switch (options.type) {
|
|
287
|
-
case define_types_js_1.MEMORY_TYPES.EPISODIC:
|
|
288
|
-
case define_types_js_1.MEMORY_TYPES.NARRATIVE:
|
|
289
|
-
return 'system';
|
|
290
|
-
case define_types_js_1.MEMORY_TYPES.SEMANTIC:
|
|
291
|
-
return 'system';
|
|
292
|
-
case define_types_js_1.MEMORY_TYPES.CAUSAL:
|
|
293
|
-
return 'system';
|
|
294
|
-
default:
|
|
295
|
-
return 'system';
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
285
|
/**
|
|
299
286
|
* The factory hands back an opaque `ReadonlyMemoryFlowChart<T>` brand
|
|
300
287
|
* to keep consumers from reaching into the FlowChart shape directly —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/memory/define.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/memory/define.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAEH,yDAAkD;AAElD,sDAAoF;AACpF,0DAA4D;AAC5D,wDAAuF;AACvF,gDAA2E;AAC3E,0DAA0F;AAC1F,gDAA2E;AAC3E,gDAAkF;AAGlF,uDAgB2B;AAG3B,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,YAAY,CAAC,OAA4B;IACvD,QAAQ,CAAC,OAAO,CAAC,CAAC;IAElB,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAExC,MAAM,UAAU,GAAqB;QACnC,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,IA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-31,7 +31,9 @@
|
|
|
31
31
|
*
|
|
32
32
|
* Emits: Indirectly — every memory pipeline emits the unified
|
|
33
33
|
* `agentfootprint.context.injected` event with `source: 'memory'`
|
|
34
|
-
* when its read subflow places content into the
|
|
34
|
+
* when its read subflow places content into the system-prompt
|
|
35
|
+
* slot (every shipped formatter writes `role: 'system'`, and
|
|
36
|
+
* system-role recall composes into `inject.systemPrompt`).
|
|
35
37
|
*
|
|
36
38
|
* @see ./define.ts for the `defineMemory()` factory itself
|
|
37
39
|
* @see ../../docs-next for guides + the 7 strategy examples
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.types.js","sourceRoot":"","sources":["../../src/memory/define.types.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"define.types.js","sourceRoot":"","sources":["../../src/memory/define.types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;AAMH,uEAAuE;AAEvE;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG;IAC1B,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;CACR,CAAC;AAGX;;;;;;;;GAQG;AACU,QAAA,iBAAiB,GAAG;IAC/B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACR,CAAC;AAGX;;;;;;GAMG;AACU,QAAA,aAAa,GAAG;IAC3B,eAAe,EAAE,iBAAiB;IAClC,UAAU,EAAE,YAAY;CAChB,CAAC;AAGX;;;;;;;;GAQG;AACU,QAAA,oBAAoB,GAAG;IAClC,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACJ,CAAC;AAqNX,uEAAuE;AAEvE,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAQ,MAAM,CAAC,MAAM,CAAC,oBAAY,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAFD,oCAEC;AAED,SAAgB,oBAAoB,CAAC,KAAa;IAChD,OAAQ,MAAM,CAAC,MAAM,CAAC,yBAAiB,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAFD,oDAEC;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,OAAQ,MAAM,CAAC,MAAM,CAAC,qBAAa,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAFD,wCAEC;AAED,SAAgB,oBAAoB,CAAC,KAAa;IAChD,OAAQ,MAAM,CAAC,MAAM,CAAC,4BAAoB,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAFD,oDAEC;AAED,uEAAuE;AAEvE;;;;;GAKG;AACU,QAAA,2BAA2B,GAAG,kBAA2B,CAAC;AAEvE,SAAgB,kBAAkB,CAAC,EAAU;IAC3C,OAAO,GAAG,mCAA2B,GAAG,EAAE,EAAE,CAAC;AAC/C,CAAC;AAFD,gDAEC;AAED,SAAgB,oBAAoB,CAAC,GAAW;IAC9C,OAAO,GAAG,CAAC,UAAU,CAAC,mCAA2B,CAAC,CAAC;AACrD,CAAC;AAFD,oDAEC"}
|
|
@@ -36,17 +36,27 @@ function formatDefault(config = {}) {
|
|
|
36
36
|
const blocks = selected.map(renderEntry).join('\n\n');
|
|
37
37
|
const content = (header ? `${header}\n\n` : '') + blocks + (footer ? `\n\n${footer}` : '');
|
|
38
38
|
scope.formatted = [{ role: 'system', content }];
|
|
39
|
-
// Context-engineering emit: memory formatted N entries into
|
|
40
|
-
// system message
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
39
|
+
// Context-engineering emit: memory formatted N entries into one
|
|
40
|
+
// system-role message.
|
|
41
|
+
//
|
|
42
|
+
// LAW: this event must name the slot the content actually lands in.
|
|
43
|
+
// It says `'system-prompt'` because that is where it goes, and it is
|
|
44
|
+
// checkable end to end — `memoryRecallInjections` routes system-role
|
|
45
|
+
// recall to `inject.systemPrompt`, `buildSystemPromptSlot` records it
|
|
46
|
+
// as a `slot: 'system-prompt'` injection, and the request carries it
|
|
47
|
+
// in `systemPrompt`. Two events describing one piece of content must
|
|
48
|
+
// not disagree: `context.memory.injected` and `context.injected` name
|
|
49
|
+
// the same slot for the same bytes.
|
|
50
|
+
//
|
|
51
|
+
// Until 7.20.0 this said `'messages'`, which was never true of this
|
|
52
|
+
// stage — `scope.formatted` above is unconditionally role `'system'`.
|
|
53
|
+
// A consumer branching on the old value was branching on a lie.
|
|
44
54
|
if (typeof scope.$emit === 'function') {
|
|
45
55
|
scope.$emit('agentfootprint.context.memory.injected', {
|
|
46
|
-
slot: '
|
|
56
|
+
slot: 'system-prompt',
|
|
47
57
|
// Memory injects ONE system-role message containing every selected
|
|
48
58
|
// entry as a citation block (see DEFAULT_HEADER + renderEntry).
|
|
49
|
-
// The downstream
|
|
59
|
+
// The downstream delta is therefore +1 system fragment, regardless
|
|
50
60
|
// of how many memory entries it carries.
|
|
51
61
|
role: 'system',
|
|
52
62
|
deltaCount: { system: 1 },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDefault.js","sourceRoot":"","sources":["../../../src/memory/stages/formatDefault.ts"],"names":[],"mappings":";;;AAiEA,MAAM,cAAc,GAClB,uFAAuF,CAAC;AAE1F;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,kBAAkB,CAAC,KAA2B;IACrD,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC;IACxB,MAAM,QAAQ,GAAG,K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yCAAyC;gBACzC,IAAI,EAAE,QAAiB;gBACvB,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE;gBACzB,KAAK,EAAE,QAAQ,CAAC,MAAM;gBACtB,0EAA0E;gBAC1E,iDAAiD;gBACjD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;aACxE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAlDD,sCAkDC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* RAG is a context-engineering flavor: embed the user's question,
|
|
5
5
|
* retrieve top-K semantically similar chunks from a vector store,
|
|
6
|
-
* inject those chunks into the
|
|
6
|
+
* inject those chunks into the system-prompt slot of the next LLM call.
|
|
7
7
|
* It's the same plumbing as `defineMemory({ type: SEMANTIC,
|
|
8
8
|
* strategy: TOP_K })` — the rename is for intent + ergonomics.
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* └─► CAUSAL (footprintjs decision snapshots)
|
|
14
14
|
*
|
|
15
15
|
* defineRAG ─► SEMANTIC + TOP_K with RAG-specific defaults
|
|
16
|
-
* (
|
|
16
|
+
* (topK=3, threshold=0.7, no LLM-extract)
|
|
17
17
|
*
|
|
18
18
|
* Pattern: Composition over duplication — defineRAG returns a
|
|
19
19
|
* MemoryDefinition produced by defineMemory. No new engine
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Emits: Indirectly — the underlying memory pipeline emits
|
|
29
29
|
* `agentfootprint.context.injected` when retrieved chunks
|
|
30
|
-
* land in the
|
|
30
|
+
* land in the system-prompt slot.
|
|
31
31
|
*
|
|
32
32
|
* @see ./indexDocuments.ts for the seeding helper
|
|
33
33
|
* @see ../../memory/define.ts for the underlying factory
|
|
34
|
+
* @see ../../memory/asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
34
35
|
*
|
|
35
36
|
* @example Basic usage
|
|
36
37
|
* ```ts
|
|
@@ -61,7 +62,6 @@ import { mock } from 'agentfootprint/llm-providers';
|
|
|
61
62
|
* .build();
|
|
62
63
|
* ```
|
|
63
64
|
*/
|
|
64
|
-
import type { ContextRole } from '../../events/types.js';
|
|
65
65
|
import type { Embedder } from '../../memory/embedding/index.js';
|
|
66
66
|
import type { MemoryStore } from '../../memory/store/index.js';
|
|
67
67
|
import type { MemoryDefinition } from '../../memory/define.types.js';
|
|
@@ -112,21 +112,6 @@ export interface DefineRAGOptions {
|
|
|
112
112
|
* sit comfortably with 0.7.
|
|
113
113
|
*/
|
|
114
114
|
readonly threshold?: number;
|
|
115
|
-
/**
|
|
116
|
-
* Role to use when injecting retrieved chunks into the messages
|
|
117
|
-
* slot. Default `'user'`.
|
|
118
|
-
*
|
|
119
|
-
* Why `'user'`: in tool-using ReAct loops, retrieved chunks
|
|
120
|
-
* conceptually "augment what the user asked." Anthropic's tool-use
|
|
121
|
-
* cookbook and OpenAI's RAG cookbook both show retrieved context
|
|
122
|
-
* inside user-turn messages.
|
|
123
|
-
*
|
|
124
|
-
* Use `'system'` for authoritative reference docs that should
|
|
125
|
-
* outweigh user instruction (policy / compliance / brand-voice
|
|
126
|
-
* corpora). Use `'assistant'` only if you've persisted prior agent
|
|
127
|
-
* turns as context — rare.
|
|
128
|
-
*/
|
|
129
|
-
readonly asRole?: ContextRole;
|
|
130
115
|
}
|
|
131
116
|
/**
|
|
132
117
|
* Build a RAG context-engineering definition. The returned
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineRAG.d.ts","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"defineRAG.d.ts","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAKrE,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAU7B;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAiClE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `asRole` refusal — one sentence, said in every place the option
|
|
3
|
+
* could be declared.
|
|
4
|
+
*
|
|
5
|
+
* WHY this exists at all: `defineMemory({ asRole })` and
|
|
6
|
+
* `defineRAG({ asRole })` accepted a role, stored it on the returned
|
|
7
|
+
* `MemoryDefinition`, and NOTHING ever read it. Every formatter this
|
|
8
|
+
* library ships writes `role: 'system'` — `formatDefault`, `formatFacts`,
|
|
9
|
+
* `formatAsNarrative`, the causal `loadSnapshot`, and the auto pipeline —
|
|
10
|
+
* so recall has always been injected as system, whatever the option said.
|
|
11
|
+
* `defineRAG` even defaulted it to `'user'` and documented why, which made
|
|
12
|
+
* the lie legible: a reader could pick a role, read it back off the
|
|
13
|
+
* definition, and be told a role the run would never use.
|
|
14
|
+
*
|
|
15
|
+
* Delivering it instead is not a one-line change. Role-differentiated
|
|
16
|
+
* recall means putting non-system content into the message list, and the
|
|
17
|
+
* messages slot does not reach the model today (see
|
|
18
|
+
* `lib/injection-engine/messagesSlotRefusal.ts`): it is the observability
|
|
19
|
+
* projection of the conversation, not a wire. Honouring `asRole: 'user'`
|
|
20
|
+
* would have to route through that slot, which would trade a dead option
|
|
21
|
+
* for a recorded-and-dropped one — strictly worse, because the recording
|
|
22
|
+
* would then claim delivery.
|
|
23
|
+
*
|
|
24
|
+
* So the option is refused where it is written, and the refusal points at
|
|
25
|
+
* the feature that would make it real: role-differentiated recall arrives
|
|
26
|
+
* with messages delivery, if field evidence asks for it.
|
|
27
|
+
*
|
|
28
|
+
* A throw where there was a silent lie is a fix, not a break: nothing that
|
|
29
|
+
* worked stops working, and something that never worked stops pretending.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* The refusal text, addressed from `site` (e.g. `defineRAG('product-docs')`).
|
|
33
|
+
* States the truth (never read; always system) and names what would change
|
|
34
|
+
* it, because a refusal that does not teach just moves the puzzle.
|
|
35
|
+
*/
|
|
36
|
+
export declare function asRoleRefusal(site: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Throw the refusal when a caller passed `asRole`. Presence, not value —
|
|
39
|
+
* an explicit `asRole: 'system'` was just as unread as `asRole: 'user'`,
|
|
40
|
+
* and letting the "harmless" one through would teach that the option
|
|
41
|
+
* works.
|
|
42
|
+
*/
|
|
43
|
+
export declare function refuseAsRole(options: object, site: string): void;
|
|
44
|
+
//# sourceMappingURL=asRoleRefusal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asRoleRefusal.d.ts","sourceRoot":"","sources":["../../../src/memory/asRoleRefusal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUlD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAEhE"}
|
|
@@ -21,9 +21,10 @@
|
|
|
21
21
|
*
|
|
22
22
|
* Emits: Indirectly — the compiled subflows emit
|
|
23
23
|
* `agentfootprint.context.injected` with `source: 'memory'`
|
|
24
|
-
* when their formatter writes to the
|
|
24
|
+
* when their formatter writes to the system-prompt slot.
|
|
25
25
|
*
|
|
26
26
|
* @see ./define.types.ts for the const-objects + types
|
|
27
|
+
* @see ./asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
27
28
|
* @see ./pipeline/*.ts for the existing pipeline factories this dispatches to
|
|
28
29
|
*/
|
|
29
30
|
import { type DefineMemoryOptions } from './define.types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAaH,OAAO,EAIL,KAAK,mBAAmB,EAYzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAInF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,gBAAgB,CAoB3E;AA8QD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,OAAO,CAErF"}
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
*
|
|
31
31
|
* Emits: Indirectly — every memory pipeline emits the unified
|
|
32
32
|
* `agentfootprint.context.injected` event with `source: 'memory'`
|
|
33
|
-
* when its read subflow places content into the
|
|
33
|
+
* when its read subflow places content into the system-prompt
|
|
34
|
+
* slot (every shipped formatter writes `role: 'system'`, and
|
|
35
|
+
* system-role recall composes into `inject.systemPrompt`).
|
|
34
36
|
*
|
|
35
37
|
* @see ./define.ts for the `defineMemory()` factory itself
|
|
36
38
|
* @see ../../docs-next for guides + the 7 strategy examples
|
|
37
39
|
* @see MEMORY.md for the load-bearing design memory
|
|
38
40
|
*/
|
|
39
41
|
import type { LLMProvider } from '../adapters/types.js';
|
|
40
|
-
import type { ContextRole } from '../events/types.js';
|
|
41
42
|
import type { Embedder } from './embedding/index.js';
|
|
42
43
|
import type { MemoryStore } from './store/index.js';
|
|
43
44
|
/**
|
|
@@ -217,8 +218,6 @@ export interface MemoryDefinition<T = unknown> {
|
|
|
217
218
|
readonly write?: ReadonlyMemoryFlowChart<T>;
|
|
218
219
|
/** When `read` runs. Default `TURN_START`. */
|
|
219
220
|
readonly timing: MemoryTiming;
|
|
220
|
-
/** Role to use when injecting formatted content into the messages slot. */
|
|
221
|
-
readonly asRole: ContextRole;
|
|
222
221
|
/** Reserved for a future release — patterns to redact before write. */
|
|
223
222
|
readonly redact?: MemoryRedactionPolicy;
|
|
224
223
|
/** Snapshot projection — only meaningful when `type === CAUSAL`. */
|
|
@@ -244,7 +243,6 @@ export interface DefineMemoryOptionsBase {
|
|
|
244
243
|
readonly store: MemoryStore;
|
|
245
244
|
readonly strategy: Strategy;
|
|
246
245
|
readonly timing?: MemoryTiming;
|
|
247
|
-
readonly asRole?: ContextRole;
|
|
248
246
|
readonly redact?: MemoryRedactionPolicy;
|
|
249
247
|
}
|
|
250
248
|
export interface DefineEpisodicOptions extends DefineMemoryOptionsBase {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.types.d.ts","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"define.types.d.ts","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AACX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE1E;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;CAQpB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE5F;;;;;;GAMG;AACH,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE9E;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAIlG,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,iBAAiB,CAAC,MAAM,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,iBAA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BAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,YAAY,CAEnE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,kBAAkB,CAE/E;AAID;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,oBAA8B,CAAC;AAEvE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDefault.d.ts","sourceRoot":"","sources":["../../../../src/memory/stages/formatDefault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC;IAC/D;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AA8BD,wBAAgB,aAAa,CAAC,MAAM,GAAE,mBAAwB,WAMvC,WAAW,WAAW,CAAC,KAAG,QAAQ,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"formatDefault.d.ts","sourceRoot":"","sources":["../../../../src/memory/stages/formatDefault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC;IAC/D;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AA8BD,wBAAgB,aAAa,CAAC,MAAM,GAAE,mBAAwB,WAMvC,WAAW,WAAW,CAAC,KAAG,QAAQ,IAAI,CAAC,CA4C7D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentfootprint",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.20.0",
|
|
4
4
|
"description": "The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sanjay Krishna Anbalagan",
|