@animalabs/agent-framework 0.11.0 → 0.13.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/src/agent.d.ts +11 -1
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +60 -4
- package/dist/src/agent.js.map +1 -1
- package/dist/src/framework.d.ts +72 -1
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +873 -123
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +7 -1
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +15 -1
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/kv-unified-wire.d.ts +16 -0
- package/dist/src/kv-unified-wire.d.ts.map +1 -0
- package/dist/src/kv-unified-wire.js +2 -0
- package/dist/src/kv-unified-wire.js.map +1 -0
- package/dist/src/mcpl/channel-registry.d.ts +84 -1
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +188 -5
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.js +28 -2
- package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
- package/dist/src/mcpl/push-handler.d.ts +6 -1
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +29 -2
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/reference-fetcher.d.ts +59 -0
- package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -0
- package/dist/src/mcpl/reference-fetcher.js +240 -0
- package/dist/src/mcpl/reference-fetcher.js.map +1 -0
- package/dist/src/mcpl/references.d.ts +125 -0
- package/dist/src/mcpl/references.d.ts.map +1 -0
- package/dist/src/mcpl/references.js +262 -0
- package/dist/src/mcpl/references.js.map +1 -0
- package/dist/src/mcpl/types.d.ts +32 -0
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/modules/index.d.ts +2 -1
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js +1 -1
- package/dist/src/modules/index.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +125 -2
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +354 -58
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/types.d.ts +7 -0
- package/dist/src/modules/workspace/types.d.ts.map +1 -1
- package/dist/src/modules/workspace/types.js.map +1 -1
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +14 -0
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/tool-wrapper-prose-guard.d.ts +8 -0
- package/dist/src/tool-wrapper-prose-guard.d.ts.map +1 -0
- package/dist/src/tool-wrapper-prose-guard.js +37 -0
- package/dist/src/tool-wrapper-prose-guard.js.map +1 -0
- package/dist/src/tune-out/coordinator.d.ts +144 -0
- package/dist/src/tune-out/coordinator.d.ts.map +1 -0
- package/dist/src/tune-out/coordinator.js +444 -0
- package/dist/src/tune-out/coordinator.js.map +1 -0
- package/dist/src/tune-out/tools.d.ts +43 -0
- package/dist/src/tune-out/tools.d.ts.map +1 -0
- package/dist/src/tune-out/tools.js +93 -0
- package/dist/src/tune-out/tools.js.map +1 -0
- package/dist/src/types/agent.d.ts +15 -0
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +6 -0
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/usage-accounting.d.ts +5 -0
- package/dist/src/usage-accounting.d.ts.map +1 -0
- package/dist/src/usage-accounting.js +11 -0
- package/dist/src/usage-accounting.js.map +1 -0
- package/dist/test/channel-incoming-targeting.test.d.ts +2 -0
- package/dist/test/channel-incoming-targeting.test.d.ts.map +1 -0
- package/dist/test/channel-incoming-targeting.test.js +81 -0
- package/dist/test/channel-incoming-targeting.test.js.map +1 -0
- package/dist/test/conversation-routing.test.js +39 -0
- package/dist/test/conversation-routing.test.js.map +1 -1
- package/dist/test/kv-unified-wiring.test.d.ts +2 -0
- package/dist/test/kv-unified-wiring.test.d.ts.map +1 -0
- package/dist/test/kv-unified-wiring.test.js +56 -0
- package/dist/test/kv-unified-wiring.test.js.map +1 -0
- package/dist/test/mcpl-push-convert.test.d.ts +2 -0
- package/dist/test/mcpl-push-convert.test.d.ts.map +1 -0
- package/dist/test/mcpl-push-convert.test.js +42 -0
- package/dist/test/mcpl-push-convert.test.js.map +1 -0
- package/dist/test/mcpl-reference-fetcher.test.d.ts +2 -0
- package/dist/test/mcpl-reference-fetcher.test.d.ts.map +1 -0
- package/dist/test/mcpl-reference-fetcher.test.js +199 -0
- package/dist/test/mcpl-reference-fetcher.test.js.map +1 -0
- package/dist/test/per-agent-delivery.test.d.ts +2 -0
- package/dist/test/per-agent-delivery.test.d.ts.map +1 -0
- package/dist/test/per-agent-delivery.test.js +108 -0
- package/dist/test/per-agent-delivery.test.js.map +1 -0
- package/dist/test/present-while-acting.test.js +64 -0
- package/dist/test/present-while-acting.test.js.map +1 -1
- package/dist/test/tool-result-history.test.js +78 -0
- package/dist/test/tool-result-history.test.js.map +1 -1
- package/dist/test/tool-wrapper-prose-guard-integration.test.d.ts +2 -0
- package/dist/test/tool-wrapper-prose-guard-integration.test.d.ts.map +1 -0
- package/dist/test/tool-wrapper-prose-guard-integration.test.js +485 -0
- package/dist/test/tool-wrapper-prose-guard-integration.test.js.map +1 -0
- package/dist/test/tool-wrapper-prose-guard.test.d.ts +2 -0
- package/dist/test/tool-wrapper-prose-guard.test.d.ts.map +1 -0
- package/dist/test/tool-wrapper-prose-guard.test.js +34 -0
- package/dist/test/tool-wrapper-prose-guard.test.js.map +1 -0
- package/dist/test/tune-out-e2e.test.d.ts +2 -0
- package/dist/test/tune-out-e2e.test.d.ts.map +1 -0
- package/dist/test/tune-out-e2e.test.js +142 -0
- package/dist/test/tune-out-e2e.test.js.map +1 -0
- package/dist/test/tune-out-gate-composition.test.d.ts +2 -0
- package/dist/test/tune-out-gate-composition.test.d.ts.map +1 -0
- package/dist/test/tune-out-gate-composition.test.js +221 -0
- package/dist/test/tune-out-gate-composition.test.js.map +1 -0
- package/dist/test/tune-out-lifecycle.test.d.ts +2 -0
- package/dist/test/tune-out-lifecycle.test.d.ts.map +1 -0
- package/dist/test/tune-out-lifecycle.test.js +121 -0
- package/dist/test/tune-out-lifecycle.test.js.map +1 -0
- package/dist/test/turn-trigger-provenance.test.d.ts +2 -0
- package/dist/test/turn-trigger-provenance.test.d.ts.map +1 -0
- package/dist/test/turn-trigger-provenance.test.js +85 -0
- package/dist/test/turn-trigger-provenance.test.js.map +1 -0
- package/dist/test/usage-accounting.test.d.ts +2 -0
- package/dist/test/usage-accounting.test.d.ts.map +1 -0
- package/dist/test/usage-accounting.test.js +13 -0
- package/dist/test/usage-accounting.test.js.map +1 -0
- package/dist/test/workspace-branch-continuation.test.d.ts +15 -0
- package/dist/test/workspace-branch-continuation.test.d.ts.map +1 -0
- package/dist/test/workspace-branch-continuation.test.js +183 -0
- package/dist/test/workspace-branch-continuation.test.js.map +1 -0
- package/dist/test/workspace-read-file-from-disk.test.d.ts +17 -0
- package/dist/test/workspace-read-file-from-disk.test.d.ts.map +1 -0
- package/dist/test/workspace-read-file-from-disk.test.js +174 -0
- package/dist/test/workspace-read-file-from-disk.test.js.map +1 -0
- package/dist/test/workspace-read-image.test.js +8 -0
- package/dist/test/workspace-read-image.test.js.map +1 -1
- package/dist/test/workspace-restore-order.test.js +1 -1
- package/dist/test/workspace-restore-order.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/agent.ts +77 -4
- package/src/framework.ts +953 -128
- package/src/gate/event-gate.ts +28 -3
- package/src/kv-unified-wire.ts +12 -0
- package/src/mcpl/channel-registry.ts +264 -8
- package/src/mcpl/hook-orchestrator.ts +29 -2
- package/src/mcpl/push-handler.ts +30 -2
- package/src/mcpl/reference-fetcher.ts +240 -0
- package/src/mcpl/references.ts +292 -0
- package/src/mcpl/types.ts +29 -0
- package/src/modules/index.ts +2 -1
- package/src/modules/workspace/index.ts +425 -66
- package/src/modules/workspace/types.ts +7 -0
- package/src/tool-result-history.ts +11 -0
- package/src/tool-wrapper-prose-guard.ts +38 -0
- package/src/tune-out/coordinator.ts +548 -0
- package/src/tune-out/tools.ts +129 -0
- package/src/types/agent.ts +16 -0
- package/src/types/framework.ts +7 -0
- package/src/usage-accounting.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animalabs/agent-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Multi-agent framework with pluggable modules, persistent state, and concurrent tool execution",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@animalabs/chronicle": "^0.3.0",
|
|
50
|
-
"@animalabs/context-manager": "^0.
|
|
50
|
+
"@animalabs/context-manager": "^0.8.0",
|
|
51
51
|
"@animalabs/membrane": "^0.5.78",
|
|
52
52
|
"chokidar": "^4.0.3",
|
|
53
53
|
"discord.js": "^14.25.1",
|
package/src/agent.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Membrane, NormalizedMessage, NormalizedRequest, ContentBlock, YieldingStream } from '@animalabs/membrane';
|
|
2
2
|
import { isAbortedResponse } from '@animalabs/membrane';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import type { CacheWireReceipt, KvUnifiedRequestHooks } from './kv-unified-wire.js';
|
|
3
5
|
import {
|
|
4
6
|
toolResultDataToHistoryString,
|
|
5
7
|
truncateForHistory,
|
|
@@ -9,6 +11,8 @@ import {
|
|
|
9
11
|
export interface StartStreamResult {
|
|
10
12
|
stream: YieldingStream;
|
|
11
13
|
request: NormalizedRequest;
|
|
14
|
+
takeKvSubmission?: () => { submissionId: string; wireReceipt: CacheWireReceipt } | undefined;
|
|
15
|
+
drainKvSubmissionIds?: () => string[];
|
|
12
16
|
}
|
|
13
17
|
import type {
|
|
14
18
|
ContextManager,
|
|
@@ -37,6 +41,18 @@ import type {
|
|
|
37
41
|
AgentRuntimeSettingsOverrides,
|
|
38
42
|
} from './types/index.js';
|
|
39
43
|
|
|
44
|
+
function stableHash(value: unknown): string {
|
|
45
|
+
const encode = (item: unknown): string => {
|
|
46
|
+
if (Array.isArray(item)) return `[${item.map(encode).join(',')}]`;
|
|
47
|
+
if (item && typeof item === 'object') {
|
|
48
|
+
const record = item as Record<string, unknown>;
|
|
49
|
+
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${encode(record[key])}`).join(',')}}`;
|
|
50
|
+
}
|
|
51
|
+
return JSON.stringify(item) ?? 'null';
|
|
52
|
+
};
|
|
53
|
+
return createHash('sha256').update(encode(value)).digest('hex');
|
|
54
|
+
}
|
|
55
|
+
|
|
40
56
|
const DEFAULT_CONTEXT_BUDGET_TOKENS = 100_000;
|
|
41
57
|
const DEFAULT_TRANSITION_PACE_TOKENS = 16_000;
|
|
42
58
|
const DEFAULT_SAME_ROUND_THINK_TEXT_POLICY: SameRoundThinkTextPolicy = 'public';
|
|
@@ -68,6 +84,8 @@ export class Agent {
|
|
|
68
84
|
readonly refusalHandling: AgentConfig['refusalHandling'];
|
|
69
85
|
/** Prose delivery mode (see AgentConfig.proseRouting). Default 'locus'. */
|
|
70
86
|
readonly proseRouting: 'locus' | 'explicit' | 'hybrid' | 'disabled';
|
|
87
|
+
/** Exact whole-response known-tool wrapper containment (default off). */
|
|
88
|
+
readonly toolWrapperProseGuard: boolean;
|
|
71
89
|
/** Prompt-cache TTL forwarded to the provider (see AgentConfig.cacheTtl). */
|
|
72
90
|
readonly cacheTtl: NonNullable<AgentConfig['cacheTtl']>;
|
|
73
91
|
/** Emit prompt-cache markers on requests (see AgentConfig.promptCaching). */
|
|
@@ -121,6 +139,7 @@ export class Agent {
|
|
|
121
139
|
this.thinking = config.thinking;
|
|
122
140
|
this.refusalHandling = config.refusalHandling;
|
|
123
141
|
this.proseRouting = config.proseRouting ?? 'locus';
|
|
142
|
+
this.toolWrapperProseGuard = config.toolWrapperProseGuard ?? false;
|
|
124
143
|
this.cacheTtl = config.cacheTtl ?? '1h';
|
|
125
144
|
this.promptCaching = config.promptCaching ?? true;
|
|
126
145
|
this.prefillUserMessage = config.prefillUserMessage;
|
|
@@ -442,9 +461,12 @@ export class Agent {
|
|
|
442
461
|
*/
|
|
443
462
|
async compileWithInjections(
|
|
444
463
|
budget?: TokenBudget,
|
|
445
|
-
injections?: ContextInjection[]
|
|
464
|
+
injections?: ContextInjection[],
|
|
465
|
+
opts?: { kvUnifiedImmutablePrefixHash?: string },
|
|
446
466
|
): Promise<CompileResult> {
|
|
447
|
-
const result = await this.contextManager.compile(
|
|
467
|
+
const result = await this.contextManager.compile(
|
|
468
|
+
this.resolveBudget(budget), injections, opts as never,
|
|
469
|
+
);
|
|
448
470
|
if (!budget) this.settleRuntimeSettingsTransition();
|
|
449
471
|
return result;
|
|
450
472
|
}
|
|
@@ -623,7 +645,26 @@ export class Agent {
|
|
|
623
645
|
(this.contextManager as unknown as { setToolDefinitions?: (t: ToolDefinition[]) => void })
|
|
624
646
|
.setToolDefinitions?.(availableTools);
|
|
625
647
|
|
|
626
|
-
|
|
648
|
+
const strategy = (this.contextManager as unknown as { getStrategy?: () => unknown })
|
|
649
|
+
.getStrategy?.() as {
|
|
650
|
+
beginKvUnifiedSubmission?: (args: { submissionId: string; requestHash: string; layoutHash: string }) => void;
|
|
651
|
+
isKvUnifiedEnabled?: () => boolean;
|
|
652
|
+
};
|
|
653
|
+
const kvUnified = strategy?.isKvUnifiedEnabled?.() === true;
|
|
654
|
+
const prospectiveSystemInjections = (injections ?? [])
|
|
655
|
+
.filter((injection) => injection.position === 'system')
|
|
656
|
+
.flatMap((injection) => injection.content);
|
|
657
|
+
const immutablePrefixHash = kvUnified
|
|
658
|
+
? stableHash({
|
|
659
|
+
tools: availableTools.length > 0 ? availableTools : undefined,
|
|
660
|
+
system: this.buildSystemPrompt(prospectiveSystemInjections),
|
|
661
|
+
})
|
|
662
|
+
: undefined;
|
|
663
|
+
let { messages, systemInjections } = await this.compileWithInjections(
|
|
664
|
+
budget,
|
|
665
|
+
injections,
|
|
666
|
+
immutablePrefixHash ? { kvUnifiedImmutablePrefixHash: immutablePrefixHash } : undefined,
|
|
667
|
+
);
|
|
627
668
|
|
|
628
669
|
// Sanitize: strip empty/whitespace text blocks and drop messages left with
|
|
629
670
|
// no content. The Anthropic API rejects empty text blocks with 400
|
|
@@ -668,6 +709,7 @@ export class Agent {
|
|
|
668
709
|
},
|
|
669
710
|
tools: availableTools.length > 0 ? availableTools : undefined,
|
|
670
711
|
promptCaching: this.promptCaching,
|
|
712
|
+
...(kvUnified ? { cacheMarkers: 'cm-owned' as const } : {}),
|
|
671
713
|
cacheTtl: this.cacheTtl,
|
|
672
714
|
...(this.prefillUserMessage && { prefillUserMessage: this.prefillUserMessage }),
|
|
673
715
|
...(this.providerParams && { providerParams: this.providerParams }),
|
|
@@ -702,6 +744,28 @@ export class Agent {
|
|
|
702
744
|
|
|
703
745
|
const request = await this.buildActivationRequest(availableTools, injections, budget);
|
|
704
746
|
|
|
747
|
+
const receiptAware = (this.contextManager as unknown as { getStrategy?: () => unknown })
|
|
748
|
+
.getStrategy?.() as {
|
|
749
|
+
beginKvUnifiedSubmission?: (args: { submissionId: string; requestHash: string; layoutHash: string }) => void;
|
|
750
|
+
isKvUnifiedEnabled?: () => boolean;
|
|
751
|
+
};
|
|
752
|
+
const kvEnabled = receiptAware?.isKvUnifiedEnabled?.() === true;
|
|
753
|
+
const kvQueue: Array<{ submissionId: string; wireReceipt: CacheWireReceipt }> = [];
|
|
754
|
+
let kvCall = 0;
|
|
755
|
+
if (kvEnabled) {
|
|
756
|
+
const layoutHash = stableHash(request.messages);
|
|
757
|
+
const kvRequest = request as NormalizedRequest & KvUnifiedRequestHooks;
|
|
758
|
+
kvRequest.onCacheWireReceipt = (receipt) => {
|
|
759
|
+
const submissionId = `${this.name}:${this._streamId}:${Date.now()}:${kvCall++}`;
|
|
760
|
+
receiptAware.beginKvUnifiedSubmission!({
|
|
761
|
+
submissionId,
|
|
762
|
+
requestHash: receipt.requestHash,
|
|
763
|
+
layoutHash,
|
|
764
|
+
});
|
|
765
|
+
kvQueue.push({ submissionId, wireReceipt: receipt });
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
|
|
705
769
|
const stream = this.membrane.streamYielding(request, {
|
|
706
770
|
emitTokens: true,
|
|
707
771
|
emitBlocks: false,
|
|
@@ -715,7 +779,16 @@ export class Agent {
|
|
|
715
779
|
});
|
|
716
780
|
|
|
717
781
|
this._state = { status: 'streaming', stream };
|
|
718
|
-
return {
|
|
782
|
+
return {
|
|
783
|
+
stream,
|
|
784
|
+
request,
|
|
785
|
+
...(kvEnabled
|
|
786
|
+
? {
|
|
787
|
+
takeKvSubmission: () => kvQueue.shift(),
|
|
788
|
+
drainKvSubmissionIds: () => kvQueue.splice(0).map((item) => item.submissionId),
|
|
789
|
+
}
|
|
790
|
+
: {}),
|
|
791
|
+
};
|
|
719
792
|
}
|
|
720
793
|
|
|
721
794
|
/**
|