@myagentroam/agent 0.9.80 → 0.9.81
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/sdk/agent.js +26 -10
- package/package.json +1 -1
package/dist/sdk/agent.js
CHANGED
|
@@ -435,11 +435,12 @@ export async function createMarAgent(options) {
|
|
|
435
435
|
? {}
|
|
436
436
|
: { workspaceDisplayPath: logicalWorkspace })
|
|
437
437
|
});
|
|
438
|
-
let agentInstructionMessage =
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (
|
|
438
|
+
let agentInstructionMessage = renderAgentInstructions(instructionContext?.entries ?? [], previousMayContainAgentInstructions);
|
|
439
|
+
let agentInstructionInsertIndex = mode === 'compact'
|
|
440
|
+
? contextualInstructionInsertIndex(messages)
|
|
441
|
+
: Math.max(0, messages.length - 1);
|
|
442
|
+
if (mode !== 'compact' &&
|
|
443
|
+
agentInstructionInsertIndex &&
|
|
443
444
|
messages[agentInstructionInsertIndex - 1]?.contextKind === 'environment')
|
|
444
445
|
agentInstructionInsertIndex--;
|
|
445
446
|
const tools = withCodeModeResultTypes(availableTools.filter((tool) => tool.name !== 'skill' || (instructionContext?.skills.size ?? 0) > 0));
|
|
@@ -506,7 +507,8 @@ export async function createMarAgent(options) {
|
|
|
506
507
|
if (mode === 'compact') {
|
|
507
508
|
const compactSystemPrompt = initialSystemPrompt;
|
|
508
509
|
const compactHistory = [...messages];
|
|
509
|
-
const
|
|
510
|
+
const projectedHistory = normalizeMessagesForModel(insertContextualInstructions(compactHistory, agentInstructionInsertIndex, agentInstructionMessage), { supportsImages: false });
|
|
511
|
+
const nativeMessages = buildNativeCompactionMessages(projectedHistory, {
|
|
510
512
|
focus: input.prompt,
|
|
511
513
|
highDensityCompaction: selectedModel.highDensityCompaction
|
|
512
514
|
});
|
|
@@ -555,7 +557,11 @@ export async function createMarAgent(options) {
|
|
|
555
557
|
let compactSummary = '';
|
|
556
558
|
const compactSystemPrompt = buildExecutionSystemPrompt(executionTools, 'run');
|
|
557
559
|
const compactHistory = retainCurrent ? messages.slice(0, -1) : messages;
|
|
558
|
-
const
|
|
560
|
+
const compactInstructionInsertIndex = retainCurrent
|
|
561
|
+
? contextualInstructionInsertIndex(compactHistory)
|
|
562
|
+
: agentInstructionInsertIndex;
|
|
563
|
+
const projectedHistory = normalizeMessagesForModel(insertContextualInstructions(compactHistory, compactInstructionInsertIndex, agentInstructionMessage), { supportsImages: false });
|
|
564
|
+
const nativeCompactMessages = buildNativeCompactionMessages(projectedHistory, {
|
|
559
565
|
highDensityCompaction: selectedModel.highDensityCompaction
|
|
560
566
|
});
|
|
561
567
|
const compactOverheadTokens = estimatedRequestTokens(compactSystemPrompt, buildCompactionMessages('', selectedModel.highDensityCompaction), executionTools);
|
|
@@ -696,9 +702,11 @@ export async function createMarAgent(options) {
|
|
|
696
702
|
deltaMessages: requestContextMessages.slice(sessionRuntime.responsesChain.messageCount)
|
|
697
703
|
}
|
|
698
704
|
: undefined;
|
|
699
|
-
const modelMessages =
|
|
700
|
-
supportsImages:
|
|
701
|
-
|
|
705
|
+
const modelMessages = mode === 'compact'
|
|
706
|
+
? normalizeMessagesForModel(requestContextMessages, { supportsImages: false })
|
|
707
|
+
: normalizeMessagesForModel(insertContextualInstructions(requestContextMessages, agentInstructionInsertIndex, agentInstructionMessage), {
|
|
708
|
+
supportsImages: selectedModel.inputCapabilities.includes('IMAGE')
|
|
709
|
+
});
|
|
702
710
|
let sawModelSemanticEvent = false;
|
|
703
711
|
const roundMessageCount = messages.length;
|
|
704
712
|
const persistToolCalls = async (calls) => {
|
|
@@ -1697,6 +1705,14 @@ function insertContextualInstructions(messages, index, content, environmentConte
|
|
|
1697
1705
|
});
|
|
1698
1706
|
return result;
|
|
1699
1707
|
}
|
|
1708
|
+
function contextualInstructionInsertIndex(messages) {
|
|
1709
|
+
let index = messages.findLastIndex((message) => message.role === 'user' && message.contextKind !== 'environment');
|
|
1710
|
+
if (index < 0)
|
|
1711
|
+
return 0;
|
|
1712
|
+
if (index > 0 && messages[index - 1]?.contextKind === 'environment')
|
|
1713
|
+
index--;
|
|
1714
|
+
return index;
|
|
1715
|
+
}
|
|
1700
1716
|
function estimatedRequestTokens(system, messages, tools, images) {
|
|
1701
1717
|
const transientImageCount = messages.reduce((total, message) => total + (message.images?.length ?? 0), images?.length ?? 0);
|
|
1702
1718
|
const textMessages = messages.map((message) => {
|