@codebolt/agent 6.1.19 → 6.1.21
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/README.md +19 -10
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +11 -15
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +0 -1
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +16 -33
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +7 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +135 -27
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +3 -3
- package/dist/processor-pieces/messageModifiers/contextAssemblyModifier.js +18 -12
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +15 -15
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +48 -2
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +9 -15
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +17 -20
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +8 -19
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +1 -1
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +15 -15
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +3 -3
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +2 -2
- package/dist/processor-pieces/utils/messageModifierHelper.js +3 -3
- package/dist/types/libFunctionTypes.d.ts +5 -0
- package/dist/unified/agent/agent.d.ts +69 -2
- package/dist/unified/agent/agent.js +370 -48
- package/dist/unified/agent/tools.d.ts +17 -3
- package/dist/unified/agent/tools.js +82 -51
- package/dist/unified/base/agentStep.d.ts +1 -0
- package/dist/unified/base/agentStep.js +39 -11
- package/dist/unified/base/initialPromptGenerator.d.ts +2 -0
- package/dist/unified/base/initialPromptGenerator.js +98 -20
- package/dist/unified/base/promptContext.d.ts +3 -0
- package/dist/unified/base/promptContext.js +193 -15
- package/dist/unified/base/responseExecutor.d.ts +9 -1
- package/dist/unified/base/responseExecutor.js +248 -68
- package/dist/unified/index.d.ts +1 -2
- package/dist/unified/index.js +2 -4
- package/dist/unified/services/CompressionCoordinator.js +9 -9
- package/dist/unified/services/compaction/autoCompact.js +5 -5
- package/dist/unified/services/compaction/contextCollapse.js +2 -2
- package/dist/unified/services/compaction/reactiveCompact.js +5 -5
- package/dist/unified/types/libTypes.d.ts +6 -0
- package/dist/unified/utils/agentToolLoader.d.ts +10 -0
- package/dist/unified/utils/agentToolLoader.js +90 -24
- package/package.json +5 -1
- package/dist/unified/agent/codeboltAgent.d.ts +0 -61
- package/dist/unified/agent/codeboltAgent.js +0 -334
|
@@ -102,6 +102,7 @@ Effective project directory for this task: ${currentDir}
|
|
|
102
102
|
${baseProjectPath ? `CodeBolt base project directory: ${baseProjectPath}
|
|
103
103
|
CodeBolt app-level configuration, providers, plugins, and .codebolt data are loaded from the base project directory. Code changes for the task should still target the effective project directory unless the user explicitly says otherwise.` : ''}
|
|
104
104
|
${directoryListing}
|
|
105
|
+
Async task policy: long-running commands and child threads are tracked as async tasks with execution_mode foreground_scoped, auto_scoped, background_scoped, or background_detached. Scoped tasks are owned by the current agent run and are stopped if the user force-stops the agent. Before completing, use async_task_list to inspect unresolved scoped work and async_task_control to wait, stop, or explicitly detach each running task. background_detached tasks survive user force-stop and natural completion, so detach only intentional background services such as dev servers.
|
|
105
106
|
`.trim();
|
|
106
107
|
// Prepare context parts (same as gemini-cli)
|
|
107
108
|
const contextParts = [environmentContext];
|
|
@@ -119,6 +120,10 @@ ${directoryListing}
|
|
|
119
120
|
if (mentionedEnvironmentContext) {
|
|
120
121
|
contextParts.push(mentionedEnvironmentContext);
|
|
121
122
|
}
|
|
123
|
+
const asyncTaskContext = await this.formatPendingAsyncTasks();
|
|
124
|
+
if (asyncTaskContext) {
|
|
125
|
+
contextParts.push(asyncTaskContext);
|
|
126
|
+
}
|
|
122
127
|
// Add full file context if enabled (just like gemini-cli does)
|
|
123
128
|
if (this.options.enableFullContext) {
|
|
124
129
|
try {
|
|
@@ -137,10 +142,11 @@ ${directoryListing}
|
|
|
137
142
|
role: 'user',
|
|
138
143
|
content: finalContent
|
|
139
144
|
};
|
|
145
|
+
const updatedMessage = (0, promptContext_1.appendUserContextMessage)(createdMessage, contextMessage);
|
|
140
146
|
return Promise.resolve({
|
|
141
|
-
...
|
|
147
|
+
...updatedMessage,
|
|
142
148
|
metadata: {
|
|
143
|
-
...
|
|
149
|
+
...updatedMessage.metadata,
|
|
144
150
|
environmentContextAdded: true,
|
|
145
151
|
projectAgentMdContextAdded: Boolean(agentMdContext),
|
|
146
152
|
fullContextAdded: this.options.enableFullContext,
|
|
@@ -187,6 +193,7 @@ ${directoryListing}
|
|
|
187
193
|
'The user explicitly mentioned these environments with #. Treat them as routing context, not as an automatic active-environment selection.',
|
|
188
194
|
'If the user asks to run, start, delegate, create, or continue work in one of these environments, first inspect this mentioned environment list and choose the matching environment.',
|
|
189
195
|
'Use the thread tool `thread_create_background` to create a background thread in the selected remote environment. Pass the selected environment object in `environment`, set `isRemoteTask: true`, and put the requested work in `userMessage` or `task`.',
|
|
196
|
+
'If the next step depends on that child thread finishing, use `async_task_control` with taskId `thread:<threadId>` and action `wait` before continuing.',
|
|
190
197
|
'If `thread_create_background` is not available in the current tool list, first use the tool search capability, such as `tool_search`, to find the thread/background-thread creation tool and then use the matching tool.',
|
|
191
198
|
'If multiple mentioned environments could match and the user did not specify which one, ask a brief clarification before creating the background thread.',
|
|
192
199
|
'Do not call environment management tools or change the active environment just because an environment was mentioned.',
|
|
@@ -194,6 +201,45 @@ ${directoryListing}
|
|
|
194
201
|
'</mentioned-environments>',
|
|
195
202
|
].join('\n');
|
|
196
203
|
}
|
|
204
|
+
async formatPendingAsyncTasks() {
|
|
205
|
+
try {
|
|
206
|
+
const response = await codeboltjs_1.default.asyncTask.listTasks({
|
|
207
|
+
scope: 'thread',
|
|
208
|
+
});
|
|
209
|
+
const tasks = Array.isArray(response === null || response === void 0 ? void 0 : response.tasks) ? response.tasks : [];
|
|
210
|
+
const unresolvedTasks = tasks.filter((task) => task &&
|
|
211
|
+
task.executionMode !== 'background_detached' &&
|
|
212
|
+
!['completed', 'failed', 'stopped'].includes(task.status));
|
|
213
|
+
const detachedTasks = tasks.filter((task) => task &&
|
|
214
|
+
task.executionMode === 'background_detached' &&
|
|
215
|
+
!['completed', 'failed', 'stopped'].includes(task.status));
|
|
216
|
+
if (unresolvedTasks.length === 0 && detachedTasks.length === 0) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const sections = [];
|
|
220
|
+
if (unresolvedTasks.length > 0) {
|
|
221
|
+
sections.push([
|
|
222
|
+
'<pending_async_tasks>',
|
|
223
|
+
'These scoped async tasks are still unresolved for this thread. Before completing, choose wait, stop, or detach for each task using async_task_control. Detach only intentional background services that should survive agent stop.',
|
|
224
|
+
JSON.stringify(unresolvedTasks, null, 2),
|
|
225
|
+
'</pending_async_tasks>',
|
|
226
|
+
].join('\n'));
|
|
227
|
+
}
|
|
228
|
+
if (detachedTasks.length > 0) {
|
|
229
|
+
sections.push([
|
|
230
|
+
'<detached_async_tasks>',
|
|
231
|
+
'These background_detached async tasks are still running in the background for this thread. They do not block completion and survive user force-stop. Stop them with async_task_control if they are no longer needed.',
|
|
232
|
+
JSON.stringify(detachedTasks, null, 2),
|
|
233
|
+
'</detached_async_tasks>',
|
|
234
|
+
].join('\n'));
|
|
235
|
+
}
|
|
236
|
+
return sections.join('\n\n');
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
console.error('Error reading pending async tasks:', error);
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
197
243
|
async readProjectAgentMd(basePath, title = 'Project Agent Instructions') {
|
|
198
244
|
const instructionFiles = [
|
|
199
245
|
path.join(basePath, '.codebolt', 'agent.md'),
|
|
@@ -34,10 +34,11 @@ class IdeContextModifier extends base_1.BaseMessageModifier {
|
|
|
34
34
|
this.lastSentIdeContext = newIdeContext;
|
|
35
35
|
}
|
|
36
36
|
this.forceFullContext = false;
|
|
37
|
+
const updatedMessage = (0, promptContext_1.appendSystemContextMessage)(createdMessage, ideContextMessage);
|
|
37
38
|
return Promise.resolve({
|
|
38
|
-
...
|
|
39
|
+
...updatedMessage,
|
|
39
40
|
metadata: {
|
|
40
|
-
...
|
|
41
|
+
...updatedMessage.metadata,
|
|
41
42
|
ideContextAdded: true,
|
|
42
43
|
ideContextType: this.forceFullContext ? 'full' : 'incremental'
|
|
43
44
|
}
|
|
@@ -37,6 +37,7 @@ exports.MemoryImportModifier = void 0;
|
|
|
37
37
|
const base_1 = require("../base");
|
|
38
38
|
const fs = __importStar(require("fs"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
|
+
const promptContext_1 = require("../../unified/base/promptContext");
|
|
40
41
|
class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
41
42
|
constructor(options = {}) {
|
|
42
43
|
super();
|
|
@@ -54,8 +55,7 @@ class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
|
54
55
|
if (!this.options.enableMemoryImport) {
|
|
55
56
|
return createdMessage;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
const userMessage = createdMessage.message.messages.find(msg => msg.role === 'user');
|
|
58
|
+
const userMessage = (0, promptContext_1.getCurrentUserMessage)(createdMessage);
|
|
59
59
|
if (!userMessage || typeof userMessage.content !== 'string') {
|
|
60
60
|
return createdMessage;
|
|
61
61
|
}
|
|
@@ -105,23 +105,17 @@ class MemoryImportModifier extends base_1.BaseMessageModifier {
|
|
|
105
105
|
if (processedImports.length === 0) {
|
|
106
106
|
return createdMessage;
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
...msg,
|
|
113
|
-
content
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
return msg;
|
|
117
|
-
});
|
|
108
|
+
const updatedMessage = (0, promptContext_1.updateCurrentUserMessage)(createdMessage, (message) => ({
|
|
109
|
+
...message,
|
|
110
|
+
content,
|
|
111
|
+
}));
|
|
118
112
|
return Promise.resolve({
|
|
113
|
+
...updatedMessage,
|
|
119
114
|
message: {
|
|
120
|
-
...
|
|
121
|
-
messages
|
|
115
|
+
...updatedMessage.message,
|
|
122
116
|
},
|
|
123
117
|
metadata: {
|
|
124
|
-
...
|
|
118
|
+
...updatedMessage.metadata,
|
|
125
119
|
memoryImportsProcessed: true,
|
|
126
120
|
importedFiles: processedImports,
|
|
127
121
|
totalImports: processedImports.length
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ToolInjectionModifier = void 0;
|
|
4
4
|
const base_1 = require("../base");
|
|
5
5
|
const agentToolLoader_1 = require("../../unified/utils/agentToolLoader");
|
|
6
|
+
const promptContext_1 = require("../../unified/base/promptContext");
|
|
6
7
|
class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
7
8
|
constructor(options = {}) {
|
|
8
9
|
super();
|
|
@@ -19,7 +20,7 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
19
20
|
}
|
|
20
21
|
async modify(originalRequest, createdMessage) {
|
|
21
22
|
try {
|
|
22
|
-
|
|
23
|
+
const mentionedMCPs = originalRequest.mentionedMCPs || [];
|
|
23
24
|
let tools = await (0, agentToolLoader_1.listAgentAvailableTools)(Array.isArray(mentionedMCPs) ? mentionedMCPs : []);
|
|
24
25
|
// Filter tools if allowedTools is specified
|
|
25
26
|
if (this.options.allowedTools && this.options.allowedTools.length > 0) {
|
|
@@ -30,17 +31,12 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
30
31
|
}
|
|
31
32
|
switch (this.options.toolsLocation) {
|
|
32
33
|
case 'InsidePrompt':
|
|
33
|
-
//@ts-ignore
|
|
34
34
|
return this.addToolsInsidePrompt(createdMessage, tools);
|
|
35
|
-
//@ts-ignore
|
|
36
35
|
case 'SystemMessage':
|
|
37
|
-
//@ts-ignore
|
|
38
36
|
return this.addToolsAsSystemMessage(createdMessage, tools);
|
|
39
37
|
case 'Tool':
|
|
40
|
-
//@ts-ignore
|
|
41
38
|
return this.addToolsAsToolCalls(createdMessage, tools);
|
|
42
39
|
default:
|
|
43
|
-
//@ts-ignore
|
|
44
40
|
return this.addToolsAsToolCalls(createdMessage, tools);
|
|
45
41
|
}
|
|
46
42
|
}
|
|
@@ -51,23 +47,24 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
51
47
|
}
|
|
52
48
|
addToolsInsidePrompt(createdMessage, tools) {
|
|
53
49
|
const toolsInfo = this.generateToolsInfo(tools);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const updatedMessage = (0, promptContext_1.updateCurrentUserMessage)(createdMessage, (message) => ({
|
|
51
|
+
...message,
|
|
52
|
+
content: typeof message.content === 'string'
|
|
53
|
+
? `${message.content}\n\n--- Available Tools ---\n${toolsInfo}`
|
|
54
|
+
: [
|
|
55
|
+
...(Array.isArray(message.content)
|
|
56
|
+
? message.content
|
|
57
|
+
: [{ type: 'text', text: String(message.content) }]),
|
|
58
|
+
{ type: 'text', text: `--- Available Tools ---\n${toolsInfo}` },
|
|
59
|
+
],
|
|
60
|
+
}));
|
|
64
61
|
return {
|
|
62
|
+
...updatedMessage,
|
|
65
63
|
message: {
|
|
66
|
-
...
|
|
67
|
-
messages: modifiedMessages
|
|
64
|
+
...updatedMessage.message,
|
|
68
65
|
},
|
|
69
66
|
metadata: {
|
|
70
|
-
...
|
|
67
|
+
...updatedMessage.metadata,
|
|
71
68
|
toolsInjected: true,
|
|
72
69
|
toolsLocation: 'InsidePrompt',
|
|
73
70
|
toolsCount: tools.length
|
|
@@ -83,7 +80,7 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
|
|
|
83
80
|
return {
|
|
84
81
|
message: {
|
|
85
82
|
...createdMessage.message,
|
|
86
|
-
|
|
83
|
+
input: [toolsMessage, ...createdMessage.message.input]
|
|
87
84
|
},
|
|
88
85
|
metadata: {
|
|
89
86
|
...createdMessage.metadata,
|
|
@@ -21,32 +21,21 @@ class LoopDetectionModifier extends base_1.BasePostInferenceProcessor {
|
|
|
21
21
|
}
|
|
22
22
|
const currentTime = Date.now();
|
|
23
23
|
// Add LLM response to history
|
|
24
|
-
|
|
24
|
+
const responseContent = llmResponseMessage.output_text || llmResponseMessage.content;
|
|
25
|
+
if (responseContent) {
|
|
25
26
|
this.messageHistory.push({
|
|
26
|
-
content:
|
|
27
|
+
content: typeof responseContent === 'string' ? responseContent : JSON.stringify(responseContent),
|
|
27
28
|
timestamp: currentTime,
|
|
28
|
-
role: llmResponseMessage.role
|
|
29
|
+
role: llmResponseMessage.role || 'assistant'
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
// Add any choice messages from LLM response to history
|
|
32
|
-
if (llmResponseMessage.choices) {
|
|
33
|
-
for (const choice of llmResponseMessage.choices) {
|
|
34
|
-
if (choice.message && choice.message.content) {
|
|
35
|
-
this.messageHistory.push({
|
|
36
|
-
content: choice.message.content,
|
|
37
|
-
timestamp: currentTime,
|
|
38
|
-
role: choice.message.role
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
32
|
// Add the original sent message to history if it exists
|
|
44
|
-
for (const message of llmMessageSent.message.
|
|
33
|
+
for (const message of llmMessageSent.message.input) {
|
|
45
34
|
if (typeof message.content === 'string') {
|
|
46
35
|
this.messageHistory.push({
|
|
47
36
|
content: message.content,
|
|
48
37
|
timestamp: currentTime,
|
|
49
|
-
role: message.role
|
|
38
|
+
role: message.role || 'user'
|
|
50
39
|
});
|
|
51
40
|
}
|
|
52
41
|
}
|
|
@@ -61,11 +50,11 @@ class LoopDetectionModifier extends base_1.BasePostInferenceProcessor {
|
|
|
61
50
|
role: 'system',
|
|
62
51
|
content: `[Loop Detection Warning] Similar messages detected in recent conversation. This may indicate a conversational loop. Consider rephrasing your request or providing more specific information.`
|
|
63
52
|
};
|
|
64
|
-
const updatedMessages = [...nextPrompt.message.
|
|
53
|
+
const updatedMessages = [...nextPrompt.message.input, warningMessage];
|
|
65
54
|
return Promise.resolve({
|
|
66
55
|
message: {
|
|
67
56
|
...nextPrompt.message,
|
|
68
|
-
|
|
57
|
+
input: updatedMessages
|
|
69
58
|
},
|
|
70
59
|
metadata: {
|
|
71
60
|
...nextPrompt.metadata,
|
|
@@ -238,7 +238,7 @@ export declare class ConversationCompactorModifier extends BasePostToolCallProce
|
|
|
238
238
|
* Forces compression regardless of threshold (for testing or manual trigger)
|
|
239
239
|
*/
|
|
240
240
|
forceCompress(messages: MessageObject[]): Promise<{
|
|
241
|
-
|
|
241
|
+
input: MessageObject[];
|
|
242
242
|
metadata: Partial<CompressionMetadata>;
|
|
243
243
|
}>;
|
|
244
244
|
}
|
|
@@ -304,7 +304,7 @@ class ConversationCompactorModifier extends basePostToolCallProcessor_1.BasePost
|
|
|
304
304
|
}
|
|
305
305
|
// If under budget, no truncation needed
|
|
306
306
|
if (toolResponseTokens <= this.options.toolResponseTokenBudget) {
|
|
307
|
-
return {
|
|
307
|
+
return { input: result, truncated: false, tokensSaved: 0 };
|
|
308
308
|
}
|
|
309
309
|
// Iterate from oldest to newest tool messages for truncation
|
|
310
310
|
// (We truncate older tool outputs first to preserve recent context)
|
|
@@ -344,7 +344,7 @@ class ConversationCompactorModifier extends basePostToolCallProcessor_1.BasePost
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
return {
|
|
347
|
+
return { input: result, truncated, tokensSaved };
|
|
348
348
|
}
|
|
349
349
|
// ========================================================================
|
|
350
350
|
// History Split Point Calculation (Phase 2)
|
|
@@ -518,7 +518,7 @@ CRITICAL RULES:
|
|
|
518
518
|
try {
|
|
519
519
|
const prompt = this.getCompressionPrompt(historyToCompress);
|
|
520
520
|
const response = await codeboltjs_1.default.llm.inference({
|
|
521
|
-
|
|
521
|
+
input: [
|
|
522
522
|
{ role: 'system', content: 'You are a precise conversation compression assistant.' },
|
|
523
523
|
{ role: 'user', content: prompt }
|
|
524
524
|
],
|
|
@@ -554,7 +554,7 @@ If the snapshot is accurate and complete, respond with just the original snapsho
|
|
|
554
554
|
If there are inaccuracies or missing critical information, provide a corrected version.
|
|
555
555
|
Keep the same XML format.`;
|
|
556
556
|
const response = await codeboltjs_1.default.llm.inference({
|
|
557
|
-
|
|
557
|
+
input: [
|
|
558
558
|
{ role: 'system', content: 'You are verifying a conversation compression for accuracy.' },
|
|
559
559
|
{ role: 'user', content: verificationPrompt }
|
|
560
560
|
]
|
|
@@ -680,7 +680,7 @@ Keep the same XML format.`;
|
|
|
680
680
|
if (this.options.enableLogging && deduplicatedCount > 0) {
|
|
681
681
|
console.log(`[ConversationCompactor] Deduplicated ${deduplicatedCount} file reads`);
|
|
682
682
|
}
|
|
683
|
-
return {
|
|
683
|
+
return { input: result, deduplicatedCount };
|
|
684
684
|
}
|
|
685
685
|
// ========================================================================
|
|
686
686
|
// Compression Strategies
|
|
@@ -732,7 +732,7 @@ Keep the same XML format.`;
|
|
|
732
732
|
*/
|
|
733
733
|
async compressSmart(messages) {
|
|
734
734
|
// Phase 1: Truncate large tool outputs
|
|
735
|
-
const {
|
|
735
|
+
const { input: truncatedMessages, truncated } = this.truncateLargeToolOutputs(messages);
|
|
736
736
|
// Check if truncation alone was sufficient
|
|
737
737
|
const tokensAfterTruncation = this.countMessageTokens(truncatedMessages);
|
|
738
738
|
const threshold = this.options.modelTokenLimit * this.options.compressionTokenThreshold;
|
|
@@ -789,7 +789,7 @@ Keep the same XML format.`;
|
|
|
789
789
|
*/
|
|
790
790
|
async compressSummarize(messages) {
|
|
791
791
|
// Phase 1: Truncate large tool outputs
|
|
792
|
-
const {
|
|
792
|
+
const { input: truncatedMessages, truncated } = this.truncateLargeToolOutputs(messages);
|
|
793
793
|
// Phase 2: Find split point
|
|
794
794
|
const splitIndex = this.findCompressionSplitIndex(truncatedMessages);
|
|
795
795
|
if (splitIndex === 0) {
|
|
@@ -869,7 +869,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
869
869
|
const { nextPrompt, rawLLMResponseMessage, tokenLimit } = input;
|
|
870
870
|
try {
|
|
871
871
|
// Safety check: ensure messages array exists
|
|
872
|
-
if (!((_a = nextPrompt === null || nextPrompt === void 0 ? void 0 : nextPrompt.message) === null || _a === void 0 ? void 0 : _a.
|
|
872
|
+
if (!((_a = nextPrompt === null || nextPrompt === void 0 ? void 0 : nextPrompt.message) === null || _a === void 0 ? void 0 : _a.input) || !Array.isArray(nextPrompt.message.input)) {
|
|
873
873
|
if (this.options.enableLogging) {
|
|
874
874
|
console.warn('[ConversationCompactor] No messages array found, skipping compression');
|
|
875
875
|
}
|
|
@@ -878,7 +878,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
878
878
|
shouldExit: false
|
|
879
879
|
};
|
|
880
880
|
}
|
|
881
|
-
const messages = nextPrompt.message.
|
|
881
|
+
const messages = nextPrompt.message.input;
|
|
882
882
|
// Get model token limit: prefer tokenLimit from LLM response, then lookup by model name, then fallback to config
|
|
883
883
|
const modelName = rawLLMResponseMessage === null || rawLLMResponseMessage === void 0 ? void 0 : rawLLMResponseMessage.model;
|
|
884
884
|
const modelTokenLimit = tokenLimit !== null && tokenLimit !== void 0 ? tokenLimit : (modelName ? getModelTokenLimit(modelName) : this.options.modelTokenLimit);
|
|
@@ -981,7 +981,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
981
981
|
};
|
|
982
982
|
}
|
|
983
983
|
// Pre-compression: deduplicate file reads to reduce token waste
|
|
984
|
-
const {
|
|
984
|
+
const { input: dedupedMessages } = this.deduplicateFileReads(messages);
|
|
985
985
|
// Apply compression based on strategy
|
|
986
986
|
let result;
|
|
987
987
|
switch (this.options.compactStrategy) {
|
|
@@ -1056,7 +1056,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
1056
1056
|
nextPrompt: {
|
|
1057
1057
|
message: {
|
|
1058
1058
|
...nextPrompt.message,
|
|
1059
|
-
|
|
1059
|
+
input: result.compressedMessages
|
|
1060
1060
|
},
|
|
1061
1061
|
metadata: {
|
|
1062
1062
|
...nextPrompt.metadata,
|
|
@@ -1079,10 +1079,10 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
1079
1079
|
...nextPrompt.metadata,
|
|
1080
1080
|
compression: {
|
|
1081
1081
|
status: CompressionStatus.FAILED_SUMMARIZATION_ERROR,
|
|
1082
|
-
originalTokenCount: this.countMessageTokens(nextPrompt.message.
|
|
1083
|
-
newTokenCount: this.countMessageTokens(nextPrompt.message.
|
|
1082
|
+
originalTokenCount: this.countMessageTokens(nextPrompt.message.input),
|
|
1083
|
+
newTokenCount: this.countMessageTokens(nextPrompt.message.input),
|
|
1084
1084
|
messagesCompressed: 0,
|
|
1085
|
-
messagesPreserved: nextPrompt.message.
|
|
1085
|
+
messagesPreserved: nextPrompt.message.input.length,
|
|
1086
1086
|
toolOutputsTruncated: false,
|
|
1087
1087
|
failedAttempts: this.failedCompressionAttempts,
|
|
1088
1088
|
timestamp: new Date().toISOString(),
|
|
@@ -1125,7 +1125,7 @@ Please continue from where the previous conversation left off. Do not ask the us
|
|
|
1125
1125
|
? this.compressSummarize(messages)
|
|
1126
1126
|
: this.compressSmart(messages));
|
|
1127
1127
|
return {
|
|
1128
|
-
|
|
1128
|
+
input: result.compressedMessages,
|
|
1129
1129
|
metadata: result.metadata
|
|
1130
1130
|
};
|
|
1131
1131
|
}
|
|
@@ -42,7 +42,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
|
|
|
42
42
|
// Also process any shell injections in the next prompt messages
|
|
43
43
|
const updatedMessages = [];
|
|
44
44
|
let contentModified = false;
|
|
45
|
-
for (const message of processedNextPrompt.message.
|
|
45
|
+
for (const message of processedNextPrompt.message.input) {
|
|
46
46
|
if (typeof message.content === 'string') {
|
|
47
47
|
let processedContent = message.content;
|
|
48
48
|
// Replace {{args}} placeholders if metadata has args
|
|
@@ -69,7 +69,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
|
|
|
69
69
|
processedNextPrompt = {
|
|
70
70
|
message: {
|
|
71
71
|
...processedNextPrompt.message,
|
|
72
|
-
|
|
72
|
+
input: updatedMessages
|
|
73
73
|
},
|
|
74
74
|
metadata: {
|
|
75
75
|
...processedNextPrompt.metadata,
|
|
@@ -109,7 +109,7 @@ class ShellProcessorModifier extends base_1.BasePostToolCallProcessor {
|
|
|
109
109
|
processedPrompt = {
|
|
110
110
|
message: {
|
|
111
111
|
...processedPrompt.message,
|
|
112
|
-
|
|
112
|
+
input: [...processedPrompt.message.input, systemMessage]
|
|
113
113
|
},
|
|
114
114
|
metadata: {
|
|
115
115
|
...processedPrompt.metadata,
|
|
@@ -104,12 +104,12 @@ class ChatCompressionModifier extends base_1.BasePreInferenceProcessor {
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
const compressionResult = await this.tryCompressChat(createdMessage.message.
|
|
107
|
+
const compressionResult = await this.tryCompressChat(createdMessage.message.input, this.options.force || false);
|
|
108
108
|
if (compressionResult.compressionStatus === CompressionStatus.COMPRESSED) {
|
|
109
109
|
return {
|
|
110
110
|
message: {
|
|
111
111
|
...createdMessage.message,
|
|
112
|
-
|
|
112
|
+
input: compressionResult.compressedMessages || createdMessage.message.input
|
|
113
113
|
},
|
|
114
114
|
metadata: {
|
|
115
115
|
...createdMessage.metadata,
|
|
@@ -7,7 +7,7 @@ const mergeMessages = (existing, additional) => {
|
|
|
7
7
|
message: {
|
|
8
8
|
...existing.message,
|
|
9
9
|
...additional.message,
|
|
10
|
-
|
|
10
|
+
input: [...existing.message.input, ...additional.message.input],
|
|
11
11
|
},
|
|
12
12
|
metadata: {
|
|
13
13
|
...existing.metadata,
|
|
@@ -31,7 +31,7 @@ const addSystemMessage = (message, systemContent) => {
|
|
|
31
31
|
return {
|
|
32
32
|
message: {
|
|
33
33
|
...message.message,
|
|
34
|
-
|
|
34
|
+
input: [systemMessage, ...message.message.input]
|
|
35
35
|
},
|
|
36
36
|
metadata: {
|
|
37
37
|
...message.metadata,
|
|
@@ -50,7 +50,7 @@ const addUserContext = (message, contextKey, contextValue) => {
|
|
|
50
50
|
return {
|
|
51
51
|
message: {
|
|
52
52
|
...message.message,
|
|
53
|
-
|
|
53
|
+
input: [...message.message.input, contextMessage]
|
|
54
54
|
},
|
|
55
55
|
metadata: {
|
|
56
56
|
...message.metadata,
|
|
@@ -232,6 +232,11 @@ export interface CodeboltAPI {
|
|
|
232
232
|
listMcpFromServers: (servers: string[]) => Promise<{
|
|
233
233
|
data: OpenAITool[];
|
|
234
234
|
}>;
|
|
235
|
+
getRegisteredTools: () => Promise<{
|
|
236
|
+
data?: {
|
|
237
|
+
tools: OpenAITool[];
|
|
238
|
+
};
|
|
239
|
+
}>;
|
|
235
240
|
getTools: (mcps: any[]) => Promise<{
|
|
236
241
|
data: OpenAITool[];
|
|
237
242
|
}>;
|
|
@@ -1,5 +1,46 @@
|
|
|
1
|
-
import { AgentConfig, AgentInterface } from "@codebolt/types/agent";
|
|
1
|
+
import { AgentConfig, AgentInterface, MessageModifier, PostInferenceProcessor, PostToolCallProcessor, PreInferenceProcessor, PreToolCallProcessor, ProcessedMessage, ToolResult } from "@codebolt/types/agent";
|
|
2
2
|
import { FlatUserMessage } from "@codebolt/types/sdk";
|
|
3
|
+
import { LoopDetectionService } from "../services/LoopDetectionService";
|
|
4
|
+
import type { CompactionOrchestratorOptions } from "../services/compaction/types";
|
|
5
|
+
export interface AgentOptions extends AgentConfig {
|
|
6
|
+
context?: ProcessedMessage;
|
|
7
|
+
allowedTools?: string[];
|
|
8
|
+
compaction?: CompactionOrchestratorOptions;
|
|
9
|
+
loopDetectionService?: LoopDetectionService;
|
|
10
|
+
maxTurns?: number;
|
|
11
|
+
includeDefaultModifiers?: boolean;
|
|
12
|
+
includeDefaultProcessors?: boolean;
|
|
13
|
+
messageModifiers?: MessageModifier[];
|
|
14
|
+
preInferenceProcessors?: PreInferenceProcessor[];
|
|
15
|
+
postInferenceProcessors?: PostInferenceProcessor[];
|
|
16
|
+
preToolCallProcessors?: PreToolCallProcessor[];
|
|
17
|
+
postToolCallProcessors?: PostToolCallProcessor[];
|
|
18
|
+
}
|
|
19
|
+
export interface AgentRunResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
state: AgentRunState | null;
|
|
22
|
+
toolResults: ToolResult[];
|
|
23
|
+
finalMessage?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use `state.prompt` instead.
|
|
27
|
+
*/
|
|
28
|
+
result: ProcessedMessage | null;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use `state` instead.
|
|
31
|
+
*/
|
|
32
|
+
context: ProcessedMessage | null;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentRunState {
|
|
35
|
+
prompt: ProcessedMessage;
|
|
36
|
+
}
|
|
37
|
+
export interface AgentRunOptions {
|
|
38
|
+
state?: AgentRunState;
|
|
39
|
+
context?: ProcessedMessage;
|
|
40
|
+
}
|
|
41
|
+
export interface CreateAgentOptions extends AgentOptions {
|
|
42
|
+
systemPrompt?: string;
|
|
43
|
+
}
|
|
3
44
|
export declare class Agent implements AgentInterface {
|
|
4
45
|
private readonly config;
|
|
5
46
|
private readonly messageModifiers;
|
|
@@ -8,19 +49,45 @@ export declare class Agent implements AgentInterface {
|
|
|
8
49
|
private readonly preToolCallProcessors;
|
|
9
50
|
private readonly postToolCallProcessors;
|
|
10
51
|
private readonly enableLogging;
|
|
52
|
+
private readonly baseSystemPrompt;
|
|
53
|
+
private readonly context;
|
|
54
|
+
private readonly allowedTools;
|
|
11
55
|
private readonly compactionOrchestrator;
|
|
12
56
|
private readonly loopDetectionService;
|
|
13
57
|
private readonly maxTurns;
|
|
14
|
-
|
|
58
|
+
private readonly localToolSchemas;
|
|
59
|
+
private readonly localToolsByExecutionName;
|
|
60
|
+
private readonly runtimeToolSetId;
|
|
61
|
+
constructor(config: AgentOptions);
|
|
62
|
+
run(message: string | FlatUserMessage, options?: ProcessedMessage | AgentRunOptions): Promise<AgentRunResult>;
|
|
63
|
+
private registerRuntimeToolsForSearch;
|
|
64
|
+
private unregisterRuntimeToolsForSearch;
|
|
65
|
+
processMessage(message: string | FlatUserMessage, options?: ProcessedMessage | AgentRunOptions): Promise<AgentRunResult>;
|
|
15
66
|
execute(reqMessage: FlatUserMessage): Promise<{
|
|
16
67
|
success: boolean;
|
|
17
68
|
result: any;
|
|
18
69
|
error?: string;
|
|
19
70
|
}>;
|
|
71
|
+
getConfig(): AgentOptions;
|
|
72
|
+
getMessageModifiers(): MessageModifier[];
|
|
73
|
+
getPreInferenceProcessors(): PreInferenceProcessor[];
|
|
74
|
+
getPostInferenceProcessors(): PostInferenceProcessor[];
|
|
75
|
+
getPreToolCallProcessors(): PreToolCallProcessor[];
|
|
76
|
+
getPostToolCallProcessors(): PostToolCallProcessor[];
|
|
77
|
+
private resolveRunContext;
|
|
78
|
+
private getResumeMessageModifiers;
|
|
79
|
+
private isProcessedMessage;
|
|
20
80
|
private applyCompaction;
|
|
81
|
+
private hydratePromptFromServerCompaction;
|
|
82
|
+
private isServerCompactionCurrent;
|
|
83
|
+
private extractCurrentRunMessages;
|
|
84
|
+
private isCurrentRunUserMessage;
|
|
85
|
+
private extractServerCompactedMessages;
|
|
86
|
+
private isServerCompactedMessage;
|
|
21
87
|
private tryRecoverPrompt;
|
|
22
88
|
private refreshAvailableTools;
|
|
23
89
|
private getAllowedToolNames;
|
|
24
90
|
private getRecoverableResponseError;
|
|
25
91
|
private collectResponseMessages;
|
|
26
92
|
}
|
|
93
|
+
export declare function createAgent(options: CreateAgentOptions): Agent;
|