@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.
Files changed (2) hide show
  1. package/dist/sdk/agent.js +26 -10
  2. 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 = mode === 'compact'
439
- ? undefined
440
- : renderAgentInstructions(instructionContext?.entries ?? [], previousMayContainAgentInstructions);
441
- let agentInstructionInsertIndex = mode === 'compact' ? undefined : Math.max(0, messages.length - 1);
442
- if (agentInstructionInsertIndex &&
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 nativeMessages = buildNativeCompactionMessages(messages, {
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 nativeCompactMessages = buildNativeCompactionMessages(compactHistory, {
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 = normalizeMessagesForModel(insertContextualInstructions(requestContextMessages, agentInstructionInsertIndex, agentInstructionMessage), {
700
- supportsImages: selectedModel.inputCapabilities.includes('IMAGE')
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) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.9.80",
3
+ "version": "0.9.81",
4
4
  "description": "Embeddable MAR coding agent SDK and CLI.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",