Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🍱 feat: Guide Compaction With a Bounded Semantic Index (#15340)

Danny Avila10981b863735
diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.js
index fbbdef00d5..32347e30ec 100644
--- a/api/server/controllers/agents/client.js
+++ b/api/server/controllers/agents/client.js
@@ -3855,14 +3855,41 @@ class AgentClient extends BaseClient {
alwaysApplySkillPrimes,
});
const useLegacyContent = this.options.agent?.useLegacyContent === true;
+ const reachableAgents = collectReachableAgents([
+ this.options.agent,
+ ...(this.agentConfigs?.values() ?? []),
+ ]);
+ const deriveCompactionSemanticIndex = this.eventActorContinuation !== 'warm';
+ const messageFormatOptions = {
+ ...(needsReasoningContentFormat ? { preserveReasoningContent: true } : {}),
+ ...(freshSkillPrimeNames.size > 0 ? { skipSkillBodyNames: freshSkillPrimeNames } : {}),
+ ...(useLegacyContent ? { legacyContent: true } : {}),
+ };
+ let semanticIntentToolNames;
+ if (deriveCompactionSemanticIndex) {
+ semanticIntentToolNames = new Set();
+ const semanticIntentBlockedToolNames = new Set();
+ for (const agent of reachableAgents) {
+ for (const toolName of agent.semanticIntentToolNames ?? []) {
+ semanticIntentToolNames.add(toolName);
+ }
+ for (const toolName of agent.semanticIntentBlockedToolNames ?? []) {
+ semanticIntentBlockedToolNames.add(toolName);
+ }
+ }
+ for (const toolName of semanticIntentBlockedToolNames) {
+ semanticIntentToolNames.delete(toolName);
+ }
+ }
+ const hasMessageFormatOptions =
+ needsReasoningContentFormat || freshSkillPrimeNames.size > 0 || useLegacyContent;
const formatOptions =
- needsReasoningContentFormat || freshSkillPrimeNames.size > 0 || useLegacyContent
+ hasMessageFormatOptions || deriveCompactionSemanticIndex
? {
- ...(needsReasoningContentFormat ? { preserveReasoningContent: true } : {}),
- ...(freshSkillPrimeNames.size > 0
- ? { skipSkillBodyNames: freshSkillPrimeNames }
+ ...messageFormatOptions,
+ ...(deriveCompactionSemanticIndex
+ ? { compactionSemanticIndex: { intentToolNames: semanticIntentToolNames } }
: {}),
- ...(useLegacyContent ? { legacyContent: true } : {}),
}
: undefined;
let {
@@ -3870,8 +3897,9 @@ class AgentClient extends BaseClient {
indexTokenCountMap,
summary: initialSummary,
boundaryTokenAdjustment,
+ compactionSemanticIndex,
} = formatAgentMessages(
- stripActivityLabelParts(payload),
+ deriveCompactionSemanticIndex ? payload : stripActivityLabelParts(payload),
this.indexTokenCountMap,
toolSet,
skillPrimeResult?.skills,
@@ -3932,10 +3960,7 @@ class AgentClient extends BaseClient {
assertModelBoundContent({
filters: appConfig?.filters,
legacyPii: appConfig?.messageFilter?.pii,
- agents: collectReachableAgents([
- this.options.agent,
- ...(this.agentConfigs?.values() ?? []),
- ]),
+ agents: reachableAgents,
skills: [...(manualSkillPrimes ?? []), ...(alwaysApplySkillPrimes ?? [])],
memories: this.modelBoundMemoryContexts,
files: this.modelBoundFileContexts,
@@ -3965,7 +3990,7 @@ class AgentClient extends BaseClient {
undefined,
toolSet,
skillPrimeResult?.skills,
- formatOptions,
+ hasMessageFormatOptions ? messageFormatOptions : undefined,
).messages
: initialMessages;
@@ -4134,6 +4159,7 @@ class AgentClient extends BaseClient {
// rebuilt turns use the summary reconstructed from durable history.
indexTokenCountMap: this.eventActorContinuation === 'warm' ? {} : indexTokenCountMap,
initialSummary: continuationSummary,
+ ...(deriveCompactionSemanticIndex ? { compactionSemanticIndex } : {}),
initialSessions,
calibrationRatio,
runId: this.responseMessageId,
diff --git a/api/server/controllers/agents/client.test.js b/api/server/controllers/agents/client.test.js
index 00e04e5c89..0cfad6fd02 100644
--- a/api/server/controllers/agents/client.test.js
+++ b/api/server/controllers/agents/client.test.js
@@ -16,6 +16,9 @@ const mockFormatAgentMessages = jest.fn(() => ({
summary: undefined,
boundaryTokenAdjustment: undefined,
}));
+const mockStripActivityLabelParts = jest.fn((payload) =>
+ jest.requireActual('@librechat/api').stripActivityLabelParts(payload),
+);
const { Providers } = require('@librechat/agents');
const { Constants, ContentTypes, EModelEndpoint } = require('librechat-data-provider');
@@ -82,6 +85,7 @@ jest.mock('@librechat/api', () => ({
recordCollectedUsage: (...args) => mockRecordCollectedUsage(...args),
getAgentCheckpointer: mockGetAgentCheckpointer,
hasDurableAgentInterruptCheckpoint: (...args) => mockHasDurableAgentInterruptCheckpoint(...args),
+ stripActivityLabelParts: (...args) => mockStripActivityLabelParts(...args),
}));
describe('AgentClient - event actor history adapter', () => {
@@ -1713,6 +1717,186 @@ describe('AgentClient - startup telemetry', () => {
expect(processStream.mock.calls[0][1]).not.toHaveProperty('callbacks');
});
+ it('derives and forwards compaction guidance without stripping activity labels', async () => {
+ jest.clearAllMocks();
+ mockIsHITLEnabled.mockReturnValue(false);
+ const compactionSemanticIndex = [
+ {
+ type: 'activity_phase',
+ sourceMessageId: 'assistant-history',
+ sourceContentIndex: 1,
+ revision: 1,
+ status: 'committed',
+ text: 'Verified the release state',
+ },
+ ];
+ const payload = [
+ {
+ messageId: 'assistant-history',
+ content: [
+ { type: ContentTypes.TEXT, text: 'Details' },
+ {
+ type: ContentTypes.ACTIVITY_LABEL,
+ activity_label: 'Verified the release state',
+ activity_label_type: 'phase',
+ },
+ ],
+ },
+ ];
+ mockFormatAgentMessages.mockReturnValueOnce({
+ messages: [],
+ indexTokenCountMap: {},
+ summary: undefined,
+ boundaryTokenAdjustment: undefined,
+ compactionSemanticIndex,
+ });
+ const processStream = jest.fn().mockResolvedValue();
+ mockCreateRun.mockResolvedValueOnce({
+ Graph: null,
+ processStream,
+ getCalibrationRatio: jest.fn(() => 0),
+ getInterrupt: jest.fn(() => undefined),
+ });
+ const client = new AgentClient({
+ req: {
+ user: { id: 'user-123' },
+ body: {},
+ config: { endpoints: { [EModelEndpoint.agents]: {} } },
+ _resumableStreamId: 'semantic-index-conversation',
+ },
+ res: {},
+ agent: {
+ id: 'agent-primary',
+ endpoint: EModelEndpoint.openAI,
+ provider: EModelEndpoint.openAI,
+ model_parameters: { model: 'gpt-4' },
+ hide_sequential_outputs: false,
+ semanticIntentToolNames: ['web_search'],
+ semanticIntentBlockedToolNames: ['create_record'],
+ },
+ agentConfigs: new Map([
+ [
+ 'agent-secondary',
+ {
+ id: 'agent-secondary',
+ endpoint: EModelEndpoint.openAI,
+ provider: EModelEndpoint.openAI,
+ model_parameters: { model: 'gpt-4' },
+ semanticIntentToolNames: ['read_file', 'create_record'],
+ },
+ ],
+ ]),
+ endpointTokenConfig: {},
+ eventHandlers: {},
+ contentParts: [],
+ collectedUsage: [],
+ artifactPromises: [],
+ });
+ client.conversationId = 'semantic-index-conversation';
+ client.responseMessageId = 'semantic-index-response';
+ client.parentMessageId = 'semantic-index-parent';
+ client.recordCollectedUsage = jest.fn().mockResolvedValue();
+
+ await client.chatCompletion({ payload });
+
+ expect(mockFormatAgentMessages).toHaveBeenCalledTimes(1);
+ const [formattedPayload, , , , formatOptions] = mockFormatAgentMessages.mock.calls[0];
+ expect(formattedPayload).toBe(payload);
+ expect(formattedPayload[0].content).toContainEqual(
+ expect.objectContaining({ type: ContentTypes.ACTIVITY_LABEL }),
+ );
+ expect(mockStripActivityLabelParts).not.toHaveBeenCalled();
+ expect(formatOptions.compactionSemanticIndex.intentToolNames).toEqual(
+ new Set(['web_search', 'read_file']),
+ );
+ expect(mockCreateRun).toHaveBeenCalledWith(
+ expect.objectContaining({ compactionSemanticIndex }),
+ );
+ expect(processStream).toHaveBeenCalledTimes(1);
+ });
+
+ it('preserves provider messages while deriving the full semantic index', () => {
+ const { formatAgentMessages } = jest.requireActual('@librechat/agents');
+ const { stripActivityLabelParts } = jest.requireActual('@librechat/api');
+ const payload = [
+ {
+ role: 'assistant',
+ messageId: 'semantic-history',
+ content: [
+ {
+ type: ContentTypes.TOOL_CALL,
+ tool_call: {
+ id: 'search-1',
+ name: 'search_docs',
+ args: JSON.stringify({ intent: 'Locate the cache implementation', query: 'cache' }),
+ output: 'Found the implementation.',
+ outcome: 'Located the cache implementation',
+ },
+ },
+ {
+ type: ContentTypes.THINK,
+ think: 'Private reasoning stays out of compaction guidance.',
+ reasoning_label: 'Checking cache ownership',
+ reasoning_label_step_id: 'reasoning-1',
+ reasoning_label_revision: 2,
+ reasoning_label_status: 'complete',
+ },
+ {
+ type: ContentTypes.ACTIVITY_LABEL,
+ activity_label: 'Mapped the cache request path',
+ activity_label_type: 'phase',
+ activity_start_index: 0,
+ pending: false,
+ },
+ { type: ContentTypes.TEXT, text: 'The cache is initialized in the request adapter.' },
+ ],
+ },
+ ];
+
+ const legacyProjection = formatAgentMessages(
+ stripActivityLabelParts(payload),
+ undefined,
+ undefined,
+ undefined,
+ { preserveReasoningContent: true },
+ );
+ const baseline = formatAgentMessages(payload, undefined, undefined, undefined, {
+ preserveReasoningContent: true,
+ });
+ const derived = formatAgentMessages(payload, undefined, undefined, undefined, {
+ preserveReasoningContent: true,
+ compactionSemanticIndex: { intentToolNames: new Set(['search_docs']) },
+ });
+
+ expect(derived.messages.map((message) => message.toDict())).toEqual(
+ baseline.messages.map((message) => message.toDict()),
+ );
+ const providerShape = (messages) =>
+ messages.map((message) => {
+ const serialized = message.toDict();
+ const {
+ sourceMessageId: _sourceMessageId,
+ sourceMessageIds: _sourceMessageIds,
+ provenance: _provenance,
+ ...additional_kwargs
+ } = serialized.data.additional_kwargs;
+ const { response_metadata: _responseMetadata, ...data } = serialized.data;
+ return { ...serialized, data: { ...data, additional_kwargs } };
+ });
+ expect(providerShape(derived.messages)).toEqual(providerShape(legacyProjection.messages));
+ expect(derived.compactionSemanticIndex).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({ type: 'tool_intent', text: 'Locate the cache implementation' }),
+ expect.objectContaining({
+ type: 'tool_outcome',
+ text: 'Located the cache implementation',
+ }),
+ expect.objectContaining({ type: 'reasoning_label', text: 'Checking cache ownership' }),
+ expect.objectContaining({ type: 'activity_phase', text: 'Mapped the cache request path' }),
+ ]),
+ );
+ });
+
it('propagates final model callback policy errors instead of persisting a generic error part', async () => {
jest.clearAllMocks();
let policyError;
@@ -1849,6 +2033,9 @@ describe('AgentClient - startup telemetry', () => {
calibrationRatio: 1.25,
}),
);
+ expect(mockCreateRun.mock.calls[0][0]).not.toHaveProperty('compactionSemanticIndex');
+ expect(mockFormatAgentMessages.mock.calls[0][4]).toBeUndefined();
+ expect(mockStripActivityLabelParts).toHaveBeenCalledTimes(1);
expect(processStream).toHaveBeenCalledWith(
{ messages: [currentEvent] },
expect.objectContaining({
diff --git a/packages/api/src/agents/__tests__/run-summarization.test.ts b/packages/api/src/agents/__tests__/run-summarization.test.ts
index 55c61514ef..5f5e7f17e3 100644
--- a/packages/api/src/agents/__tests__/run-summarization.test.ts
+++ b/packages/api/src/agents/__tests__/run-summarization.test.ts
@@ -6,9 +6,9 @@ import {
MAX_SUBAGENT_DEPTH,
MAX_SUBAGENT_RUN_CONFIGS,
} from 'librechat-data-provider';
+import type { CompactionSemanticIndex, SubagentTaskConfig } from '@librechat/agents';
import type { SummarizationConfig, TEndpoint } from 'librechat-data-provider';
import type { BaseMessage } from '@langchain/core/messages';
-import type { SubagentTaskConfig } from '@librechat/agents';
import type { AppConfig } from '@librechat/data-schemas';
import type { ModelBoundChatModelCallback } from '~/middleware/modelBoundContent';
import { createRun, isAskUserQuestionAdminDisabled } from '~/agents/run';
@@ -182,6 +182,7 @@ async function callAndCapture(
appConfig?: AppConfig;
messages?: BaseMessage[];
discoveredToolNames?: string[];
+ compactionSemanticIndex?: CompactionSemanticIndex;
subagentTasks?: SubagentTaskConfig;
modelCallbacks?: readonly ModelBoundChatModelCallback[];
} = {},
@@ -197,6 +198,7 @@ async function callAndCapture(
appConfig: opts.appConfig,
messages: opts.messages,
discoveredToolNames: opts.discoveredToolNames,
+ compactionSemanticIndex: opts.compactionSemanticIndex,
subagentTasks: opts.subagentTasks,
modelCallbacks: opts.modelCallbacks,
streaming: true,
@@ -260,6 +262,57 @@ beforeEach(() => {
process.env.TENANT_ISOLATION_STRICT = 'true';
});
+describe('compaction semantic index forwarding', () => {
+ it('forwards one host-derived snapshot to every top-level agent input', async () => {
+ const compactionSemanticIndex = [
+ {
+ type: 'activity_phase',
+ sourceMessageId: 'message-1',
+ sourceContentIndex: 3,
+ revision: 2,
+ status: 'committed',
+ text: 'Verified the release state',
+ },
+ ] satisfies CompactionSemanticIndex;
+
+ const agents = await callAndCapture({
+ agents: [makeAgent({ id: 'agent_1' }), makeAgent({ id: 'agent_2' })],
+ compactionSemanticIndex,
+ });
+
+ expect(agents).toHaveLength(2);
+ expect(agents[0].compactionSemanticIndex).toBe(compactionSemanticIndex);
+ expect(agents[1].compactionSemanticIndex).toBe(compactionSemanticIndex);
+ });
+
+ it('does not leak the parent history index into an isolated subagent', async () => {
+ const compactionSemanticIndex = [
+ {
+ type: 'activity_phase',
+ sourceMessageId: 'message-1',
+ sourceContentIndex: 3,
+ revision: 2,
+ status: 'committed',
+ text: 'Verified the release state',
+ },
+ ] satisfies CompactionSemanticIndex;
+ const child = makeAgent({ id: 'agent_child' });
+ const [root] = await callAndCapture({
+ agents: [
+ makeAgent({
+ subagents: { enabled: true, allowSelf: false, agent_ids: ['agent_child'] },
+ subagentAgentConfigs: [child],
+ }),
+ ],
+ compactionSemanticIndex,
+ });
+ const [childConfig] = root.subagentConfigs as Array<Record<string, unknown>>;
+
+ expect(root.compactionSemanticIndex).toBe(compactionSemanticIndex);
+ expect(childConfig.agentInputs).not.toHaveProperty('compactionSemanticIndex');
+ });
+});
+
afterAll(() => {
delete process.env.TENANT_ISOLATION_STRICT;
});
diff --git a/packages/api/src/agents/initialize.ts b/packages/api/src/agents/initialize.ts
index 5831c95b95..96bd6fcef4 100644
--- a/packages/api/src/agents/initialize.ts
+++ b/packages/api/src/agents/initialize.ts
@@ -403,6 +403,10 @@ export type InitializedAgent = Agent & {
* own and are never listed here.
*/
intentToolNames?: string[];
+ /** Marker-verified tool names whose model-authored intent labels are safe compaction guidance. */
+ semanticIntentToolNames?: string[];
+ /** Tool names whose unverified schemas veto global semantic-intent trust for same-name calls. */
+ semanticIntentBlockedToolNames?: string[];
/** Whether the inline memory tools (`set_memory`/`delete_memory`) were
* registered for this agent. Authoritative LibreChat-only signal of the
* inline memory opt-in for the execution path, since some contexts hold the
@@ -1521,6 +1525,8 @@ export async function initializeAgent(
}
let intentToolNames: string[] | undefined;
+ let semanticIntentToolNames: string[] | undefined;
+ let semanticIntentBlockedToolNames: string[] | undefined;
/**
* Inject the `run_in_background` param into eligible opted-in tools and
@@ -1701,6 +1707,12 @@ export async function initializeAgent(
capabilityToolNames,
});
toolDefinitions = intentSanitized.toolDefinitions;
+ if (intentSanitized.semanticIntentToolNames.length > 0) {
+ semanticIntentToolNames = intentSanitized.semanticIntentToolNames;
+ }
+ if (intentSanitized.semanticIntentBlockedToolNames.length > 0) {
+ semanticIntentBlockedToolNames = intentSanitized.semanticIntentBlockedToolNames;
+ }
const hasFinalAgentTools =
(structuredTools?.length ?? 0) > 0 || (toolDefinitions?.length ?? 0) > 0;
@@ -1764,6 +1776,8 @@ export async function initializeAgent(
mcpToolAliases,
backgroundToolNames,
intentToolNames,
+ semanticIntentToolNames,
+ semanticIntentBlockedToolNames,
actionsEnabled,
accessibleMcpServerNames: resolvedAuditNames,
baseContextTokens,
diff --git a/packages/api/src/agents/intent.spec.ts b/packages/api/src/agents/intent.spec.ts
index 28f3e4af7d..762bd9a1c1 100644
--- a/packages/api/src/agents/intent.spec.ts
+++ b/packages/api/src/agents/intent.spec.ts
@@ -525,13 +525,53 @@ describe('sanitizeIntentLabels', () => {
it('leaves defs untouched when the capability is on and nothing opted out', () => {
const skill = sdkNativeDef('skill');
const defs = [skill];
- const { toolDefinitions } = sanitizeIntentLabels({
+ const { toolDefinitions, semanticIntentToolNames } = sanitizeIntentLabels({
toolDefinitions: defs,
toolRegistry: undefined,
toolOptions: undefined,
capabilityEnabled: true,
});
expect(toolDefinitions).toBe(defs);
+ expect(semanticIntentToolNames).toEqual(['skill']);
+ });
+
+ it('projects only surviving marker-verified intent schemas for compaction', () => {
+ const skill = sdkNativeDef('skill');
+ const hostInjected = injectIntentParam(mcpDef('web_search'));
+ const optedOut = sdkNativeDef('read_file');
+ const businessIntent = {
+ name: 'create_record',
+ parameters: {
+ type: 'object',
+ properties: {
+ intent: { type: 'string', description: 'CRM intent category for the record' },
+ },
+ },
+ } as unknown as LCTool;
+ const registryOnly = sdkNativeDef('tool_search');
+ const toolRegistry: LCToolRegistry = new Map([['tool_search', registryOnly]]);
+
+ const { semanticIntentToolNames, semanticIntentBlockedToolNames } = sanitizeIntentLabels({
+ toolDefinitions: [skill, hostInjected, optedOut, businessIntent],
+ toolRegistry,
+ toolOptions: { read_file: { describe_intent: false } },
+ capabilityEnabled: true,
+ });
+
+ expect(semanticIntentToolNames).toEqual(['skill', 'web_search', 'tool_search']);
+ expect(semanticIntentBlockedToolNames).toEqual(['read_file', 'create_record']);
+ });
+
+ it('projects no semantic intent names when the capability is disabled', () => {
+ const { semanticIntentToolNames, semanticIntentBlockedToolNames } = sanitizeIntentLabels({
+ toolDefinitions: [sdkNativeDef('skill')],
+ toolRegistry: undefined,
+ toolOptions: undefined,
+ capabilityEnabled: false,
+ });
+
+ expect(semanticIntentToolNames).toEqual([]);
+ expect(semanticIntentBlockedToolNames).toEqual(['skill']);
});
it('enforces explicit opt-outs on late-registered defs when the capability is on', () => {
diff --git a/packages/api/src/agents/intent.ts b/packages/api/src/agents/intent.ts
index 5989ce95c5..fce00bb253 100644
--- a/packages/api/src/agents/intent.ts
+++ b/packages/api/src/agents/intent.ts
@@ -412,7 +412,11 @@ export function sanitizeIntentLabels(params: {
capabilityEnabled: boolean;
/** Capability marker → registered definition names, from `initializeAgent`. */
capabilityToolNames?: CapabilityToolNames;
-}): { toolDefinitions: LCTool[] } {
+}): {
+ toolDefinitions: LCTool[];
+ semanticIntentToolNames: string[];
+ semanticIntentBlockedToolNames: string[];
+} {
const { toolRegistry, toolOptions, capabilityEnabled, capabilityToolNames } = params;
const defs = params.toolDefinitions ?? [];
const shouldStrip = (name: string): boolean =>
@@ -422,11 +426,22 @@ export function sanitizeIntentLabels(params: {
: true;
let changed = false;
+ const semanticIntentToolNames = new Set<string>();
+ const semanticIntentBlockedToolNames = new Set<string>();
+ const projectSemanticTrust = (def: LCTool): void => {
+ if (isIntentLabelProperty(def.parameters?.properties?.[INTENT_ARG])) {
+ semanticIntentToolNames.add(def.name);
+ return;
+ }
+ semanticIntentBlockedToolNames.add(def.name);
+ };
const nextDefs = defs.map((def) => {
if (!shouldStrip(def.name)) {
+ projectSemanticTrust(def);
return def;
}
const stripped = removeIntentParam(def);
+ projectSemanticTrust(stripped);
if (stripped !== def) {
changed = true;
const registryEntry = toolRegistry?.get(def.name);
@@ -439,15 +454,21 @@ export function sanitizeIntentLabels(params: {
if (toolRegistry) {
for (const [name, entry] of toolRegistry) {
if (!shouldStrip(name)) {
+ projectSemanticTrust(entry);
continue;
}
const stripped = removeIntentParam(entry);
+ projectSemanticTrust(stripped);
if (stripped !== entry) {
toolRegistry.set(name, stripped);
}
}
}
- return { toolDefinitions: changed ? nextDefs : defs };
+ return {
+ toolDefinitions: changed ? nextDefs : defs,
+ semanticIntentToolNames: Array.from(semanticIntentToolNames),
+ semanticIntentBlockedToolNames: Array.from(semanticIntentBlockedToolNames),
+ };
}
/**
diff --git a/packages/api/src/agents/run.ts b/packages/api/src/agents/run.ts
index fe7fd3ac60..0757b8439d 100644
--- a/packages/api/src/agents/run.ts
+++ b/packages/api/src/agents/run.ts
@@ -15,6 +15,7 @@ import type {
SummarizationConfig as AgentSummarizationConfig,
MultiAgentGraphConfig,
ContextPruningConfig,
+ CompactionSemanticIndex,
OpenAIClientOptions,
StandardGraphConfig,
StreamPreemption,
@@ -397,6 +398,8 @@ type RunAgent = Omit<Agent, 'tools'> & {
backgroundToolNames?: string[];
/** Names of tools with the host-injected `intent` param (stripped from self-spawn inputs). */
intentToolNames?: string[];
+ /** Marker-verified tool names whose intent labels are safe compaction guidance. */
+ semanticIntentToolNames?: string[];
/**
* Per-agent codeenv gate set by `initializeAgent`: admin-level
* `execute_code` capability AND the agent actually requested
@@ -1383,6 +1386,7 @@ export async function createRun({
indexTokenCountMap,
initialSessions,
summarizationConfig,
+ compactionSemanticIndex,
initialSummary,
modelCallbacks,
calibrationRatio,
@@ -1429,6 +1433,8 @@ export async function createRun({
*/
discoveredToolNames?: string[];
summarizationConfig?: SummarizationConfig;
+ /** Bounded, source-addressed navigation guidance derived with provider messages. */
+ compactionSemanticIndex?: CompactionSemanticIndex;
/** Cross-run summary from formatAgentMessages, forwarded to AgentContext */
initialSummary?: { text: string; tokenCount: number };
/** Model-level guards inherited by root, summary, fallback, and subagent clients. */
@@ -1730,6 +1736,7 @@ export async function createRun({
!isSubagent && discoveredTools.size > 0 ? Array.from(discoveredTools) : undefined,
summarizationEnabled: summarization.enabled,
summarizationConfig: summarization.config,
+ ...(!isSubagent && compactionSemanticIndex != null ? { compactionSemanticIndex } : {}),
initialSummary: isSubagent ? undefined : initialSummary,
contextPruningConfig: summarization.contextPruning,
maxToolResultChars: agent.maxToolResultChars,