agentfootprint 8.1.0 → 8.2.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/dist/core/Agent.js +44 -1
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/stages/seed.js +10 -0
- package/dist/core/agent/stages/seed.js.map +1 -1
- package/dist/core/agent/stages/window.js +21 -0
- package/dist/core/agent/stages/window.js.map +1 -1
- package/dist/core/agent/window/folded.js +98 -0
- package/dist/core/agent/window/folded.js.map +1 -0
- package/dist/core/agent/window/index.js +9 -1
- package/dist/core/agent/window/index.js.map +1 -1
- package/dist/core/agent/window/options.js +18 -2
- package/dist/core/agent/window/options.js.map +1 -1
- package/dist/core/agent/window/strategies/summarizeOldest.js +25 -2
- package/dist/core/agent/window/strategies/summarizeOldest.js.map +1 -1
- package/dist/core/agent/window/summarize.js +27 -1
- package/dist/core/agent/window/summarize.js.map +1 -1
- package/dist/core/agent/window/types.js +6 -0
- package/dist/core/agent/window/types.js.map +1 -1
- package/dist/core/runCheckpoint.js +9 -1
- package/dist/core/runCheckpoint.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +17 -0
- package/dist/esm/core/Agent.js +44 -1
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/stages/seed.d.ts +11 -0
- package/dist/esm/core/agent/stages/seed.js +10 -0
- package/dist/esm/core/agent/stages/seed.js.map +1 -1
- package/dist/esm/core/agent/stages/window.d.ts +13 -0
- package/dist/esm/core/agent/stages/window.js +21 -0
- package/dist/esm/core/agent/stages/window.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +15 -1
- package/dist/esm/core/agent/window/folded.d.ts +90 -0
- package/dist/esm/core/agent/window/folded.js +92 -0
- package/dist/esm/core/agent/window/folded.js.map +1 -0
- package/dist/esm/core/agent/window/index.d.ts +7 -1
- package/dist/esm/core/agent/window/index.js +6 -0
- package/dist/esm/core/agent/window/index.js.map +1 -1
- package/dist/esm/core/agent/window/options.d.ts +7 -1
- package/dist/esm/core/agent/window/options.js +17 -1
- package/dist/esm/core/agent/window/options.js.map +1 -1
- package/dist/esm/core/agent/window/strategies/summarizeOldest.d.ts +4 -2
- package/dist/esm/core/agent/window/strategies/summarizeOldest.js +25 -2
- package/dist/esm/core/agent/window/strategies/summarizeOldest.js.map +1 -1
- package/dist/esm/core/agent/window/strategy.d.ts +26 -1
- package/dist/esm/core/agent/window/summarize.d.ts +11 -0
- package/dist/esm/core/agent/window/summarize.js +27 -1
- package/dist/esm/core/agent/window/summarize.js.map +1 -1
- package/dist/esm/core/agent/window/types.d.ts +106 -1
- package/dist/esm/core/agent/window/types.js +6 -0
- package/dist/esm/core/agent/window/types.js.map +1 -1
- package/dist/esm/core/runCheckpoint.d.ts +32 -1
- package/dist/esm/core/runCheckpoint.js +9 -1
- package/dist/esm/core/runCheckpoint.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/types/core/Agent.d.ts +17 -0
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/stages/seed.d.ts +11 -0
- package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
- package/dist/types/core/agent/stages/window.d.ts +13 -0
- package/dist/types/core/agent/stages/window.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +15 -1
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/agent/window/folded.d.ts +91 -0
- package/dist/types/core/agent/window/folded.d.ts.map +1 -0
- package/dist/types/core/agent/window/index.d.ts +7 -1
- package/dist/types/core/agent/window/index.d.ts.map +1 -1
- package/dist/types/core/agent/window/options.d.ts +7 -1
- package/dist/types/core/agent/window/options.d.ts.map +1 -1
- package/dist/types/core/agent/window/strategies/summarizeOldest.d.ts +4 -2
- package/dist/types/core/agent/window/strategies/summarizeOldest.d.ts.map +1 -1
- package/dist/types/core/agent/window/strategy.d.ts +26 -1
- package/dist/types/core/agent/window/strategy.d.ts.map +1 -1
- package/dist/types/core/agent/window/summarize.d.ts +11 -0
- package/dist/types/core/agent/window/summarize.d.ts.map +1 -1
- package/dist/types/core/agent/window/types.d.ts +106 -1
- package/dist/types/core/agent/window/types.d.ts.map +1 -1
- package/dist/types/core/runCheckpoint.d.ts +32 -1
- package/dist/types/core/runCheckpoint.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* window/folded — join a summary sitting in a conversation back to what it
|
|
3
|
+
* stands for.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: Pure lookup over recorded facts. No I/O, no inference.
|
|
6
|
+
* Role: core/ layer, and the ONE public door onto retained originals.
|
|
7
|
+
* Emits: N/A.
|
|
8
|
+
*
|
|
9
|
+
* ── Why a fingerprint and not an index ──────────────────────────────────────
|
|
10
|
+
* The obvious join key is "the summary is at `history[3]`". It is also wrong.
|
|
11
|
+
* A later fold swallows the span that CONTAINS an earlier summary, and every
|
|
12
|
+
* index after it moves; a conversation that folded four times would need its
|
|
13
|
+
* stored indices rewritten on every fold, and any reader holding an old one
|
|
14
|
+
* would silently be pointing at somebody else's message.
|
|
15
|
+
*
|
|
16
|
+
* So the join key is a fingerprint of the summary message's full content —
|
|
17
|
+
* authored frame included. Three things follow, and all three are the point:
|
|
18
|
+
*
|
|
19
|
+
* • it costs NO extra bytes on the wire (no id token planted in the frame);
|
|
20
|
+
* • it survives JSON, storage, and being read by a runtime that has never
|
|
21
|
+
* heard of this function;
|
|
22
|
+
* • it cannot be FORGED. A model that writes a message opening with the
|
|
23
|
+
* frame's own words produces different content, therefore a different
|
|
24
|
+
* fingerprint, therefore no match — `isCompactedSummary` alone says "this
|
|
25
|
+
* LOOKS like a frame", and this says "this IS the frame of a fold that was
|
|
26
|
+
* recorded". The two answers are different questions and the gap between
|
|
27
|
+
* them is exactly where a forgery would live.
|
|
28
|
+
*
|
|
29
|
+
* ── Absent is an answer ─────────────────────────────────────────────────────
|
|
30
|
+
* `undefined` means "no fold was recorded for this message" and never "there
|
|
31
|
+
* were no originals". A conversation stored by 8.1 has summaries and no spans
|
|
32
|
+
* at all; one folded under `retain: 'discard'` has a span whose `messages` is
|
|
33
|
+
* absent. Those are three different facts and the caller can tell them apart:
|
|
34
|
+
* no span, a span with no messages, a span with messages.
|
|
35
|
+
*/
|
|
36
|
+
import type { LLMMessage } from '../../../adapters/types.js';
|
|
37
|
+
import type { FoldedSpan } from './types.js';
|
|
38
|
+
/**
|
|
39
|
+
* The join key for one summary message: a fingerprint of its whole content.
|
|
40
|
+
*
|
|
41
|
+
* @internal Consumers join through {@link foldedSpanFor}; this is exported for
|
|
42
|
+
* the strategy that stamps the span and for tests that pin the two agree.
|
|
43
|
+
*/
|
|
44
|
+
export declare function summaryFingerprint(content: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* The smallest thing that can answer "what did this conversation fold?".
|
|
47
|
+
*
|
|
48
|
+
* Structural rather than `AgentRunCheckpoint` on purpose: it also fits a
|
|
49
|
+
* paused run's `conversation`, a hand-built fixture, and anything a consumer
|
|
50
|
+
* pulled out of their own store — and it keeps this file from importing the
|
|
51
|
+
* checkpoint module, which imports this one's sibling types.
|
|
52
|
+
*/
|
|
53
|
+
export interface FoldedConversation {
|
|
54
|
+
readonly folded?: readonly FoldedSpan[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* What one summary message in a conversation stands for.
|
|
58
|
+
*
|
|
59
|
+
* Hand it the conversation you stored and a message out of its `history`; get
|
|
60
|
+
* back the fold that produced that message, with the original messages when
|
|
61
|
+
* the policy retained them.
|
|
62
|
+
*
|
|
63
|
+
* @returns the span, or `undefined` when this conversation recorded no fold
|
|
64
|
+
* for this message — see "Absent is an answer" above.
|
|
65
|
+
*
|
|
66
|
+
* @example Show a user what the agent actually saw last week
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { foldedSpanFor, isCompactedSummary } from 'agentfootprint';
|
|
69
|
+
*
|
|
70
|
+
* const conversation = readEnvelope(await sessions.hydrate(sessionId));
|
|
71
|
+
* for (const message of conversation.history) {
|
|
72
|
+
* if (!isCompactedSummary(message)) continue;
|
|
73
|
+
* const span = foldedSpanFor(conversation, message);
|
|
74
|
+
* console.log(`summary of ${span?.messageCount ?? '?'} messages`);
|
|
75
|
+
* for (const original of span?.messages ?? []) {
|
|
76
|
+
* console.log(` ${original.role}: ${original.content}`);
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function foldedSpanFor(conversation: FoldedConversation, message: LLMMessage): FoldedSpan | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Every message this conversation ever folded, oldest fold first, flattened.
|
|
84
|
+
*
|
|
85
|
+
* The transcript-shaped answer to `foldedSpanFor`'s message-shaped one: what
|
|
86
|
+
* a support view prints when somebody asks what the agent was told before the
|
|
87
|
+
* summaries. Spans that were discarded contribute nothing — they have nothing
|
|
88
|
+
* to contribute, and `foldedSpanFor` is where you find out that they existed.
|
|
89
|
+
*/
|
|
90
|
+
export declare function foldedMessages(conversation: FoldedConversation): readonly LLMMessage[];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* window/folded — join a summary sitting in a conversation back to what it
|
|
3
|
+
* stands for.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: Pure lookup over recorded facts. No I/O, no inference.
|
|
6
|
+
* Role: core/ layer, and the ONE public door onto retained originals.
|
|
7
|
+
* Emits: N/A.
|
|
8
|
+
*
|
|
9
|
+
* ── Why a fingerprint and not an index ──────────────────────────────────────
|
|
10
|
+
* The obvious join key is "the summary is at `history[3]`". It is also wrong.
|
|
11
|
+
* A later fold swallows the span that CONTAINS an earlier summary, and every
|
|
12
|
+
* index after it moves; a conversation that folded four times would need its
|
|
13
|
+
* stored indices rewritten on every fold, and any reader holding an old one
|
|
14
|
+
* would silently be pointing at somebody else's message.
|
|
15
|
+
*
|
|
16
|
+
* So the join key is a fingerprint of the summary message's full content —
|
|
17
|
+
* authored frame included. Three things follow, and all three are the point:
|
|
18
|
+
*
|
|
19
|
+
* • it costs NO extra bytes on the wire (no id token planted in the frame);
|
|
20
|
+
* • it survives JSON, storage, and being read by a runtime that has never
|
|
21
|
+
* heard of this function;
|
|
22
|
+
* • it cannot be FORGED. A model that writes a message opening with the
|
|
23
|
+
* frame's own words produces different content, therefore a different
|
|
24
|
+
* fingerprint, therefore no match — `isCompactedSummary` alone says "this
|
|
25
|
+
* LOOKS like a frame", and this says "this IS the frame of a fold that was
|
|
26
|
+
* recorded". The two answers are different questions and the gap between
|
|
27
|
+
* them is exactly where a forgery would live.
|
|
28
|
+
*
|
|
29
|
+
* ── Absent is an answer ─────────────────────────────────────────────────────
|
|
30
|
+
* `undefined` means "no fold was recorded for this message" and never "there
|
|
31
|
+
* were no originals". A conversation stored by 8.1 has summaries and no spans
|
|
32
|
+
* at all; one folded under `retain: 'discard'` has a span whose `messages` is
|
|
33
|
+
* absent. Those are three different facts and the caller can tell them apart:
|
|
34
|
+
* no span, a span with no messages, a span with messages.
|
|
35
|
+
*/
|
|
36
|
+
import { fnv1a } from '../../slots/helpers.js';
|
|
37
|
+
/**
|
|
38
|
+
* The join key for one summary message: a fingerprint of its whole content.
|
|
39
|
+
*
|
|
40
|
+
* @internal Consumers join through {@link foldedSpanFor}; this is exported for
|
|
41
|
+
* the strategy that stamps the span and for tests that pin the two agree.
|
|
42
|
+
*/
|
|
43
|
+
export function summaryFingerprint(content) {
|
|
44
|
+
return fnv1a(content);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* What one summary message in a conversation stands for.
|
|
48
|
+
*
|
|
49
|
+
* Hand it the conversation you stored and a message out of its `history`; get
|
|
50
|
+
* back the fold that produced that message, with the original messages when
|
|
51
|
+
* the policy retained them.
|
|
52
|
+
*
|
|
53
|
+
* @returns the span, or `undefined` when this conversation recorded no fold
|
|
54
|
+
* for this message — see "Absent is an answer" above.
|
|
55
|
+
*
|
|
56
|
+
* @example Show a user what the agent actually saw last week
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { foldedSpanFor, isCompactedSummary } from 'agentfootprint';
|
|
59
|
+
*
|
|
60
|
+
* const conversation = readEnvelope(await sessions.hydrate(sessionId));
|
|
61
|
+
* for (const message of conversation.history) {
|
|
62
|
+
* if (!isCompactedSummary(message)) continue;
|
|
63
|
+
* const span = foldedSpanFor(conversation, message);
|
|
64
|
+
* console.log(`summary of ${span?.messageCount ?? '?'} messages`);
|
|
65
|
+
* for (const original of span?.messages ?? []) {
|
|
66
|
+
* console.log(` ${original.role}: ${original.content}`);
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function foldedSpanFor(conversation, message) {
|
|
72
|
+
const spans = conversation.folded;
|
|
73
|
+
if (spans === undefined || spans.length === 0)
|
|
74
|
+
return undefined;
|
|
75
|
+
const fingerprint = summaryFingerprint(message.content);
|
|
76
|
+
return spans.find((span) => span.summaryFingerprint === fingerprint);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Every message this conversation ever folded, oldest fold first, flattened.
|
|
80
|
+
*
|
|
81
|
+
* The transcript-shaped answer to `foldedSpanFor`'s message-shaped one: what
|
|
82
|
+
* a support view prints when somebody asks what the agent was told before the
|
|
83
|
+
* summaries. Spans that were discarded contribute nothing — they have nothing
|
|
84
|
+
* to contribute, and `foldedSpanFor` is where you find out that they existed.
|
|
85
|
+
*/
|
|
86
|
+
export function foldedMessages(conversation) {
|
|
87
|
+
const out = [];
|
|
88
|
+
for (const span of conversation.folded ?? [])
|
|
89
|
+
out.push(...(span.messages ?? []));
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=folded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"folded.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/folded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAI/C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,aAAa,CAC3B,YAAgC,EAChC,OAAmB;IAEnB,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC;IAClC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAChE,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,KAAK,WAAW,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,YAAgC;IAC7D,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,MAAM,IAAI,EAAE;QAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;IACjF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
* is a claim about the past, so this library files it as a claim — not as the
|
|
9
9
|
* past. A drop is an absence, and it is named the same way.
|
|
10
10
|
*
|
|
11
|
+
* A commit log lives as long as the process. A conversation lives longer, so
|
|
12
|
+
* `.compaction({ retain })` also carries the folded originals on the
|
|
13
|
+
* conversation checkpoint — `foldedSpanFor(conversation, message)` is the door
|
|
14
|
+
* back to them, in this process or the one after the deploy.
|
|
15
|
+
*
|
|
11
16
|
* Three strategies ship, all sharing one turn segmentation and one refusal
|
|
12
17
|
* engine:
|
|
13
18
|
* `summarizeOldest` fold the oldest span into a summary (`.compaction()`)
|
|
@@ -17,7 +22,8 @@
|
|
|
17
22
|
* Public surface (re-exported from the package root).
|
|
18
23
|
*/
|
|
19
24
|
export { CompactionUnmeasurableError } from './errors.js';
|
|
20
|
-
export type { CompactionOptions, CompactionRecord, FoldRefusal, FoldRefusalReason, ResolvedCompaction, SlidingWindowOptions, SlidingWindowRecord, TokenBudgetOptions, TokenBudgetRecord, WindowRecord, WindowRefusal, WindowRefusalReason, } from './types.js';
|
|
25
|
+
export type { CompactionOptions, CompactionRecord, CompactionRetention, FoldedSpan, FoldRefusal, FoldRefusalReason, ResolvedCompaction, SlidingWindowOptions, SlidingWindowRecord, TokenBudgetOptions, TokenBudgetRecord, WindowRecord, WindowRefusal, WindowRefusalReason, } from './types.js';
|
|
26
|
+
export { foldedMessages, foldedSpanFor, type FoldedConversation } from './folded.js';
|
|
21
27
|
export type { RemovalFacts, WindowEviction, WindowStrategy, WindowStrategyInput, WindowStrategyResult, } from './strategy.js';
|
|
22
28
|
export type { RemovalPlan, Turn } from './turns.js';
|
|
23
29
|
export { COMPACTED_FRAME_PREFIX, isCompactedSummary } from './summarize.js';
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
* is a claim about the past, so this library files it as a claim — not as the
|
|
9
9
|
* past. A drop is an absence, and it is named the same way.
|
|
10
10
|
*
|
|
11
|
+
* A commit log lives as long as the process. A conversation lives longer, so
|
|
12
|
+
* `.compaction({ retain })` also carries the folded originals on the
|
|
13
|
+
* conversation checkpoint — `foldedSpanFor(conversation, message)` is the door
|
|
14
|
+
* back to them, in this process or the one after the deploy.
|
|
15
|
+
*
|
|
11
16
|
* Three strategies ship, all sharing one turn segmentation and one refusal
|
|
12
17
|
* engine:
|
|
13
18
|
* `summarizeOldest` fold the oldest span into a summary (`.compaction()`)
|
|
@@ -17,6 +22,7 @@
|
|
|
17
22
|
* Public surface (re-exported from the package root).
|
|
18
23
|
*/
|
|
19
24
|
export { CompactionUnmeasurableError } from './errors.js';
|
|
25
|
+
export { foldedMessages, foldedSpanFor } from './folded.js';
|
|
20
26
|
export { COMPACTED_FRAME_PREFIX, isCompactedSummary } from './summarize.js';
|
|
21
27
|
export { DROP_NOTICE_PREFIX, isDropNotice } from './notice.js';
|
|
22
28
|
export { summarizeOldest } from './strategies/summarizeOldest.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAiB1D,OAAO,EAAE,cAAc,EAAE,aAAa,EAA2B,MAAM,aAAa,CAAC;AASrF,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -13,9 +13,15 @@
|
|
|
13
13
|
* out to be nonsense on iteration 40 of a paid run is a policy that cost you
|
|
14
14
|
* money to discover.
|
|
15
15
|
*/
|
|
16
|
-
import type { CompactionOptions, ResolvedCompaction, SlidingWindowOptions, TokenBudgetOptions } from './types.js';
|
|
16
|
+
import type { CompactionOptions, CompactionRetention, ResolvedCompaction, SlidingWindowOptions, TokenBudgetOptions } from './types.js';
|
|
17
17
|
/** Default depth of the "never touch this" recent window. */
|
|
18
18
|
export declare const DEFAULT_KEEP_RECENT_TURNS = 6;
|
|
19
|
+
/**
|
|
20
|
+
* What happens to folded messages when nobody said. The originals ride with
|
|
21
|
+
* the conversation: losing them has to be a choice somebody typed, not a
|
|
22
|
+
* default they inherited.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_RETENTION: CompactionRetention;
|
|
19
25
|
/**
|
|
20
26
|
* Validate `.compaction()` / `summarizeOldest()` options.
|
|
21
27
|
*
|
|
@@ -15,6 +15,13 @@
|
|
|
15
15
|
*/
|
|
16
16
|
/** Default depth of the "never touch this" recent window. */
|
|
17
17
|
export const DEFAULT_KEEP_RECENT_TURNS = 6;
|
|
18
|
+
/**
|
|
19
|
+
* What happens to folded messages when nobody said. The originals ride with
|
|
20
|
+
* the conversation: losing them has to be a choice somebody typed, not a
|
|
21
|
+
* default they inherited.
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_RETENTION = 'conversation';
|
|
24
|
+
const RETENTIONS = ['conversation', 'discard'];
|
|
18
25
|
function requireObject(options, label, shape) {
|
|
19
26
|
if (options === null || typeof options !== 'object') {
|
|
20
27
|
throw new Error(`${label}: expected an options object (${shape}), got ${typeof options}.`);
|
|
@@ -43,7 +50,7 @@ function requireKeepRecentTurns(keepRecentTurns, label) {
|
|
|
43
50
|
*/
|
|
44
51
|
export function resolveCompactionOptions(options, label) {
|
|
45
52
|
requireObject(options, label, '{ thresholdTokens, summarizer, ... }');
|
|
46
|
-
const { thresholdTokens, summarizer, keepRecentTurns, model } = options;
|
|
53
|
+
const { thresholdTokens, summarizer, keepRecentTurns, model, retain } = options;
|
|
47
54
|
requireThreshold(thresholdTokens, label);
|
|
48
55
|
if (summarizer === null ||
|
|
49
56
|
typeof summarizer !== 'object' ||
|
|
@@ -57,11 +64,20 @@ export function resolveCompactionOptions(options, label) {
|
|
|
57
64
|
if (model !== undefined && (typeof model !== 'string' || model.length === 0)) {
|
|
58
65
|
throw new Error(`${label}: model must be a non-empty model id, got ${String(model)}.`);
|
|
59
66
|
}
|
|
67
|
+
if (retain !== undefined && !RETENTIONS.includes(retain)) {
|
|
68
|
+
throw new Error(`${label}: retain must be ${RETENTIONS.map((r) => `'${r}'`).join(' or ')}, got ` +
|
|
69
|
+
`${String(retain)}. It decides what happens to the messages a fold removes: ` +
|
|
70
|
+
`'conversation' (the default) carries them on the conversation checkpoint so a ` +
|
|
71
|
+
`restart can still produce them, and 'discard' does not. A value this library does ` +
|
|
72
|
+
`not recognise is refused rather than treated as one of them — guessing here would ` +
|
|
73
|
+
`mean guessing whether to keep somebody's transcript.`);
|
|
74
|
+
}
|
|
60
75
|
return {
|
|
61
76
|
thresholdTokens,
|
|
62
77
|
keepRecentTurns: keepRecentTurns ?? DEFAULT_KEEP_RECENT_TURNS,
|
|
63
78
|
summarizer,
|
|
64
79
|
model,
|
|
80
|
+
retain: retain ?? DEFAULT_RETENTION,
|
|
65
81
|
};
|
|
66
82
|
}
|
|
67
83
|
/** Validate `slidingWindow()` options. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAwB,cAAc,CAAC;AAErE,MAAM,UAAU,GAAmC,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAE/E,SAAS,aAAa,CAAC,OAAgB,EAAE,KAAa,EAAE,KAAa;IACnE,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,IAAI,KAA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vC,OAA2B,EAC3B,KAAa;IAEb,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,uCAAuC,CAAC,CAAC;IACvE,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACrD,gBAAgB,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACzC,IAAI,eAAe,KAAK,SAAS;QAAE,sBAAsB,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IAClF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,IAAI,yBAAyB,EAAE,CAAC;AAC5F,CAAC"}
|
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
* This is what `.compaction({...})` configures, and the market's familiar
|
|
11
11
|
* move (Claude Code / the Claude Agent SDK call it compaction). What is
|
|
12
12
|
* different here is not the fold — it is that the fold is filed as a claim:
|
|
13
|
-
* a summary is a claim ABOUT the past, and the past itself stays
|
|
14
|
-
* commit log,
|
|
13
|
+
* a summary is a claim ABOUT the past, and the past itself stays. In the
|
|
14
|
+
* commit log for as long as the process lives, and — since 8.2, under
|
|
15
|
+
* `retain: 'conversation'` — on the conversation checkpoint for as long as
|
|
16
|
+
* the conversation does, which is the half a standing agent actually needs.
|
|
15
17
|
*
|
|
16
18
|
* Everything it decides, it explains. Every engaged path returns a record —
|
|
17
19
|
* including the paths that change nothing, which are the ones a person
|
|
@@ -10,14 +10,17 @@
|
|
|
10
10
|
* This is what `.compaction({...})` configures, and the market's familiar
|
|
11
11
|
* move (Claude Code / the Claude Agent SDK call it compaction). What is
|
|
12
12
|
* different here is not the fold — it is that the fold is filed as a claim:
|
|
13
|
-
* a summary is a claim ABOUT the past, and the past itself stays
|
|
14
|
-
* commit log,
|
|
13
|
+
* a summary is a claim ABOUT the past, and the past itself stays. In the
|
|
14
|
+
* commit log for as long as the process lives, and — since 8.2, under
|
|
15
|
+
* `retain: 'conversation'` — on the conversation checkpoint for as long as
|
|
16
|
+
* the conversation does, which is the half a standing agent actually needs.
|
|
15
17
|
*
|
|
16
18
|
* Everything it decides, it explains. Every engaged path returns a record —
|
|
17
19
|
* including the paths that change nothing, which are the ones a person
|
|
18
20
|
* debugging an over-budget window actually needs.
|
|
19
21
|
*/
|
|
20
22
|
import { CompactionUnmeasurableError } from '../errors.js';
|
|
23
|
+
import { summaryFingerprint } from '../folded.js';
|
|
21
24
|
import { resolveCompactionOptions } from '../options.js';
|
|
22
25
|
import { indexRange } from '../removal.js';
|
|
23
26
|
import { buildSummaryMessage, isCompactedSummary, runSummarizer } from '../summarize.js';
|
|
@@ -122,6 +125,7 @@ export function summarizeOldest(options) {
|
|
|
122
125
|
foldedMessageCount: span.length,
|
|
123
126
|
iteration,
|
|
124
127
|
model,
|
|
128
|
+
retain: config.retain,
|
|
125
129
|
});
|
|
126
130
|
const spend = { model, usage: summary.usage };
|
|
127
131
|
// Would the fold actually help? A summary plus its authored frame can be
|
|
@@ -140,6 +144,24 @@ export function summarizeOldest(options) {
|
|
|
140
144
|
const foldedAtMs = input.now();
|
|
141
145
|
const facts = input.removalFacts(indexRange(spanStart, spanEnd), foldedAtMs);
|
|
142
146
|
const window = [...head, summaryMessage, ...tail];
|
|
147
|
+
// The durable half. It rides the SAME result the window change rides,
|
|
148
|
+
// so the stage commits both together — there is no ordering in which
|
|
149
|
+
// the messages leave and the record of what they were does not follow.
|
|
150
|
+
// Under 'discard' the span is still filed: a discard is an absence, and
|
|
151
|
+
// this family files absences the same way it files claims.
|
|
152
|
+
const foldedSpan = {
|
|
153
|
+
summaryFingerprint: summaryFingerprint(summaryMessage.content),
|
|
154
|
+
runId: input.runId,
|
|
155
|
+
iteration,
|
|
156
|
+
foldedAtMs,
|
|
157
|
+
model,
|
|
158
|
+
messageCount: span.length,
|
|
159
|
+
removedStageIds: facts.removedStageIds,
|
|
160
|
+
retained: config.retain,
|
|
161
|
+
// Detached before it is handed on: `history` came off a live scope and
|
|
162
|
+
// a stored conversation must never hold a reference into the heap.
|
|
163
|
+
...(config.retain === 'conversation' && { messages: span.map((m) => ({ ...m })) }),
|
|
164
|
+
};
|
|
143
165
|
const record = {
|
|
144
166
|
...base,
|
|
145
167
|
removedStageIds: facts.removedStageIds,
|
|
@@ -161,6 +183,7 @@ export function summarizeOldest(options) {
|
|
|
161
183
|
},
|
|
162
184
|
record,
|
|
163
185
|
evictions: facts.evictions,
|
|
186
|
+
folded: [foldedSpan],
|
|
164
187
|
budgetPressure: {
|
|
165
188
|
capTokens: config.thresholdTokens,
|
|
166
189
|
projectedTokens: measured.input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarizeOldest.js","sourceRoot":"","sources":["../../../../../../src/core/agent/window/strategies/summarizeOldest.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"summarizeOldest.js","sourceRoot":"","sources":["../../../../../../src/core/agent/window/strategies/summarizeOldest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,MAAM,MAAM,GAAG,wBAAwB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAEpE,OAAO;QACL,IAAI,EAAE,gBAAgB;QAEtB,KAAK,CAAC,IAAI,CAAC,KAA0B;YACnC,MAAM,EAAE,OAAO,EAAE,KAAK,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ACD,MAAM;gBACN,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,MAAM,EAAE,CAAC,UAAU,CAAC;gBACpB,cAAc,EAAE;oBACd,SAAS,EAAE,MAAM,CAAC,eAAe;oBACjC,eAAe,EAAE,QAAQ,CAAC,KAAK;oBAC/B,UAAU,EAAE,WAAW;iBACxB;gBACD,KAAK;aACN,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
*/
|
|
40
40
|
import type { LLMMessage } from '../../../adapters/types.js';
|
|
41
41
|
import type { Turn, RemovalPlan } from './turns.js';
|
|
42
|
-
import type { WindowRecord } from './types.js';
|
|
42
|
+
import type { FoldedSpan, WindowRecord } from './types.js';
|
|
43
43
|
/** One message leaving the window, with the facts an eviction event needs. */
|
|
44
44
|
export interface WindowEviction {
|
|
45
45
|
/** Index in the PRE-change window — the index the content hash was built on. */
|
|
@@ -76,6 +76,16 @@ export interface WindowStrategyInput {
|
|
|
76
76
|
} | undefined;
|
|
77
77
|
/** The ReAct iteration this decision belongs to. */
|
|
78
78
|
readonly iteration: number;
|
|
79
|
+
/**
|
|
80
|
+
* The run this decision belongs to.
|
|
81
|
+
*
|
|
82
|
+
* A strategy that retains what it removed has to name the run whose commit
|
|
83
|
+
* log held it — that is the honest answer to "where else could I have found
|
|
84
|
+
* this?", and the answer is "nowhere, once that process ended", which is the
|
|
85
|
+
* whole reason retention exists. `'unknown'` when the runtime could not name
|
|
86
|
+
* the run, never a fabricated id.
|
|
87
|
+
*/
|
|
88
|
+
readonly runId: string;
|
|
79
89
|
/** The agent's own model — the sensible default for a strategy that bills. */
|
|
80
90
|
readonly agentModel: string;
|
|
81
91
|
/** `provider.name` of the MAIN provider, for a refusal that names it. */
|
|
@@ -128,6 +138,21 @@ export interface WindowStrategyResult {
|
|
|
128
138
|
readonly record: WindowRecord;
|
|
129
139
|
/** Messages that left the window, for `context.evicted`. */
|
|
130
140
|
readonly evictions: readonly WindowEviction[];
|
|
141
|
+
/**
|
|
142
|
+
* Spans this visit removed, in the form that OUTLIVES the process: appended
|
|
143
|
+
* to the conversation checkpoint, so a restart can still say what a summary
|
|
144
|
+
* stands for — and, under `retain: 'conversation'`, produce it verbatim.
|
|
145
|
+
*
|
|
146
|
+
* OMIT IT unless your strategy replaced messages with something that stands
|
|
147
|
+
* for them. `summarizeOldest` fills it because a summary is a claim that
|
|
148
|
+
* needs its evidence; the drop strategies do not, because a drop replaces
|
|
149
|
+
* nothing and its authored notice claims nothing.
|
|
150
|
+
*
|
|
151
|
+
* The stage writes these in the SAME commit as the window change, so there
|
|
152
|
+
* is no state in which messages left the window and the record of what they
|
|
153
|
+
* were did not follow them.
|
|
154
|
+
*/
|
|
155
|
+
readonly folded?: readonly FoldedSpan[];
|
|
131
156
|
/**
|
|
132
157
|
* The budget reading to report on `agentfootprint.context.budget_pressure`.
|
|
133
158
|
*
|
|
@@ -17,9 +17,15 @@
|
|
|
17
17
|
*
|
|
18
18
|
* The frame is authored. The summary is data. Neither can become
|
|
19
19
|
* the other.
|
|
20
|
+
*
|
|
21
|
+
* A third rule joined them in 8.2: the frame may only claim what is
|
|
22
|
+
* true. It names where the folded messages went, and it reads that
|
|
23
|
+
* from the resolved retention policy rather than asserting a
|
|
24
|
+
* constant — see {@link retentionSentence}.
|
|
20
25
|
* Emits: N/A (the stage emits; this file only builds and calls).
|
|
21
26
|
*/
|
|
22
27
|
import type { LLMMessage, LLMProvider, LLMResponse } from '../../../adapters/types.js';
|
|
28
|
+
import type { CompactionRetention } from './types.js';
|
|
23
29
|
/** Opening of the authored label. Stable — tests and readers match on it. */
|
|
24
30
|
export declare const COMPACTED_FRAME_PREFIX = "[compacted history";
|
|
25
31
|
/**
|
|
@@ -39,11 +45,16 @@ export declare function renderTranscript(messages: readonly LLMMessage[]): strin
|
|
|
39
45
|
* The label is written by this function and always comes first. `summary` is
|
|
40
46
|
* appended to it verbatim: the library never edits model output, and it never
|
|
41
47
|
* lets model output speak in the library's voice either.
|
|
48
|
+
*
|
|
49
|
+
* The label states the retention policy, and states it truthfully — see
|
|
50
|
+
* {@link retentionSentence}. `COMPACTED_FRAME_PREFIX` is unchanged: it is what
|
|
51
|
+
* every reader and every test matches on, and it stays put.
|
|
42
52
|
*/
|
|
43
53
|
export declare function buildSummaryMessage(summary: string, facts: {
|
|
44
54
|
readonly foldedMessageCount: number;
|
|
45
55
|
readonly iteration: number;
|
|
46
56
|
readonly model: string;
|
|
57
|
+
readonly retain: CompactionRetention;
|
|
47
58
|
}): LLMMessage;
|
|
48
59
|
/** True when this message is a frame a previous fold wrote. */
|
|
49
60
|
export declare function isCompactedSummary(msg: LLMMessage | undefined): boolean;
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
*
|
|
18
18
|
* The frame is authored. The summary is data. Neither can become
|
|
19
19
|
* the other.
|
|
20
|
+
*
|
|
21
|
+
* A third rule joined them in 8.2: the frame may only claim what is
|
|
22
|
+
* true. It names where the folded messages went, and it reads that
|
|
23
|
+
* from the resolved retention policy rather than asserting a
|
|
24
|
+
* constant — see {@link retentionSentence}.
|
|
20
25
|
* Emits: N/A (the stage emits; this file only builds and calls).
|
|
21
26
|
*/
|
|
22
27
|
/** Opening of the authored label. Stable — tests and readers match on it. */
|
|
@@ -56,6 +61,23 @@ function renderMessage(msg) {
|
|
|
56
61
|
export function renderTranscript(messages) {
|
|
57
62
|
return [TRANSCRIPT_OPEN, ...messages.map(renderMessage), TRANSCRIPT_CLOSE].join('\n');
|
|
58
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Where the folded messages went, said in the frame itself.
|
|
66
|
+
*
|
|
67
|
+
* Through 8.1 this sentence was a constant: *"The folded messages are retained
|
|
68
|
+
* verbatim in this run's commit log."* True inside the process, and false the
|
|
69
|
+
* moment the run ended — which is exactly when a standing agent reads it back
|
|
70
|
+
* out of storage. A library asserting something false inside the model's own
|
|
71
|
+
* context is worse than saying nothing, so the sentence is now written FROM
|
|
72
|
+
* the resolved retention policy and can only say what actually happened.
|
|
73
|
+
*/
|
|
74
|
+
function retentionSentence(retain) {
|
|
75
|
+
return retain === 'conversation'
|
|
76
|
+
? `The folded messages are retained verbatim with this conversation and can be produced ` +
|
|
77
|
+
`on request.`
|
|
78
|
+
: `The folded messages were not retained beyond the run that folded them; only this ` +
|
|
79
|
+
`summary carries them forward.`;
|
|
80
|
+
}
|
|
59
81
|
/**
|
|
60
82
|
* Build the message that replaces the folded span IN THE WINDOW.
|
|
61
83
|
*
|
|
@@ -65,12 +87,16 @@ export function renderTranscript(messages) {
|
|
|
65
87
|
* The label is written by this function and always comes first. `summary` is
|
|
66
88
|
* appended to it verbatim: the library never edits model output, and it never
|
|
67
89
|
* lets model output speak in the library's voice either.
|
|
90
|
+
*
|
|
91
|
+
* The label states the retention policy, and states it truthfully — see
|
|
92
|
+
* {@link retentionSentence}. `COMPACTED_FRAME_PREFIX` is unchanged: it is what
|
|
93
|
+
* every reader and every test matches on, and it stays put.
|
|
68
94
|
*/
|
|
69
95
|
export function buildSummaryMessage(summary, facts) {
|
|
70
96
|
const label = `${COMPACTED_FRAME_PREFIX} — ${facts.foldedMessageCount} earlier message(s) were folded ` +
|
|
71
97
|
`out of this window at iteration ${facts.iteration}. The text after this line is a SUMMARY ` +
|
|
72
98
|
`written by ${facts.model}; it is a claim about the conversation, not the conversation. ` +
|
|
73
|
-
|
|
99
|
+
`${retentionSentence(facts.retain)}]`;
|
|
74
100
|
return { role: 'user', content: `${label}\n\n${summary}` };
|
|
75
101
|
}
|
|
76
102
|
/** True when this message is a frame a previous fold wrote. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/summarize.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/summarize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAKH,6EAA6E;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