@myagentroam/agent 0.12.8 → 0.12.9
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/runtime/compaction/generate.d.ts +1 -0
- package/dist/runtime/compaction/generate.js +2 -7
- package/dist/runtime/compaction/history.js +1 -1
- package/dist/sdk/execution-compaction.d.ts +3 -2
- package/dist/sdk/execution-compaction.js +4 -2
- package/dist/sdk/request-preparation.d.ts +2 -0
- package/dist/sdk/request-preparation.js +5 -1
- package/dist/sdk/session-execution-factory.js +6 -2
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ import { type AuthoritativeModelUsage } from '../context/usage.js';
|
|
|
7
7
|
import type { CompactionOperation } from './operation.js';
|
|
8
8
|
interface CompactionSnapshot {
|
|
9
9
|
readonly history: readonly ModelMessage[];
|
|
10
|
+
readonly requestMessages: readonly ModelMessage[];
|
|
10
11
|
readonly system: string;
|
|
11
12
|
readonly systemBlocks?: ModelRequest['systemBlocks'];
|
|
12
13
|
readonly tools: readonly ClientToolDefinition[];
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { AgentError } from '../../error.js';
|
|
2
2
|
import { isProviderContextOverflow, recoverModelStream } from '../../model/recovery.js';
|
|
3
|
-
import { normalizeMessagesForModel } from '../context/normalize.js';
|
|
4
3
|
import { estimatedRequestTokens } from '../context/request-budget.js';
|
|
5
4
|
import { shouldUseNativeCompaction } from '../context/usage.js';
|
|
6
5
|
import { buildCompactionInput, buildCompactionMessages, buildNativeCompactionMessages } from './history.js';
|
|
7
|
-
import { projectSmartCompactionMessage } from './smart.js';
|
|
8
6
|
/** Generate a candidate from an isolated snapshot; never commit or adopt active context. */
|
|
9
7
|
export async function generateCompactionCandidate(snapshot, dependencies) {
|
|
10
8
|
const { operation, turn } = dependencies;
|
|
11
|
-
const
|
|
12
|
-
supportsImages: false
|
|
13
|
-
}).map(projectSmartCompactionMessage);
|
|
14
|
-
const nativeMessages = buildNativeCompactionMessages(projectedHistory, {
|
|
9
|
+
const nativeMessages = buildNativeCompactionMessages(snapshot.requestMessages, {
|
|
15
10
|
...(snapshot.focus === undefined ? {} : { focus: snapshot.focus })
|
|
16
11
|
});
|
|
17
12
|
const overhead = estimatedRequestTokens(snapshot.system, buildCompactionMessages(''), snapshot.tools);
|
|
@@ -21,7 +16,7 @@ export async function generateCompactionCandidate(snapshot, dependencies) {
|
|
|
21
16
|
contextWindowTokens: snapshot.contextWindowTokens,
|
|
22
17
|
latestUsage: snapshot.latestUsage,
|
|
23
18
|
historyMessages: snapshot.history,
|
|
24
|
-
appendedMessages: nativeMessages.slice(
|
|
19
|
+
appendedMessages: nativeMessages.slice(-1)
|
|
25
20
|
});
|
|
26
21
|
const fallbackMessages = () => buildCompactionMessages(buildCompactionInput(snapshot.history, {
|
|
27
22
|
...(snapshot.focus === undefined ? {} : { focus: snapshot.focus }),
|
|
@@ -6,7 +6,7 @@ export function buildNativeCompactionMessages(messages, input = {}) {
|
|
|
6
6
|
const contract = compactionPrompt();
|
|
7
7
|
return [
|
|
8
8
|
...messages
|
|
9
|
-
.filter((message) => message.contextKind !== 'private')
|
|
9
|
+
.filter((message) => message.contextKind !== 'private' || message.role === 'provider')
|
|
10
10
|
.map((message) => {
|
|
11
11
|
if (!message.images?.length)
|
|
12
12
|
return message;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { splitContextualPrompt } from '../runtime/context/contextual-blocks.js';
|
|
2
|
-
import type { SessionModelMessage } from '../session/model-request.js';
|
|
2
|
+
import type { SessionModelMessage, SessionModelRequest } from '../session/model-request.js';
|
|
3
3
|
import type { SessionRecord } from '../session/record-contract.js';
|
|
4
4
|
import type { SessionStore } from '../session/store/contracts.js';
|
|
5
5
|
import type { ClientToolDefinition } from '../tools/contracts.js';
|
|
@@ -11,7 +11,7 @@ import type { ResourceInputProjection } from './resource-input.js';
|
|
|
11
11
|
import type { createExecutionModelContext } from './execution-model-context.js';
|
|
12
12
|
import type { generateExecutionCompaction } from './execution-compact-generation.js';
|
|
13
13
|
type Snapshot = Parameters<typeof generateExecutionCompaction>[0]['snapshot'];
|
|
14
|
-
/** Snapshots
|
|
14
|
+
/** Snapshots durable evidence and its request projection separately; adopts only a committed checkpoint. */
|
|
15
15
|
export declare function createExecutionCompaction(ports: {
|
|
16
16
|
readonly mode: 'run' | 'plan' | 'compact';
|
|
17
17
|
readonly sessionId: string;
|
|
@@ -29,6 +29,7 @@ export declare function createExecutionCompaction(ports: {
|
|
|
29
29
|
boundary(): number;
|
|
30
30
|
updateBoundary(value: number): void;
|
|
31
31
|
snapshotTools(): readonly ClientToolDefinition[];
|
|
32
|
+
projectRequest(history: readonly SessionModelMessage[], tools: readonly ClientToolDefinition[]): Pick<SessionModelRequest, 'messages' | 'tools'>;
|
|
32
33
|
usage(): Snapshot['latestUsage'];
|
|
33
34
|
effort(): Snapshot['reasoningEffort'];
|
|
34
35
|
environment(): EnvironmentContextState;
|
|
@@ -2,7 +2,7 @@ import { splitContextualPrompt } from '../runtime/context/contextual-blocks.js';
|
|
|
2
2
|
import { compactSnapshotAnchor } from '../runtime/compaction/retained-context.js';
|
|
3
3
|
import { buildCompactedHistory } from '../runtime/compaction/history.js';
|
|
4
4
|
import { commitExecutionCompaction } from './execution-compact-commit.js';
|
|
5
|
-
/** Snapshots
|
|
5
|
+
/** Snapshots durable evidence and its request projection separately; adopts only a committed checkpoint. */
|
|
6
6
|
export function createExecutionCompaction(ports) {
|
|
7
7
|
return async (input, signal, prepare, compactionId) => {
|
|
8
8
|
const { messages, modelContext } = ports;
|
|
@@ -18,6 +18,7 @@ export function createExecutionCompaction(ports) {
|
|
|
18
18
|
return false;
|
|
19
19
|
const history = structuredClone(prefix).map(({ images: _images, ...message }) => message);
|
|
20
20
|
const tools = structuredClone(ports.snapshotTools());
|
|
21
|
+
const request = structuredClone(ports.projectRequest(history, tools));
|
|
21
22
|
const generation = modelContext.worldState.generation;
|
|
22
23
|
const usage = ports.usage();
|
|
23
24
|
const effort = ports.effort();
|
|
@@ -39,11 +40,12 @@ export function createExecutionCompaction(ports) {
|
|
|
39
40
|
});
|
|
40
41
|
const candidate = await ports.generate({
|
|
41
42
|
history,
|
|
43
|
+
requestMessages: request.messages,
|
|
42
44
|
system: composition.system,
|
|
43
45
|
...(composition.systemBlocks === undefined
|
|
44
46
|
? {}
|
|
45
47
|
: { systemBlocks: composition.systemBlocks }),
|
|
46
|
-
tools,
|
|
48
|
+
tools: request.tools,
|
|
47
49
|
contextWindowTokens: ports.model.contextWindowTokens,
|
|
48
50
|
latestUsage: usage,
|
|
49
51
|
reasoningEffort: effort,
|
|
@@ -5,5 +5,7 @@ import type { AgentModelConfiguration } from '../model/configuration.js';
|
|
|
5
5
|
import { type ContextualWorldState } from '../runtime/context/world-state.js';
|
|
6
6
|
/** Assemble captured round values only. Admission, Hooks and publication belong to Session. */
|
|
7
7
|
export declare function prepareSessionModelRequest(candidate: ModelRequest, model: Pick<AgentModelConfiguration, 'protocol' | 'inputCapabilities'>, entries: ContextualWorldState['entries'], residentTools: readonly ClientToolDefinition[], autoPermission: boolean): ModelRequest;
|
|
8
|
+
/** Conversation and Compact keep identical Code Mode and native discovery tool prefixes. */
|
|
9
|
+
export declare function projectSessionRequestTools(model: Pick<AgentModelConfiguration, 'protocol'>, tools: readonly ClientToolDefinition[], residentTools: readonly ClientToolDefinition[]): readonly ClientToolDefinition[];
|
|
8
10
|
/** The actual candidate and current Session view share the same side-effect-free projection. */
|
|
9
11
|
export declare function projectSessionRequestMessages(messages: readonly ModelMessage[], entries: ContextualWorldState['entries'], supportsImages: boolean, codeMode: boolean, autoPermission?: boolean): ModelMessage[];
|
|
@@ -10,9 +10,13 @@ export function prepareSessionModelRequest(candidate, model, entries, residentTo
|
|
|
10
10
|
return {
|
|
11
11
|
...candidate,
|
|
12
12
|
messages: projectSessionRequestMessages(candidate.messages, entries, model.inputCapabilities.includes('IMAGE'), codeMode, autoPermission),
|
|
13
|
-
tools:
|
|
13
|
+
tools: projectSessionRequestTools(model, candidate.tools, residentTools)
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
/** Conversation and Compact keep identical Code Mode and native discovery tool prefixes. */
|
|
17
|
+
export function projectSessionRequestTools(model, tools, residentTools) {
|
|
18
|
+
return projectModelRequestTools(model, projectCodeModeTools(tools, residentTools), new Set(residentTools.map((tool) => tool.name)));
|
|
19
|
+
}
|
|
16
20
|
/** The actual candidate and current Session view share the same side-effect-free projection. */
|
|
17
21
|
export function projectSessionRequestMessages(messages, entries, supportsImages, codeMode, autoPermission = false) {
|
|
18
22
|
return normalizeMessagesForModel(insertContextualWorldState(messages, entries), {
|
|
@@ -20,7 +20,7 @@ import { prepareExecutionRoundRequest } from './execution-round-request.js';
|
|
|
20
20
|
import { ExecutionToolCatalog, initializeExecutionToolCatalog } from './execution-tool-catalog.js';
|
|
21
21
|
import { createExecutionToolScope } from './execution-tool-scope.js';
|
|
22
22
|
import { createNativeSteer } from './native-steer.js';
|
|
23
|
-
import { projectSessionRequestMessages } from './request-preparation.js';
|
|
23
|
+
import { projectSessionRequestMessages, projectSessionRequestTools } from './request-preparation.js';
|
|
24
24
|
import { ResourceInputProjection } from './resource-input.js';
|
|
25
25
|
import { createHash, randomUUID } from 'node:crypto';
|
|
26
26
|
import { AgentError, describeAgentError } from '../error.js';
|
|
@@ -469,7 +469,7 @@ export function createSessionExecutionFactory(ports) {
|
|
|
469
469
|
? normalizeMessagesForModel([...preparingRequestMessages, ...messages.slice(preparingRequestBaseLength)], { supportsImages: selectedModel.inputCapabilities.includes('IMAGE') })
|
|
470
470
|
: projectSessionRequestMessages(messages.map((message, index) => index === currentExecutionUserIndex && modelInputImages?.length
|
|
471
471
|
? { ...message, images: modelInputImages }
|
|
472
|
-
: message),
|
|
472
|
+
: message), modelContext.worldState.entries, mode !== 'compact' && selectedModel.inputCapabilities.includes('IMAGE'), baseTools().some((tool) => tool.name === 'code_exec'), permissionPolicy.mode === 'auto')
|
|
473
473
|
}
|
|
474
474
|
});
|
|
475
475
|
if (mode !== 'compact') {
|
|
@@ -618,6 +618,10 @@ export function createSessionExecutionFactory(ports) {
|
|
|
618
618
|
contextCoordinator.setBoundary(value);
|
|
619
619
|
},
|
|
620
620
|
snapshotTools: () => projectTools(toolCatalog.tools),
|
|
621
|
+
projectRequest: (history, tools) => ({
|
|
622
|
+
messages: projectSessionRequestMessages(history, modelContext.worldState.entries, false, tools.some((tool) => tool.name === 'code_exec'), permissionPolicy.mode === 'auto'),
|
|
623
|
+
tools: projectSessionRequestTools(selectedModel, tools, projectTools(mcpRegistry.projectDirect(baseTools())))
|
|
624
|
+
}),
|
|
621
625
|
usage: () => modelLifecycle.usage,
|
|
622
626
|
effort: () => requestReasoningEffort ?? reasoningEffort,
|
|
623
627
|
environment: () => executionEnvironment,
|