@anvia/core 1.4.0 → 1.5.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/README.md +29 -6
- package/dist/agent/agent.js +7 -7
- package/dist/agent/index.d.ts +5 -5
- package/dist/agent/index.js +10 -10
- package/dist/agent/resolve-options.js +2 -2
- package/dist/agent/resolved-agent.js +8 -8
- package/dist/agent/team/agent-team.js +10 -10
- package/dist/agent/team/index.js +10 -10
- package/dist/{agent-D3iyrJQb.d.ts → agent-BUc18r6A.d.ts} +6 -2
- package/dist/{chunk-APKCA2LY.js → chunk-35GMQS3R.js} +3 -3
- package/dist/{chunk-U5AJS7KM.js → chunk-AYN34XVW.js} +5 -5
- package/dist/{chunk-ZGDUEOSH.js → chunk-DXW37JLZ.js} +4 -4
- package/dist/{chunk-GE46NHN4.js → chunk-FGOVEUVK.js} +37 -27
- package/dist/chunk-FGOVEUVK.js.map +1 -0
- package/dist/{chunk-HSWH3ZLP.js → chunk-I7YCEQXT.js} +3 -3
- package/dist/{chunk-6RVQ3C64.js → chunk-MTJDYC6T.js} +3 -3
- package/dist/{chunk-PXX3ITNH.js → chunk-UEUSJ3UQ.js} +4 -4
- package/dist/{chunk-IHAURFIO.js → chunk-UYODZ7OE.js} +2 -2
- package/dist/{chunk-K4IBS7VB.js → chunk-WLUWRBQ4.js} +22 -8
- package/dist/chunk-WLUWRBQ4.js.map +1 -0
- package/dist/evals/index.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +11 -11
- package/dist/internal/agent-runtime/agent-run.js +4 -4
- package/dist/internal/agent-runtime/memory.js +1 -1
- package/dist/internal/agent.d.ts +3 -3
- package/dist/internal/agent.js +8 -8
- package/dist/internal/team-runtime/run.js +9 -9
- package/dist/memory/index.d.ts +2 -2
- package/dist/memory/index.js +1 -1
- package/dist/memory/options.js +1 -1
- package/dist/{middleware-DORuwSy-.d.ts → middleware-BxzML2hK.d.ts} +1 -1
- package/dist/observability/index.d.ts +2 -2
- package/dist/pipeline/index.d.ts +3 -3
- package/dist/pipeline/index.js +2 -2
- package/dist/pipeline/pipeline.js +2 -2
- package/dist/tool/index.d.ts +2 -2
- package/dist/{types-DhWxTobb.d.ts → types-B8KBVXuH.d.ts} +20 -5
- package/package.json +1 -1
- package/dist/chunk-GE46NHN4.js.map +0 -1
- package/dist/chunk-K4IBS7VB.js.map +0 -1
- /package/dist/{chunk-APKCA2LY.js.map → chunk-35GMQS3R.js.map} +0 -0
- /package/dist/{chunk-U5AJS7KM.js.map → chunk-AYN34XVW.js.map} +0 -0
- /package/dist/{chunk-ZGDUEOSH.js.map → chunk-DXW37JLZ.js.map} +0 -0
- /package/dist/{chunk-HSWH3ZLP.js.map → chunk-I7YCEQXT.js.map} +0 -0
- /package/dist/{chunk-6RVQ3C64.js.map → chunk-MTJDYC6T.js.map} +0 -0
- /package/dist/{chunk-PXX3ITNH.js.map → chunk-UEUSJ3UQ.js.map} +0 -0
- /package/dist/{chunk-IHAURFIO.js.map → chunk-UYODZ7OE.js.map} +0 -0
package/README.md
CHANGED
|
@@ -660,7 +660,7 @@ const agent = new Agent({
|
|
|
660
660
|
savePolicy: "message",
|
|
661
661
|
compaction: {
|
|
662
662
|
trigger: { afterTokens: 32_000 },
|
|
663
|
-
retention: {
|
|
663
|
+
retention: { recentTurns: 4 },
|
|
664
664
|
compactor,
|
|
665
665
|
conflictRetries: false,
|
|
666
666
|
},
|
|
@@ -679,10 +679,25 @@ for await (const event of agent.stream({ prompt: "What did we decide?", session
|
|
|
679
679
|
}
|
|
680
680
|
```
|
|
681
681
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
682
|
+
### Retention API design
|
|
683
|
+
|
|
684
|
+
- **Public option:** `retention: { recentTurns: N }`.
|
|
685
|
+
- **Counting unit:** a user-led turn, not an individual message. Each `user` message starts a turn;
|
|
686
|
+
every following `assistant`, `tool`, or `system` message belongs to it until the next `user`
|
|
687
|
+
message. Tool calls and results therefore cannot be split at the compaction boundary.
|
|
688
|
+
- **Default:** omitting `retention` resolves to `{ recentTurns: 1 }`.
|
|
689
|
+
- **Validation:** `N` must be a nonnegative safe integer. Fractions, negative values, infinity, and
|
|
690
|
+
specifying both retention modes are rejected.
|
|
691
|
+
- **Boundaries:** exactly the last `N` complete stored turns remain unsummarized. `N = 0` summarizes
|
|
692
|
+
the whole stored transcript when it contains a user-led turn. If at most `N` turns exist,
|
|
693
|
+
compaction is a no-op.
|
|
694
|
+
- **Leading messages:** messages before the first `user` do not count as a turn. When older turns
|
|
695
|
+
are summarized, this leading prefix is summarized with them.
|
|
696
|
+
- **Trigger interaction:** the stored transcript plus incoming user message is compared with
|
|
697
|
+
`afterTokens`, but the incoming message is not part of the stored-turn retention count.
|
|
698
|
+
`afterTokens` remains only the automatic trigger threshold and does not cap retained turns.
|
|
699
|
+
- **Compatibility:** deprecated `{ recentTokens: N }` remains supported with its previous
|
|
700
|
+
whole-turn semantics. It is mutually exclusive with `recentTurns`.
|
|
686
701
|
|
|
687
702
|
The built-in token counter is a lightweight provider-neutral estimate. Pass `tokenCounter` when you
|
|
688
703
|
have a model-specific tokenizer or counting service. A custom counter may be async, can be called
|
|
@@ -691,12 +706,20 @@ multiple times, and must return deterministic, monotonic, nonnegative safe integ
|
|
|
691
706
|
```ts
|
|
692
707
|
compaction: {
|
|
693
708
|
trigger: { afterTokens: 32_000 },
|
|
694
|
-
retention: {
|
|
709
|
+
retention: { recentTurns: 4 },
|
|
695
710
|
tokenCounter: (messages) => tokenizer.count(messages),
|
|
696
711
|
compactor,
|
|
697
712
|
}
|
|
698
713
|
```
|
|
699
714
|
|
|
715
|
+
For migration, the deprecated `retention: { recentTokens: N }` form remains supported with its
|
|
716
|
+
previous semantics: it keeps as many complete recent user-led turns as fit the token budget and
|
|
717
|
+
always keeps the newest turn. `recentTokens` must be positive and less than `afterTokens`.
|
|
718
|
+
`recentTurns` and `recentTokens` are mutually exclusive; use `recentTurns` for deterministic
|
|
719
|
+
count-based retention. Omitting `retention` previously used
|
|
720
|
+
`Math.floor(afterTokens / 4)` as a token budget and now retains one turn. To preserve the old
|
|
721
|
+
implicit behavior during migration, set that value explicitly as `recentTokens`.
|
|
722
|
+
|
|
700
723
|
You can force the configured policy without starting an Agent run. The result makes a no-op
|
|
701
724
|
explicit rather than throwing:
|
|
702
725
|
|
package/dist/agent/agent.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-UEUSJ3UQ.js";
|
|
4
|
+
import "../chunk-AYN34XVW.js";
|
|
5
5
|
import "../chunk-B57NNDEF.js";
|
|
6
6
|
import "../chunk-LAIATEUB.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-FGOVEUVK.js";
|
|
8
8
|
import "../chunk-GDY2Z2SZ.js";
|
|
9
9
|
import "../chunk-KITX3HDN.js";
|
|
10
10
|
import "../chunk-NPJ2T3L5.js";
|
|
@@ -19,10 +19,10 @@ import "../chunk-T3ZOZEAB.js";
|
|
|
19
19
|
import "../chunk-6E6ABRJ6.js";
|
|
20
20
|
import "../chunk-YNA3UR42.js";
|
|
21
21
|
import "../chunk-H3H74RWJ.js";
|
|
22
|
-
import "../chunk-E44DRLUL.js";
|
|
23
|
-
import "../chunk-LQJ4KHMY.js";
|
|
24
22
|
import "../chunk-MJCMKZFP.js";
|
|
25
23
|
import "../chunk-EZR5AV3J.js";
|
|
24
|
+
import "../chunk-E44DRLUL.js";
|
|
25
|
+
import "../chunk-LQJ4KHMY.js";
|
|
26
26
|
import "../chunk-OJF67RNM.js";
|
|
27
27
|
import "../chunk-FAPIZJS2.js";
|
|
28
28
|
import "../chunk-7LBPRXZP.js";
|
|
@@ -34,8 +34,8 @@ import "../chunk-NF6WBPFG.js";
|
|
|
34
34
|
import "../chunk-LBYJPMHC.js";
|
|
35
35
|
import "../chunk-KFAVEL5F.js";
|
|
36
36
|
import "../chunk-GLMYZ6OA.js";
|
|
37
|
-
import "../chunk-
|
|
38
|
-
import "../chunk-
|
|
37
|
+
import "../chunk-UYODZ7OE.js";
|
|
38
|
+
import "../chunk-WLUWRBQ4.js";
|
|
39
39
|
import "../chunk-ZPJFXRQZ.js";
|
|
40
40
|
import "../chunk-MEN4AFDZ.js";
|
|
41
41
|
import "../chunk-VZ5ZZBNX.js";
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export { M as ModelCallOptions } from '../model-call-options-CZkSw_xN.js';
|
|
2
2
|
export { R as RetryContext, a as RetryOptions, b as RetrySetting } from '../retry-CjvSlKGW.js';
|
|
3
|
-
import { A as Agent, d as AgentOptions } from '../agent-
|
|
4
|
-
export { a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from '../agent-
|
|
3
|
+
import { A as Agent, d as AgentOptions } from '../agent-BUc18r6A.js';
|
|
4
|
+
export { a as AgentContextInput, b as AgentMemory, c as AgentMemoryOptions, e as AgentToolInput, f as AgentToolOptions, C as CreateHybridVectorContextOptions, g as CreateVectorContextOptions, V as VectorContext, h as VectorContextBaseOptions, i as createVectorContext, j as isVectorContext } from '../agent-BUc18r6A.js';
|
|
5
5
|
import { d as CompletionModel, f as CompletionModelControlsOf, M as Message, U as Usage, c as CompletionFinishReason } from '../types-DYqZKDA8.js';
|
|
6
6
|
import { AgentInteractionRequest, AgentInteractionResponse } from './interactions/index.js';
|
|
7
|
-
import { p as AgentRunSettings, m as AgentPrompt, n as AgentResponse, A as AgentBlockedOutcome, v as AgentStreamEvent, r as AgentSteerInput, s as AgentSteerReceipt, g as AgentInteractionOutcome } from '../middleware-
|
|
8
|
-
export { a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, h as AgentLifecycle, i as AgentMemoryCompactionEvent, j as AgentMemoryCompactionOptions, l as AgentOutcome, o as AgentRunOptions, q as AgentStartEvent, t as AgentStepFinishEvent, u as AgentStream, w as AgentToolCallDeltaEvent, x as AgentToolFinishEvent, y as AgentToolStartEvent } from '../middleware-
|
|
7
|
+
import { p as AgentRunSettings, m as AgentPrompt, n as AgentResponse, A as AgentBlockedOutcome, v as AgentStreamEvent, r as AgentSteerInput, s as AgentSteerReceipt, g as AgentInteractionOutcome } from '../middleware-BxzML2hK.js';
|
|
8
|
+
export { a as AgentChildStreamEvent, b as AgentDeltaEvent, c as AgentErrorEvent, d as AgentErrorStreamEvent, e as AgentFinishEvent, f as AgentInput, h as AgentLifecycle, i as AgentMemoryCompactionEvent, j as AgentMemoryCompactionOptions, l as AgentOutcome, o as AgentRunOptions, q as AgentStartEvent, t as AgentStepFinishEvent, u as AgentStream, w as AgentToolCallDeltaEvent, x as AgentToolFinishEvent, y as AgentToolStartEvent } from '../middleware-BxzML2hK.js';
|
|
9
9
|
import '../types-CqiX-4_C.js';
|
|
10
10
|
import '../types-0t3BczrD.js';
|
|
11
11
|
import '../tool-D_jV3cRZ.js';
|
|
12
|
-
import '../types-
|
|
12
|
+
import '../types-B8KBVXuH.js';
|
|
13
13
|
import '../zod-schema-C7F4clpm.js';
|
|
14
14
|
import 'zod';
|
|
15
15
|
import '../types-Cu2tEf3V.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../chunk-53TPAXYR.js";
|
|
2
2
|
import {
|
|
3
3
|
AgentTeam
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-35GMQS3R.js";
|
|
5
5
|
import "../chunk-X6WS3XWL.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-I7YCEQXT.js";
|
|
7
7
|
import "../chunk-PIMD4DYG.js";
|
|
8
8
|
import "../chunk-FSBDE6RF.js";
|
|
9
9
|
import "../chunk-3TAQXJBC.js";
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
AgentTeamInteractionError,
|
|
13
13
|
AgentTeamLimitError
|
|
14
14
|
} from "../chunk-ENZ2XX27.js";
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-MTJDYC6T.js";
|
|
16
16
|
import {
|
|
17
17
|
Agent
|
|
18
|
-
} from "../chunk-
|
|
19
|
-
import "../chunk-
|
|
18
|
+
} from "../chunk-UEUSJ3UQ.js";
|
|
19
|
+
import "../chunk-AYN34XVW.js";
|
|
20
20
|
import "../chunk-B57NNDEF.js";
|
|
21
21
|
import "../chunk-LAIATEUB.js";
|
|
22
|
-
import "../chunk-
|
|
22
|
+
import "../chunk-FGOVEUVK.js";
|
|
23
23
|
import "../chunk-GDY2Z2SZ.js";
|
|
24
24
|
import "../chunk-KITX3HDN.js";
|
|
25
25
|
import "../chunk-NPJ2T3L5.js";
|
|
@@ -34,10 +34,10 @@ import "../chunk-T3ZOZEAB.js";
|
|
|
34
34
|
import "../chunk-6E6ABRJ6.js";
|
|
35
35
|
import "../chunk-YNA3UR42.js";
|
|
36
36
|
import "../chunk-H3H74RWJ.js";
|
|
37
|
-
import "../chunk-E44DRLUL.js";
|
|
38
|
-
import "../chunk-LQJ4KHMY.js";
|
|
39
37
|
import "../chunk-MJCMKZFP.js";
|
|
40
38
|
import "../chunk-EZR5AV3J.js";
|
|
39
|
+
import "../chunk-E44DRLUL.js";
|
|
40
|
+
import "../chunk-LQJ4KHMY.js";
|
|
41
41
|
import "../chunk-OJF67RNM.js";
|
|
42
42
|
import "../chunk-FAPIZJS2.js";
|
|
43
43
|
import "../chunk-7LBPRXZP.js";
|
|
@@ -49,8 +49,8 @@ import "../chunk-NF6WBPFG.js";
|
|
|
49
49
|
import "../chunk-LBYJPMHC.js";
|
|
50
50
|
import "../chunk-KFAVEL5F.js";
|
|
51
51
|
import "../chunk-GLMYZ6OA.js";
|
|
52
|
-
import "../chunk-
|
|
53
|
-
import "../chunk-
|
|
52
|
+
import "../chunk-UYODZ7OE.js";
|
|
53
|
+
import "../chunk-WLUWRBQ4.js";
|
|
54
54
|
import "../chunk-ZPJFXRQZ.js";
|
|
55
55
|
import "../chunk-MEN4AFDZ.js";
|
|
56
56
|
import "../chunk-VZ5ZZBNX.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
markResolvedAgentOptions,
|
|
3
3
|
resolveAgentOptions
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-UYODZ7OE.js";
|
|
5
|
+
import "../chunk-WLUWRBQ4.js";
|
|
6
6
|
import "../chunk-ZPJFXRQZ.js";
|
|
7
7
|
import "../chunk-MEN4AFDZ.js";
|
|
8
8
|
import "../chunk-VZ5ZZBNX.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createResolvedAgent,
|
|
3
3
|
getResolvedAgentOptions
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-MTJDYC6T.js";
|
|
5
|
+
import "../chunk-UEUSJ3UQ.js";
|
|
6
|
+
import "../chunk-AYN34XVW.js";
|
|
7
7
|
import "../chunk-B57NNDEF.js";
|
|
8
8
|
import "../chunk-LAIATEUB.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-FGOVEUVK.js";
|
|
10
10
|
import "../chunk-GDY2Z2SZ.js";
|
|
11
11
|
import "../chunk-KITX3HDN.js";
|
|
12
12
|
import "../chunk-NPJ2T3L5.js";
|
|
@@ -21,10 +21,10 @@ import "../chunk-T3ZOZEAB.js";
|
|
|
21
21
|
import "../chunk-6E6ABRJ6.js";
|
|
22
22
|
import "../chunk-YNA3UR42.js";
|
|
23
23
|
import "../chunk-H3H74RWJ.js";
|
|
24
|
-
import "../chunk-E44DRLUL.js";
|
|
25
|
-
import "../chunk-LQJ4KHMY.js";
|
|
26
24
|
import "../chunk-MJCMKZFP.js";
|
|
27
25
|
import "../chunk-EZR5AV3J.js";
|
|
26
|
+
import "../chunk-E44DRLUL.js";
|
|
27
|
+
import "../chunk-LQJ4KHMY.js";
|
|
28
28
|
import "../chunk-OJF67RNM.js";
|
|
29
29
|
import "../chunk-FAPIZJS2.js";
|
|
30
30
|
import "../chunk-7LBPRXZP.js";
|
|
@@ -36,8 +36,8 @@ import "../chunk-NF6WBPFG.js";
|
|
|
36
36
|
import "../chunk-LBYJPMHC.js";
|
|
37
37
|
import "../chunk-KFAVEL5F.js";
|
|
38
38
|
import "../chunk-GLMYZ6OA.js";
|
|
39
|
-
import "../chunk-
|
|
40
|
-
import "../chunk-
|
|
39
|
+
import "../chunk-UYODZ7OE.js";
|
|
40
|
+
import "../chunk-WLUWRBQ4.js";
|
|
41
41
|
import "../chunk-ZPJFXRQZ.js";
|
|
42
42
|
import "../chunk-MEN4AFDZ.js";
|
|
43
43
|
import "../chunk-VZ5ZZBNX.js";
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentTeam
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-35GMQS3R.js";
|
|
4
4
|
import "../../chunk-X6WS3XWL.js";
|
|
5
|
-
import "../../chunk-
|
|
5
|
+
import "../../chunk-I7YCEQXT.js";
|
|
6
6
|
import "../../chunk-PIMD4DYG.js";
|
|
7
7
|
import "../../chunk-FSBDE6RF.js";
|
|
8
8
|
import "../../chunk-3TAQXJBC.js";
|
|
9
9
|
import "../../chunk-CJKGTEN4.js";
|
|
10
10
|
import "../../chunk-ENZ2XX27.js";
|
|
11
|
-
import "../../chunk-
|
|
12
|
-
import "../../chunk-
|
|
13
|
-
import "../../chunk-
|
|
11
|
+
import "../../chunk-MTJDYC6T.js";
|
|
12
|
+
import "../../chunk-UEUSJ3UQ.js";
|
|
13
|
+
import "../../chunk-AYN34XVW.js";
|
|
14
14
|
import "../../chunk-B57NNDEF.js";
|
|
15
15
|
import "../../chunk-LAIATEUB.js";
|
|
16
|
-
import "../../chunk-
|
|
16
|
+
import "../../chunk-FGOVEUVK.js";
|
|
17
17
|
import "../../chunk-GDY2Z2SZ.js";
|
|
18
18
|
import "../../chunk-KITX3HDN.js";
|
|
19
19
|
import "../../chunk-NPJ2T3L5.js";
|
|
@@ -28,10 +28,10 @@ import "../../chunk-T3ZOZEAB.js";
|
|
|
28
28
|
import "../../chunk-6E6ABRJ6.js";
|
|
29
29
|
import "../../chunk-YNA3UR42.js";
|
|
30
30
|
import "../../chunk-H3H74RWJ.js";
|
|
31
|
-
import "../../chunk-E44DRLUL.js";
|
|
32
|
-
import "../../chunk-LQJ4KHMY.js";
|
|
33
31
|
import "../../chunk-MJCMKZFP.js";
|
|
34
32
|
import "../../chunk-EZR5AV3J.js";
|
|
33
|
+
import "../../chunk-E44DRLUL.js";
|
|
34
|
+
import "../../chunk-LQJ4KHMY.js";
|
|
35
35
|
import "../../chunk-OJF67RNM.js";
|
|
36
36
|
import "../../chunk-FAPIZJS2.js";
|
|
37
37
|
import "../../chunk-7LBPRXZP.js";
|
|
@@ -43,8 +43,8 @@ import "../../chunk-NF6WBPFG.js";
|
|
|
43
43
|
import "../../chunk-LBYJPMHC.js";
|
|
44
44
|
import "../../chunk-KFAVEL5F.js";
|
|
45
45
|
import "../../chunk-GLMYZ6OA.js";
|
|
46
|
-
import "../../chunk-
|
|
47
|
-
import "../../chunk-
|
|
46
|
+
import "../../chunk-UYODZ7OE.js";
|
|
47
|
+
import "../../chunk-WLUWRBQ4.js";
|
|
48
48
|
import "../../chunk-ZPJFXRQZ.js";
|
|
49
49
|
import "../../chunk-MEN4AFDZ.js";
|
|
50
50
|
import "../../chunk-VZ5ZZBNX.js";
|
package/dist/agent/team/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../../chunk-53TPAXYR.js";
|
|
2
2
|
import {
|
|
3
3
|
AgentTeam
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-35GMQS3R.js";
|
|
5
5
|
import "../../chunk-X6WS3XWL.js";
|
|
6
|
-
import "../../chunk-
|
|
6
|
+
import "../../chunk-I7YCEQXT.js";
|
|
7
7
|
import "../../chunk-PIMD4DYG.js";
|
|
8
8
|
import "../../chunk-FSBDE6RF.js";
|
|
9
9
|
import "../../chunk-3TAQXJBC.js";
|
|
@@ -12,12 +12,12 @@ import {
|
|
|
12
12
|
AgentTeamInteractionError,
|
|
13
13
|
AgentTeamLimitError
|
|
14
14
|
} from "../../chunk-ENZ2XX27.js";
|
|
15
|
-
import "../../chunk-
|
|
16
|
-
import "../../chunk-
|
|
17
|
-
import "../../chunk-
|
|
15
|
+
import "../../chunk-MTJDYC6T.js";
|
|
16
|
+
import "../../chunk-UEUSJ3UQ.js";
|
|
17
|
+
import "../../chunk-AYN34XVW.js";
|
|
18
18
|
import "../../chunk-B57NNDEF.js";
|
|
19
19
|
import "../../chunk-LAIATEUB.js";
|
|
20
|
-
import "../../chunk-
|
|
20
|
+
import "../../chunk-FGOVEUVK.js";
|
|
21
21
|
import "../../chunk-GDY2Z2SZ.js";
|
|
22
22
|
import "../../chunk-KITX3HDN.js";
|
|
23
23
|
import "../../chunk-NPJ2T3L5.js";
|
|
@@ -32,10 +32,10 @@ import "../../chunk-T3ZOZEAB.js";
|
|
|
32
32
|
import "../../chunk-6E6ABRJ6.js";
|
|
33
33
|
import "../../chunk-YNA3UR42.js";
|
|
34
34
|
import "../../chunk-H3H74RWJ.js";
|
|
35
|
-
import "../../chunk-E44DRLUL.js";
|
|
36
|
-
import "../../chunk-LQJ4KHMY.js";
|
|
37
35
|
import "../../chunk-MJCMKZFP.js";
|
|
38
36
|
import "../../chunk-EZR5AV3J.js";
|
|
37
|
+
import "../../chunk-E44DRLUL.js";
|
|
38
|
+
import "../../chunk-LQJ4KHMY.js";
|
|
39
39
|
import "../../chunk-OJF67RNM.js";
|
|
40
40
|
import "../../chunk-FAPIZJS2.js";
|
|
41
41
|
import "../../chunk-7LBPRXZP.js";
|
|
@@ -47,8 +47,8 @@ import "../../chunk-NF6WBPFG.js";
|
|
|
47
47
|
import "../../chunk-LBYJPMHC.js";
|
|
48
48
|
import "../../chunk-KFAVEL5F.js";
|
|
49
49
|
import "../../chunk-GLMYZ6OA.js";
|
|
50
|
-
import "../../chunk-
|
|
51
|
-
import "../../chunk-
|
|
50
|
+
import "../../chunk-UYODZ7OE.js";
|
|
51
|
+
import "../../chunk-WLUWRBQ4.js";
|
|
52
52
|
import "../../chunk-ZPJFXRQZ.js";
|
|
53
53
|
import "../../chunk-MEN4AFDZ.js";
|
|
54
54
|
import "../../chunk-VZ5ZZBNX.js";
|
|
@@ -2,8 +2,8 @@ import { b as RetrySetting } from './retry-CjvSlKGW.js';
|
|
|
2
2
|
import { D as Document, d as CompletionModel, P as ProviderTool, J as JsonObject, C as CompletionControlValues, f as CompletionModelControlsOf, z as ToolChoice } from './types-DYqZKDA8.js';
|
|
3
3
|
import { d as GuardrailPolicyInput, c as GuardrailPolicy } from './types-CqiX-4_C.js';
|
|
4
4
|
import { a as McpServer } from './types-0t3BczrD.js';
|
|
5
|
-
import {
|
|
6
|
-
import { h as AgentLifecycle, P as AgentObservabilityOptions, k as AgentMiddleware, o as AgentRunOptions, l as AgentOutcome, p as AgentRunSettings, u as AgentStream, j as AgentMemoryCompactionOptions } from './middleware-
|
|
5
|
+
import { F as MemoryStore, A as MemorySavePolicy, G as MemoryTokenCounter, o as MemoryCompactor, d as MemoryCompactionConflictRetryOptions, z as MemoryOptions, k as MemoryCompactionResult } from './types-B8KBVXuH.js';
|
|
6
|
+
import { h as AgentLifecycle, P as AgentObservabilityOptions, k as AgentMiddleware, o as AgentRunOptions, l as AgentOutcome, p as AgentRunSettings, u as AgentStream, j as AgentMemoryCompactionOptions } from './middleware-BxzML2hK.js';
|
|
7
7
|
import { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
|
|
8
8
|
import { A as AnyTool, T as Tool, c as ToolCallContext, N as NormalizedToolOutput } from './tool-D_jV3cRZ.js';
|
|
9
9
|
import { AgentContinuation, AgentInteractionResponse } from './agent/interactions/index.js';
|
|
@@ -78,7 +78,11 @@ type AgentMemory = {
|
|
|
78
78
|
afterTokens: number;
|
|
79
79
|
};
|
|
80
80
|
retention: {
|
|
81
|
+
recentTurns: number;
|
|
82
|
+
recentTokens?: undefined;
|
|
83
|
+
} | {
|
|
81
84
|
recentTokens: number;
|
|
85
|
+
recentTurns?: undefined;
|
|
82
86
|
};
|
|
83
87
|
tokenCounter: MemoryTokenCounter;
|
|
84
88
|
compactor: MemoryCompactor;
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
} from "./chunk-X6WS3XWL.js";
|
|
4
4
|
import {
|
|
5
5
|
TeamRun
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-I7YCEQXT.js";
|
|
7
7
|
import {
|
|
8
8
|
TeamStream
|
|
9
9
|
} from "./chunk-3TAQXJBC.js";
|
|
10
10
|
import {
|
|
11
11
|
Agent
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-UEUSJ3UQ.js";
|
|
13
13
|
import {
|
|
14
14
|
assertPositiveSafeInteger
|
|
15
15
|
} from "./chunk-NPJ2T3L5.js";
|
|
@@ -104,4 +104,4 @@ var AgentTeam = class {
|
|
|
104
104
|
export {
|
|
105
105
|
AgentTeam
|
|
106
106
|
};
|
|
107
|
-
//# sourceMappingURL=chunk-
|
|
107
|
+
//# sourceMappingURL=chunk-35GMQS3R.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-LAIATEUB.js";
|
|
7
7
|
import {
|
|
8
8
|
AgentRunMemory
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-FGOVEUVK.js";
|
|
10
10
|
import {
|
|
11
11
|
fetchContextDocuments,
|
|
12
12
|
fetchToolDefinitions
|
|
@@ -45,15 +45,15 @@ import {
|
|
|
45
45
|
import {
|
|
46
46
|
startAgentRunObservers
|
|
47
47
|
} from "./chunk-YNA3UR42.js";
|
|
48
|
-
import {
|
|
49
|
-
MemoryCompactionError
|
|
50
|
-
} from "./chunk-LQJ4KHMY.js";
|
|
51
48
|
import {
|
|
52
49
|
extractRagText
|
|
53
50
|
} from "./chunk-MJCMKZFP.js";
|
|
54
51
|
import {
|
|
55
52
|
createAsyncQueue
|
|
56
53
|
} from "./chunk-EZR5AV3J.js";
|
|
54
|
+
import {
|
|
55
|
+
MemoryCompactionError
|
|
56
|
+
} from "./chunk-LQJ4KHMY.js";
|
|
57
57
|
import {
|
|
58
58
|
runControl
|
|
59
59
|
} from "./chunk-FAPIZJS2.js";
|
|
@@ -2336,4 +2336,4 @@ function observerRunEnd(outcome) {
|
|
|
2336
2336
|
export {
|
|
2337
2337
|
AgentRun
|
|
2338
2338
|
};
|
|
2339
|
-
//# sourceMappingURL=chunk-
|
|
2339
|
+
//# sourceMappingURL=chunk-AYN34XVW.js.map
|
|
@@ -2,6 +2,9 @@ import {
|
|
|
2
2
|
snapshotPipelineObservability,
|
|
3
3
|
startPipelineRunObservers
|
|
4
4
|
} from "./chunk-ETYB5JO6.js";
|
|
5
|
+
import {
|
|
6
|
+
PipelineAgentSuspensionError
|
|
7
|
+
} from "./chunk-R6722CIU.js";
|
|
5
8
|
import {
|
|
6
9
|
childContext,
|
|
7
10
|
combineAbortSignals,
|
|
@@ -9,9 +12,6 @@ import {
|
|
|
9
12
|
runNode,
|
|
10
13
|
stageContext
|
|
11
14
|
} from "./chunk-EKZRAWBP.js";
|
|
12
|
-
import {
|
|
13
|
-
PipelineAgentSuspensionError
|
|
14
|
-
} from "./chunk-R6722CIU.js";
|
|
15
15
|
import {
|
|
16
16
|
appendComposedGraph,
|
|
17
17
|
appendParallelBranch,
|
|
@@ -372,4 +372,4 @@ function normalizeParallelBranches(branches) {
|
|
|
372
372
|
export {
|
|
373
373
|
Pipeline
|
|
374
374
|
};
|
|
375
|
-
//# sourceMappingURL=chunk-
|
|
375
|
+
//# sourceMappingURL=chunk-DXW37JLZ.js.map
|
|
@@ -162,7 +162,7 @@ var AgentRunMemory = class {
|
|
|
162
162
|
snapshot.messages,
|
|
163
163
|
incomingMessages,
|
|
164
164
|
options.trigger.afterTokens,
|
|
165
|
-
options.retention
|
|
165
|
+
options.retention,
|
|
166
166
|
options.tokenCounter,
|
|
167
167
|
force
|
|
168
168
|
);
|
|
@@ -249,7 +249,7 @@ var AgentRunMemory = class {
|
|
|
249
249
|
throw new MemoryCompactionConflictError(maxAttempts, usage);
|
|
250
250
|
}
|
|
251
251
|
};
|
|
252
|
-
async function selectCompactionPrefix(messages, incomingMessages, afterTokens,
|
|
252
|
+
async function selectCompactionPrefix(messages, incomingMessages, afterTokens, retention, tokenCounter, force) {
|
|
253
253
|
const originalTokenCount = await countTokens(tokenCounter, messages);
|
|
254
254
|
const incomingTokenCount = incomingMessages.length === 0 ? 0 : await countTokens(tokenCounter, incomingMessages);
|
|
255
255
|
const none = {
|
|
@@ -264,31 +264,42 @@ async function selectCompactionPrefix(messages, incomingMessages, afterTokens, r
|
|
|
264
264
|
const userMessageIndexes = messages.flatMap(
|
|
265
265
|
(message, index) => message.role === "user" ? [index] : []
|
|
266
266
|
);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
267
|
+
let compactedMessageCount;
|
|
268
|
+
let retainedTokenCount;
|
|
269
|
+
if (retention.recentTurns !== void 0) {
|
|
270
|
+
if (userMessageIndexes.length <= retention.recentTurns) {
|
|
271
|
+
return none;
|
|
272
|
+
}
|
|
273
|
+
compactedMessageCount = retention.recentTurns === 0 ? messages.length : userMessageIndexes[userMessageIndexes.length - retention.recentTurns] ?? 0;
|
|
274
|
+
retainedTokenCount = await countTokens(tokenCounter, messages.slice(compactedMessageCount));
|
|
275
|
+
} else {
|
|
276
|
+
if (userMessageIndexes.length <= 1) {
|
|
277
|
+
return none;
|
|
278
|
+
}
|
|
279
|
+
const tailTokenCounts = /* @__PURE__ */ new Map();
|
|
280
|
+
const countTail = async (messageIndex) => {
|
|
281
|
+
const cached = tailTokenCounts.get(messageIndex);
|
|
282
|
+
if (cached !== void 0) return cached;
|
|
283
|
+
const count = await countTokens(tokenCounter, messages.slice(messageIndex));
|
|
284
|
+
tailTokenCounts.set(messageIndex, count);
|
|
285
|
+
return count;
|
|
286
|
+
};
|
|
287
|
+
let lower = 0;
|
|
288
|
+
let upper = userMessageIndexes.length - 1;
|
|
289
|
+
let retainedBoundary = upper;
|
|
290
|
+
while (lower <= upper) {
|
|
291
|
+
const middle = Math.floor((lower + upper) / 2);
|
|
292
|
+
const candidate = userMessageIndexes[middle] ?? 0;
|
|
293
|
+
if (await countTail(candidate) <= retention.recentTokens) {
|
|
294
|
+
retainedBoundary = middle;
|
|
295
|
+
upper = middle - 1;
|
|
296
|
+
} else {
|
|
297
|
+
lower = middle + 1;
|
|
298
|
+
}
|
|
289
299
|
}
|
|
300
|
+
compactedMessageCount = userMessageIndexes[retainedBoundary] ?? 0;
|
|
301
|
+
retainedTokenCount = tailTokenCounts.get(compactedMessageCount) ?? await countTokens(tokenCounter, messages.slice(compactedMessageCount));
|
|
290
302
|
}
|
|
291
|
-
const compactedMessageCount = userMessageIndexes[retainedBoundary] ?? 0;
|
|
292
303
|
if (compactedMessageCount === 0) {
|
|
293
304
|
return none;
|
|
294
305
|
}
|
|
@@ -296,7 +307,6 @@ async function selectCompactionPrefix(messages, incomingMessages, afterTokens, r
|
|
|
296
307
|
tokenCounter,
|
|
297
308
|
messages.slice(0, compactedMessageCount)
|
|
298
309
|
);
|
|
299
|
-
const retainedTokenCount = tailTokenCounts.get(compactedMessageCount) ?? await countTokens(tokenCounter, messages.slice(compactedMessageCount));
|
|
300
310
|
return {
|
|
301
311
|
compactedMessageCount,
|
|
302
312
|
originalTokenCount,
|
|
@@ -339,4 +349,4 @@ function isEmptyUsage(usage) {
|
|
|
339
349
|
export {
|
|
340
350
|
AgentRunMemory
|
|
341
351
|
};
|
|
342
|
-
//# sourceMappingURL=chunk-
|
|
352
|
+
//# sourceMappingURL=chunk-FGOVEUVK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/agent-runtime/memory.ts"],"sourcesContent":["import type { Agent } from \"../../agent/agent\";\nimport type { AgentMemory } from \"../../agent/types\";\nimport { type Message as MessageType, Usage } from \"../../completion/index\";\nimport {\n createMemoryCompactionSummary,\n cumulativeCompactedMessageCount,\n} from \"../../memory/compaction\";\nimport { MemoryCompactionConflictError, MemoryCompactionError } from \"../../memory/errors\";\nimport type {\n MemoryCompactionInfo,\n MemoryCompactionResult,\n MemorySavePolicy,\n MemoryScope,\n MemoryTokenCounter,\n} from \"../../memory/types\";\nimport { throwIfAborted } from \"../abort\";\n\nexport type MemoryPreparation = {\n history: MessageType[];\n usage: ReturnType<typeof Usage.empty>;\n compaction?: MemoryCompactionInfo | undefined;\n originalTokenCount?: number | undefined;\n};\n\ntype MemoryAgent = Pick<Agent, \"memory\">;\n\nexport class AgentRunMemory {\n constructor(\n private readonly agent: MemoryAgent,\n private readonly memoryScope: MemoryScope | undefined,\n private readonly initialHistory: MessageType[],\n ) {}\n\n memoryPolicy(): MemorySavePolicy | undefined {\n return this.memory()?.savePolicy;\n }\n\n pendingTurnMessages(newMessages: MessageType[]): MessageType[] {\n return this.memoryPolicy() === \"turn\" ? [...newMessages] : [];\n }\n\n async prepareHistory(\n runId: string,\n incomingMessages: readonly MessageType[],\n abortSignal?: AbortSignal | undefined,\n ): Promise<MemoryPreparation> {\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined) {\n return {\n history: this.initialHistory,\n usage: Usage.empty(),\n };\n }\n\n const preparation = await this.prepareStoredHistory(\n memory,\n runId,\n incomingMessages,\n abortSignal,\n );\n const memoryHistory = preparation.history;\n const chatHistory = [...memoryHistory, ...this.initialHistory];\n return {\n ...preparation,\n history: chatHistory,\n };\n }\n\n async compact(\n runId: string,\n abortSignal?: AbortSignal | undefined,\n ): Promise<MemoryCompactionResult> {\n const memory = this.memory();\n const scope = this.memoryScope;\n if (memory === undefined || scope === undefined) {\n throw new TypeError(\"Manual memory compaction requires an Agent with configured memory.\");\n }\n if (memory.compaction === undefined || memory.store.compaction === undefined) {\n throw new TypeError(\"Manual memory compaction requires a configured compaction policy.\");\n }\n const preparation = await this.prepareStoredHistory(memory, runId, [], abortSignal, true);\n if (preparation.compaction !== undefined) {\n return { type: \"compacted\", ...preparation.compaction };\n }\n return {\n type: \"skipped\",\n reason: \"nothing_to_compact\",\n originalMessageCount: preparation.history.length,\n originalTokenCount:\n preparation.originalTokenCount ??\n (await countTokens(memory.compaction.tokenCounter, preparation.history)),\n };\n }\n\n async commitAcceptedInput(runId: string, messages: MessageType[]): Promise<void> {\n const memory = this.memory();\n if (\n memory === undefined ||\n this.memoryScope === undefined ||\n memory.savePolicy !== \"message\" ||\n messages.length === 0\n ) {\n return;\n }\n\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn: 1,\n messages,\n });\n }\n\n async commitMessages(\n runId: string,\n turn: number,\n messages: MessageType[],\n pendingTurnMessages: MessageType[],\n ): Promise<void> {\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined || messages.length === 0) {\n return;\n }\n if (memory.savePolicy === \"message\") {\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn,\n messages,\n });\n } else if (memory.savePolicy === \"turn\") {\n pendingTurnMessages.push(...messages);\n }\n }\n\n async commitCompletedTurn(\n runId: string,\n turn: number,\n pendingTurnMessages: MessageType[],\n ): Promise<void> {\n const memory = this.memory();\n if (\n memory === undefined ||\n this.memoryScope === undefined ||\n memory.savePolicy !== \"turn\" ||\n pendingTurnMessages.length === 0\n ) {\n return;\n }\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn,\n messages: [...pendingTurnMessages],\n });\n pendingTurnMessages.length = 0;\n }\n\n async commitCompletedRun(\n runId: string,\n turn: number,\n newMessages: MessageType[],\n pendingTurnMessages: MessageType[],\n ): Promise<void> {\n await this.commitCompletedTurn(runId, turn, pendingTurnMessages);\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined || memory.savePolicy !== \"run\") {\n return;\n }\n await memory.store.append({\n scope: this.memoryScope,\n runId,\n turn,\n messages: [...newMessages],\n });\n }\n\n async recordError(runId: string, error: unknown, newMessages: MessageType[]): Promise<void> {\n const memory = this.memory();\n if (memory === undefined || this.memoryScope === undefined) {\n return;\n }\n await memory.store.recordError?.({\n scope: this.memoryScope,\n runId,\n error,\n messages: [...newMessages],\n });\n }\n\n private memory(): AgentMemory | undefined {\n return this.memoryScope === undefined ? undefined : this.agent.memory;\n }\n\n private async prepareStoredHistory(\n memory: AgentMemory,\n runId: string,\n incomingMessages: readonly MessageType[],\n abortSignal?: AbortSignal | undefined,\n force = false,\n ): Promise<MemoryPreparation> {\n const scope = this.memoryScope;\n if (scope === undefined) {\n return { history: [], usage: Usage.empty() };\n }\n const options = memory.compaction;\n const capability = memory.store.compaction;\n if (options === undefined || capability === undefined) {\n return {\n history: await memory.store.load({ scope }),\n usage: Usage.empty(),\n };\n }\n\n let usage = Usage.empty();\n const maxAttempts = options.conflictRetries === false ? 1 : options.conflictRetries.maxAttempts;\n for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {\n throwIfAborted(abortSignal);\n const snapshot = await capability.snapshot({ scope });\n throwIfAborted(abortSignal);\n const selection = await selectCompactionPrefix(\n snapshot.messages,\n incomingMessages,\n options.trigger.afterTokens,\n options.retention,\n options.tokenCounter,\n force,\n );\n throwIfAborted(abortSignal);\n const compactedMessageCount = selection.compactedMessageCount;\n if (compactedMessageCount === 0) {\n return {\n history: snapshot.messages,\n usage,\n originalTokenCount: selection.originalTokenCount,\n };\n }\n\n const prefix = snapshot.messages.slice(0, compactedMessageCount);\n let result: Awaited<ReturnType<typeof options.compactor>>;\n try {\n result = await options.compactor({\n scope,\n messages: prefix,\n abortSignal,\n });\n } catch (error) {\n throw remappedCompactorError(error, usage);\n }\n if (result.usage !== undefined) {\n usage = Usage.add(usage, result.usage);\n }\n if (typeof result?.summary !== \"string\") {\n throw new MemoryCompactionError(\"Memory compactor must return a summary string.\", {\n usage,\n });\n }\n const summaryText = result.summary.trim();\n if (summaryText.length === 0) {\n throw new MemoryCompactionError(\"Memory compactor returned an empty summary.\", {\n usage,\n });\n }\n const summary = createMemoryCompactionSummary(\n summaryText,\n cumulativeCompactedMessageCount(prefix),\n );\n const retained = snapshot.messages.slice(compactedMessageCount);\n let resultTokenCount: number;\n try {\n resultTokenCount = await countTokens(options.tokenCounter, [summary, ...retained]);\n } catch (error) {\n throw remappedCompactorError(error, usage);\n }\n throwIfAborted(abortSignal);\n let replacement: Awaited<ReturnType<typeof capability.replacePrefix>>;\n try {\n replacement = await capability.replacePrefix({\n scope,\n revision: snapshot.revision,\n messageCount: compactedMessageCount,\n replacement: summary,\n runId: `memory-compaction:${runId}:${attempt}`,\n });\n } catch (error) {\n throw new MemoryCompactionError(\"Memory compaction prefix replacement failed.\", {\n cause: error,\n usage,\n });\n }\n if (replacement.status === \"committed\") {\n return {\n history: [summary, ...retained],\n usage,\n compaction: {\n originalMessageCount: snapshot.messages.length,\n compactedMessageCount,\n retainedMessageCount: retained.length,\n originalTokenCount: selection.originalTokenCount,\n compactedTokenCount: selection.compactedTokenCount,\n retainedTokenCount: selection.retainedTokenCount,\n resultTokenCount,\n attempts: attempt,\n usage,\n },\n };\n }\n throwIfAborted(abortSignal);\n }\n\n throw new MemoryCompactionConflictError(maxAttempts, usage);\n }\n}\n\ntype CompactionSelection = {\n compactedMessageCount: number;\n originalTokenCount: number;\n compactedTokenCount: number;\n retainedTokenCount: number;\n};\n\nasync function selectCompactionPrefix(\n messages: readonly MessageType[],\n incomingMessages: readonly MessageType[],\n afterTokens: number,\n retention:\n | { recentTurns: number; recentTokens?: undefined }\n | { recentTokens: number; recentTurns?: undefined },\n tokenCounter: MemoryTokenCounter,\n force: boolean,\n): Promise<CompactionSelection> {\n const originalTokenCount = await countTokens(tokenCounter, messages);\n const incomingTokenCount =\n incomingMessages.length === 0 ? 0 : await countTokens(tokenCounter, incomingMessages);\n const none = {\n compactedMessageCount: 0,\n originalTokenCount,\n compactedTokenCount: 0,\n retainedTokenCount: originalTokenCount,\n };\n if (!force && originalTokenCount + incomingTokenCount <= afterTokens) {\n return none;\n }\n const userMessageIndexes = messages.flatMap((message, index) =>\n message.role === \"user\" ? [index] : [],\n );\n let compactedMessageCount: number;\n let retainedTokenCount: number;\n if (retention.recentTurns !== undefined) {\n if (userMessageIndexes.length <= retention.recentTurns) {\n return none;\n }\n compactedMessageCount =\n retention.recentTurns === 0\n ? messages.length\n : (userMessageIndexes[userMessageIndexes.length - retention.recentTurns] ?? 0);\n retainedTokenCount = await countTokens(tokenCounter, messages.slice(compactedMessageCount));\n } else {\n if (userMessageIndexes.length <= 1) {\n return none;\n }\n\n // Legacy token retention still keeps complete user-led turns. The newest turn is always kept\n // even when it alone exceeds the budget. Find the earliest fitting tail logarithmically.\n const tailTokenCounts = new Map<number, number>();\n const countTail = async (messageIndex: number): Promise<number> => {\n const cached = tailTokenCounts.get(messageIndex);\n if (cached !== undefined) return cached;\n const count = await countTokens(tokenCounter, messages.slice(messageIndex));\n tailTokenCounts.set(messageIndex, count);\n return count;\n };\n let lower = 0;\n let upper = userMessageIndexes.length - 1;\n let retainedBoundary = upper;\n while (lower <= upper) {\n const middle = Math.floor((lower + upper) / 2);\n const candidate = userMessageIndexes[middle] ?? 0;\n if ((await countTail(candidate)) <= retention.recentTokens) {\n retainedBoundary = middle;\n upper = middle - 1;\n } else {\n lower = middle + 1;\n }\n }\n compactedMessageCount = userMessageIndexes[retainedBoundary] ?? 0;\n retainedTokenCount =\n tailTokenCounts.get(compactedMessageCount) ??\n (await countTokens(tokenCounter, messages.slice(compactedMessageCount)));\n }\n if (compactedMessageCount === 0) {\n return none;\n }\n const compactedTokenCount = await countTokens(\n tokenCounter,\n messages.slice(0, compactedMessageCount),\n );\n return {\n compactedMessageCount,\n originalTokenCount,\n compactedTokenCount,\n retainedTokenCount,\n };\n}\n\nasync function countTokens(\n tokenCounter: MemoryTokenCounter,\n messages: readonly MessageType[],\n): Promise<number> {\n let count: number;\n try {\n count = await tokenCounter(messages);\n } catch (error) {\n throw new MemoryCompactionError(\"Memory token counter failed.\", { cause: error });\n }\n if (!Number.isSafeInteger(count) || count < 0) {\n throw new MemoryCompactionError(\"Memory token counter must return a nonnegative safe integer.\");\n }\n return count;\n}\n\nfunction remappedCompactorError(error: unknown, usage: ReturnType<typeof Usage.empty>): Error {\n if (error instanceof MemoryCompactionError) {\n const mergedUsage =\n error.usage === undefined\n ? usage\n : isEmptyUsage(usage)\n ? error.usage\n : Usage.add(usage, error.usage);\n if (mergedUsage === error.usage || (error.usage === undefined && isEmptyUsage(usage))) {\n return error;\n }\n return new MemoryCompactionError(error.message, {\n cause: error,\n usage: mergedUsage,\n });\n }\n return new MemoryCompactionError(\"Memory compactor failed.\", {\n cause: error,\n usage,\n });\n}\n\nfunction isEmptyUsage(usage: ReturnType<typeof Usage.empty>): boolean {\n return (\n usage.inputTokens === 0 &&\n usage.outputTokens === 0 &&\n usage.totalTokens === 0 &&\n usage.cachedInputTokens === 0 &&\n usage.cacheCreationInputTokens === 0\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YACmB,OACA,aACA,gBACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAHgB;AAAA,EACA;AAAA,EACA;AAAA,EAGnB,eAA6C;AAC3C,WAAO,KAAK,OAAO,GAAG;AAAA,EACxB;AAAA,EAEA,oBAAoB,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,SAAS,uBAAuB,OAAgB,OAA8C;AAC5F,MAAI,iBAAiB,uBAAuB;AAC1C,UAAM,cACJ,MAAM,UAAU,SACZ,QACA,aAAa,KAAK,IAChB,MAAM,QACN,MAAM,IAAI,OAAO,MAAM,KAAK;AACpC,QAAI,gBAAgB,MAAM,SAAU,MAAM,UAAU,UAAa,aAAa,KAAK,GAAI;AACrF,aAAO;AAAA,IACT;AACA,WAAO,IAAI,sBAAsB,MAAM,SAAS;AAAA,MAC9C,OAAO;AAAA,MACP,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACA,SAAO,IAAI,sBAAsB,4BAA4B;AAAA,IAC3D,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;AAEA,SAAS,aAAa,OAAgD;AACpE,SACE,MAAM,gBAAgB,KACtB,MAAM,iBAAiB,KACvB,MAAM,gBAAgB,KACtB,MAAM,sBAAsB,KAC5B,MAAM,6BAA6B;AAEvC;","names":[]}
|
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
createResolvedAgent,
|
|
21
21
|
getResolvedAgentOptions
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-MTJDYC6T.js";
|
|
23
23
|
import {
|
|
24
24
|
AgentRun
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-AYN34XVW.js";
|
|
26
26
|
import {
|
|
27
27
|
withInternalAgentRunOptions
|
|
28
28
|
} from "./chunk-KITX3HDN.js";
|
|
@@ -619,4 +619,4 @@ var TeamRun = class {
|
|
|
619
619
|
export {
|
|
620
620
|
TeamRun
|
|
621
621
|
};
|
|
622
|
-
//# sourceMappingURL=chunk-
|
|
622
|
+
//# sourceMappingURL=chunk-I7YCEQXT.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UEUSJ3UQ.js";
|
|
4
4
|
import {
|
|
5
5
|
getAgentToolState
|
|
6
6
|
} from "./chunk-A7BXVZXZ.js";
|
|
7
7
|
import {
|
|
8
8
|
markResolvedAgentOptions
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-UYODZ7OE.js";
|
|
10
10
|
|
|
11
11
|
// src/agent/resolved-agent.ts
|
|
12
12
|
function createResolvedAgent(options) {
|
|
@@ -45,4 +45,4 @@ export {
|
|
|
45
45
|
createResolvedAgent,
|
|
46
46
|
getResolvedAgentOptions
|
|
47
47
|
};
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-MTJDYC6T.js.map
|