@codebolt/agent 5.0.8 → 5.0.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.
Files changed (114) hide show
  1. package/dist/unified/base/responseExecutor.js +10 -6
  2. package/package.json +5 -5
  3. package/dist/agent.d.ts +0 -86
  4. package/dist/agent.js +0 -324
  5. package/dist/builderpattern/agent.d.ts +0 -86
  6. package/dist/builderpattern/agent.js +0 -324
  7. package/dist/builderpattern/followupquestionbuilder.d.ts +0 -75
  8. package/dist/builderpattern/followupquestionbuilder.js +0 -197
  9. package/dist/builderpattern/index.d.ts +0 -14
  10. package/dist/builderpattern/index.js +0 -23
  11. package/dist/builderpattern/llmoutputhandler.d.ts +0 -102
  12. package/dist/builderpattern/llmoutputhandler.js +0 -452
  13. package/dist/builderpattern/promptbuilder.d.ts +0 -382
  14. package/dist/builderpattern/promptbuilder.js +0 -805
  15. package/dist/builderpattern/systemprompt.d.ts +0 -20
  16. package/dist/builderpattern/systemprompt.js +0 -48
  17. package/dist/builderpattern/taskInstruction.d.ts +0 -37
  18. package/dist/builderpattern/taskInstruction.js +0 -57
  19. package/dist/builderpattern/usermessage.d.ts +0 -70
  20. package/dist/builderpattern/usermessage.js +0 -123
  21. package/dist/composablepattern/agent.d.ts +0 -169
  22. package/dist/composablepattern/agent.js +0 -598
  23. package/dist/composablepattern/codebolt-storage.d.ts +0 -67
  24. package/dist/composablepattern/codebolt-storage.js +0 -320
  25. package/dist/composablepattern/document.d.ts +0 -149
  26. package/dist/composablepattern/document.js +0 -405
  27. package/dist/composablepattern/examples/codebolt-integration-example.d.ts +0 -12
  28. package/dist/composablepattern/examples/codebolt-integration-example.js +0 -218
  29. package/dist/composablepattern/examples/codebolt-storage-example.d.ts +0 -40
  30. package/dist/composablepattern/examples/codebolt-storage-example.js +0 -223
  31. package/dist/composablepattern/examples/custom-steps-example.d.ts +0 -20
  32. package/dist/composablepattern/examples/custom-steps-example.js +0 -455
  33. package/dist/composablepattern/examples/document-agent.d.ts +0 -17
  34. package/dist/composablepattern/examples/document-agent.js +0 -107
  35. package/dist/composablepattern/examples/simple-codebolt-integration.d.ts +0 -8
  36. package/dist/composablepattern/examples/simple-codebolt-integration.js +0 -164
  37. package/dist/composablepattern/examples/weather-agent.d.ts +0 -18
  38. package/dist/composablepattern/examples/weather-agent.js +0 -86
  39. package/dist/composablepattern/examples/workflow-example.d.ts +0 -12
  40. package/dist/composablepattern/examples/workflow-example.js +0 -463
  41. package/dist/composablepattern/index.d.ts +0 -63
  42. package/dist/composablepattern/index.js +0 -115
  43. package/dist/composablepattern/memory.d.ts +0 -89
  44. package/dist/composablepattern/memory.js +0 -141
  45. package/dist/composablepattern/tool.d.ts +0 -84
  46. package/dist/composablepattern/tool.js +0 -260
  47. package/dist/composablepattern/types.d.ts +0 -194
  48. package/dist/composablepattern/types.js +0 -6
  49. package/dist/composablepattern/user-context.d.ts +0 -214
  50. package/dist/composablepattern/user-context.js +0 -275
  51. package/dist/composablepattern/workflow.d.ts +0 -388
  52. package/dist/composablepattern/workflow.js +0 -562
  53. package/dist/followupquestionbuilder.d.ts +0 -75
  54. package/dist/followupquestionbuilder.js +0 -197
  55. package/dist/index.d.ts +0 -14
  56. package/dist/index.js +0 -23
  57. package/dist/llmoutputhandler.d.ts +0 -102
  58. package/dist/llmoutputhandler.js +0 -452
  59. package/dist/processor/agent/agentStep.d.ts +0 -49
  60. package/dist/processor/agent/agentStep.js +0 -241
  61. package/dist/processor/agent/toolExecutor.d.ts +0 -19
  62. package/dist/processor/agent/toolExecutor.js +0 -90
  63. package/dist/processor/index.d.ts +0 -7
  64. package/dist/processor/index.js +0 -36
  65. package/dist/processor/messageModifiers/baseMessageModifier.d.ts +0 -20
  66. package/dist/processor/messageModifiers/baseMessageModifier.js +0 -55
  67. package/dist/processor/processors/baseProcessor.d.ts +0 -14
  68. package/dist/processor/processors/baseProcessor.js +0 -29
  69. package/dist/processor/tools/baseTool.d.ts +0 -10
  70. package/dist/processor/tools/baseTool.js +0 -20
  71. package/dist/processor/tools/toolList.d.ts +0 -9
  72. package/dist/processor/tools/toolList.js +0 -22
  73. package/dist/processor/types/interfaces.d.ts +0 -94
  74. package/dist/processor/types/interfaces.js +0 -2
  75. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.d.ts +0 -22
  76. package/dist/processor-pieces/messageModifiers/addToolsListMessageModifier.js +0 -144
  77. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.d.ts +0 -15
  78. package/dist/processor-pieces/messageModifiers/baseContextMessageModifier.js +0 -75
  79. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.d.ts +0 -11
  80. package/dist/processor-pieces/messageModifiers/baseSystemInstructionMessageModifier.js +0 -46
  81. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.d.ts +0 -12
  82. package/dist/processor-pieces/messageModifiers/handleUrlMessageModifier.js +0 -60
  83. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.d.ts +0 -18
  84. package/dist/processor-pieces/messageModifiers/imageAttachmentMessageModifier.js +0 -222
  85. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.d.ts +0 -22
  86. package/dist/processor-pieces/messageModifiers/workingDirectoryMessageModifier.js +0 -194
  87. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.d.ts +0 -41
  88. package/dist/processor-pieces/processors/advancedLoopDetectionProcessor.js +0 -197
  89. package/dist/processor-pieces/processors/chatCompressionProcessor.d.ts +0 -26
  90. package/dist/processor-pieces/processors/chatCompressionProcessor.js +0 -90
  91. package/dist/processor-pieces/processors/chatRecordingProcessor.d.ts +0 -81
  92. package/dist/processor-pieces/processors/chatRecordingProcessor.js +0 -329
  93. package/dist/processor-pieces/processors/contextManagementProcessor.d.ts +0 -40
  94. package/dist/processor-pieces/processors/contextManagementProcessor.js +0 -305
  95. package/dist/processor-pieces/processors/loopDetectionProcessor.d.ts +0 -30
  96. package/dist/processor-pieces/processors/loopDetectionProcessor.js +0 -137
  97. package/dist/processor-pieces/processors/responseValidationProcessor.d.ts +0 -30
  98. package/dist/processor-pieces/processors/responseValidationProcessor.js +0 -228
  99. package/dist/processor-pieces/processors/telemetryProcessor.d.ts +0 -99
  100. package/dist/processor-pieces/processors/telemetryProcessor.js +0 -311
  101. package/dist/processor-pieces/processors/tokenManagementProcessor.d.ts +0 -37
  102. package/dist/processor-pieces/processors/tokenManagementProcessor.js +0 -178
  103. package/dist/processor-pieces/processors/toolExecutionProcessor.d.ts +0 -43
  104. package/dist/processor-pieces/processors/toolExecutionProcessor.js +0 -207
  105. package/dist/processor-pieces/tools/fileTools.d.ts +0 -26
  106. package/dist/processor-pieces/tools/fileTools.js +0 -162
  107. package/dist/promptbuilder.d.ts +0 -382
  108. package/dist/promptbuilder.js +0 -805
  109. package/dist/systemprompt.d.ts +0 -20
  110. package/dist/systemprompt.js +0 -48
  111. package/dist/taskInstruction.d.ts +0 -37
  112. package/dist/taskInstruction.js +0 -57
  113. package/dist/usermessage.d.ts +0 -70
  114. package/dist/usermessage.js +0 -123
@@ -125,7 +125,11 @@ class ResponseExecutor {
125
125
  if (contentBlock.message) {
126
126
  if (contentBlock.message.content != null) {
127
127
  lastMessageContent = contentBlock.message.content;
128
- await codeboltjs_1.default.chat.sendMessage(contentBlock.message.content, {});
128
+ // await codebolt.chat.sendMessage(contentBlock.message.content, {});
129
+ }
130
+ if (contentBlock.message["reasoning_content"] != null && (!lastMessageContent || lastMessageContent.trim() === '')) {
131
+ lastMessageContent = contentBlock.message["reasoning_content"];
132
+ // await codebolt.chat.sendMessage((contentBlock.message as any)["reasoning_content"], {});
129
133
  }
130
134
  }
131
135
  }
@@ -263,8 +267,8 @@ class ResponseExecutor {
263
267
  if (taskCompletedBlock) {
264
268
  const completionArgs = JSON.parse(taskCompletedBlock.function.arguments || "{}");
265
269
  // Capture the final message from attempt_completion
266
- if (completionArgs.result) {
267
- this.finalMessage = completionArgs.result;
270
+ if (completionArgs) {
271
+ this.finalMessage = JSON.stringify(completionArgs);
268
272
  }
269
273
  let [_, result] = await this.executeTool(taskCompletedBlock.function.name, completionArgs);
270
274
  if (result === "") {
@@ -301,12 +305,12 @@ class ResponseExecutor {
301
305
  * @returns Promise with tuple [userRejected, result]
302
306
  */
303
307
  async executeTool(toolName, toolInput) {
304
- var _a, _b;
308
+ var _a, _b, _c;
305
309
  //codebolttools--readfile
306
310
  // console.log("Executing tool: ", toolName, toolInput);
307
311
  const parts = toolName.split('--');
308
- const toolboxName = (_a = parts[0]) !== null && _a !== void 0 ? _a : '';
309
- const actualToolName = (_b = parts[1]) !== null && _b !== void 0 ? _b : '';
312
+ const toolboxName = parts.length > 1 ? ((_a = parts[0]) !== null && _a !== void 0 ? _a : '') : 'codebolt';
313
+ const actualToolName = parts.length > 1 ? ((_b = parts[1]) !== null && _b !== void 0 ? _b : '') : ((_c = parts[0]) !== null && _c !== void 0 ? _c : '');
310
314
  // console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
311
315
  const { data } = await codeboltjs_1.default.mcp.executeTool(toolboxName, actualToolName, toolInput);
312
316
  // console.log("Tool result: ", data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/agent",
3
- "version": "5.0.8",
3
+ "version": "5.0.9",
4
4
  "description": "CodeBolt Agent utilities for building and managing AI agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -30,10 +30,10 @@
30
30
  "dependencies": {
31
31
  "js-yaml": "^4.1.0",
32
32
  "zod": "^3.22.4",
33
- "@codebolt/types": "5.0.8"
33
+ "@codebolt/types": "5.0.9"
34
34
  },
35
35
  "peerDependencies": {
36
- "@codebolt/codeboltjs": "5.0.8"
36
+ "@codebolt/codeboltjs": "5.0.9"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/js-yaml": "^4.0.9",
@@ -43,8 +43,8 @@
43
43
  "typedoc": "0.28.16",
44
44
  "typedoc-plugin-markdown": "4.9.0",
45
45
  "typescript": "^5.4.5",
46
- "@codebolt/codeboltjs": "5.0.8",
47
- "@codebolt/types": "5.0.8"
46
+ "@codebolt/codeboltjs": "5.0.9",
47
+ "@codebolt/types": "5.0.9"
48
48
  },
49
49
  "exports": {
50
50
  "./builder": {
package/dist/agent.d.ts DELETED
@@ -1,86 +0,0 @@
1
- import { SystemPrompt } from "./systemprompt";
2
- import { TaskInstruction } from "./taskInstruction";
3
- /**
4
- * Agent class that manages conversations with LLMs and tool executions.
5
- * Handles the conversation flow, tool calls, and task completions.
6
- */
7
- declare class Agent {
8
- /** Available tools for the agent to use */
9
- private tools;
10
- /** Full conversation history for API calls */
11
- private apiConversationHistory;
12
- /** Maximum number of conversation turns (0 means unlimited) */
13
- private maxRun;
14
- /** System prompt that provides instructions to the model */
15
- private systemPrompt;
16
- /** Messages from the user */
17
- private userMessage;
18
- /** The next user message to be added to the conversation */
19
- private nextUserMessage;
20
- /**
21
- * Creates a new Agent instance.
22
- *
23
- * @param tools - The tools available to the agent
24
- * @param systemPrompt - The system prompt providing instructions to the LLM
25
- * @param maxRun - Maximum number of conversation turns (0 means unlimited)
26
- */
27
- constructor(tools: any | undefined, systemPrompt: SystemPrompt, maxRun?: number);
28
- /**
29
- * Runs the agent on a specific task until completion or max runs reached.
30
- *
31
- * @param task - The task instruction to be executed
32
- * @param successCondition - Optional function to determine if the task is successful
33
- * @returns Promise with success status, error (if any), and the last assistant message
34
- */
35
- run(task: TaskInstruction, successCondition?: () => boolean): Promise<{
36
- success: boolean;
37
- error: string | null;
38
- message: string | null;
39
- }>;
40
- /**
41
- * Attempts to make a request to the LLM with conversation history and tools.
42
- *
43
- * @param apiConversationHistory - The current conversation history
44
- * @param tools - The tools available to the LLM
45
- * @returns Promise with the LLM response
46
- */
47
- private attemptLlmRequest;
48
- /**
49
- * Executes a tool with given name and input.
50
- *
51
- * @param toolName - The name of the tool to execute
52
- * @param toolInput - The input parameters for the tool
53
- * @returns Promise with tuple [userRejected, result]
54
- */
55
- private executeTool;
56
- /**
57
- * Starts a sub-agent to handle a specific task.
58
- *
59
- * @param agentName - The name of the sub-agent to start
60
- * @param params - Parameters for the sub-agent
61
- * @returns Promise with tuple [userRejected, result]
62
- */
63
- private startSubAgent;
64
- /**
65
- * Extracts tool details from a tool call object.
66
- *
67
- * @param tool - The tool call object from the LLM response
68
- * @returns ToolDetails object with name, input, and ID
69
- */
70
- private getToolDetail;
71
- /**
72
- * Creates a tool result object from the tool execution response.
73
- *
74
- * @param tool_call_id - The ID of the tool call
75
- * @param content - The content returned by the tool
76
- * @returns ToolResult object
77
- */
78
- private getToolResult;
79
- /**
80
- * Fallback method for API requests in case of failures.
81
- *
82
- * @throws Error API request fallback not implemented
83
- */
84
- private attemptApiRequest;
85
- }
86
- export { Agent };
package/dist/agent.js DELETED
@@ -1,324 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Agent = void 0;
7
- const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
8
- const { chat, mcp, llm, agent: codeboltAgent } = codeboltjs_1.default;
9
- // All interfaces moved to libFunctionTypes.ts
10
- /**
11
- * Agent class that manages conversations with LLMs and tool executions.
12
- * Handles the conversation flow, tool calls, and task completions.
13
- */
14
- class Agent {
15
- /**
16
- * Creates a new Agent instance.
17
- *
18
- * @param tools - The tools available to the agent
19
- * @param systemPrompt - The system prompt providing instructions to the LLM
20
- * @param maxRun - Maximum number of conversation turns (0 means unlimited)
21
- */
22
- constructor(tools = [], systemPrompt, maxRun = 0) {
23
- this.tools = tools;
24
- this.userMessage = [];
25
- this.apiConversationHistory = [];
26
- this.maxRun = maxRun;
27
- this.systemPrompt = systemPrompt;
28
- }
29
- /**
30
- * Runs the agent on a specific task until completion or max runs reached.
31
- *
32
- * @param task - The task instruction to be executed
33
- * @param successCondition - Optional function to determine if the task is successful
34
- * @returns Promise with success status, error (if any), and the last assistant message
35
- */
36
- async run(task, successCondition = () => true) {
37
- var _a, _b;
38
- let mentaionedMCPSTool = await task.userMessage.getMentionedMcpsTools();
39
- this.tools = [
40
- ...this.tools,
41
- ...mentaionedMCPSTool || [],
42
- ];
43
- let mentionedAgents = await task.userMessage.getMentionedAgents();
44
- // Transform agents into tool format
45
- const agentTools = mentionedAgents.map(agent => {
46
- return {
47
- type: "function",
48
- function: {
49
- name: `subagent--${agent.unique_id}`,
50
- description: agent.longDescription || agent.description,
51
- parameters: {
52
- type: "object",
53
- properties: {
54
- task: {
55
- type: "string",
56
- description: "The task to be executed by the tool."
57
- }
58
- },
59
- required: ["task"]
60
- }
61
- }
62
- };
63
- });
64
- this.tools = this.tools.concat(agentTools);
65
- let completed = false;
66
- let userMessages = await task.toPrompt();
67
- this.apiConversationHistory.push({ role: "user", content: userMessages });
68
- let runcomplete = 0;
69
- while (!completed && (runcomplete <= this.maxRun || this.maxRun === 0)) {
70
- try {
71
- runcomplete++;
72
- const response = await this.attemptLlmRequest(this.apiConversationHistory, this.tools);
73
- let isMessagePresentinReply = false;
74
- for (const contentBlock of response.choices) {
75
- if (contentBlock.message) {
76
- isMessagePresentinReply = true;
77
- this.apiConversationHistory.push(contentBlock.message);
78
- if (contentBlock.message.content != null) {
79
- await chat.sendMessage(contentBlock.message.content, {});
80
- }
81
- }
82
- }
83
- if (!isMessagePresentinReply) {
84
- this.apiConversationHistory.push({
85
- role: "assistant",
86
- content: [{ type: "text", text: "Failure: I did not provide a response." }],
87
- });
88
- }
89
- try {
90
- let toolResults = [];
91
- let taskCompletedBlock;
92
- let userRejectedToolUse = false;
93
- const contentBlock = response.choices[0];
94
- if ((_a = contentBlock.message) === null || _a === void 0 ? void 0 : _a.tool_calls) {
95
- for (const tool of contentBlock.message.tool_calls) {
96
- try {
97
- const { toolInput, toolName, toolUseId } = this.getToolDetail(tool);
98
- if (!userRejectedToolUse) {
99
- if (toolName.includes("attempt_completion")) {
100
- taskCompletedBlock = tool;
101
- }
102
- else {
103
- let [serverName] = toolName.replace('--', ':').split(':');
104
- if (serverName == 'subagent') {
105
- const agentResponse = await codeboltAgent.startAgent(toolName.replace("subagent--", ''), toolInput.task);
106
- const [didUserReject, result] = [false, "tool result is successful"];
107
- let toolResult = this.getToolResult(toolUseId, result);
108
- toolResults.push({
109
- role: "tool",
110
- tool_call_id: toolResult.tool_call_id,
111
- content: toolResult.content,
112
- });
113
- if (toolResult.userMessage) {
114
- this.nextUserMessage = {
115
- role: "user",
116
- content: toolResult.userMessage
117
- };
118
- }
119
- if (didUserReject) {
120
- userRejectedToolUse = true;
121
- }
122
- }
123
- else {
124
- const [didUserReject, result] = await this.executeTool(toolName, toolInput);
125
- // toolResults.push(this.getToolResult(toolUseId, result));
126
- let toolResult = this.getToolResult(toolUseId, result);
127
- toolResults.push({
128
- role: "tool",
129
- tool_call_id: toolResult.tool_call_id,
130
- content: toolResult.content,
131
- });
132
- if (toolResult.userMessage) {
133
- this.nextUserMessage = {
134
- role: "user",
135
- content: toolResult.userMessage
136
- };
137
- }
138
- if (didUserReject) {
139
- userRejectedToolUse = true;
140
- }
141
- }
142
- }
143
- }
144
- else {
145
- let toolResult = this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection.");
146
- toolResults.push({
147
- role: "tool",
148
- tool_call_id: toolResult.tool_call_id,
149
- content: toolResult.content,
150
- });
151
- if (toolResult.userMessage) {
152
- this.nextUserMessage = {
153
- role: "user",
154
- content: toolResult.userMessage
155
- };
156
- }
157
- }
158
- }
159
- catch (error) {
160
- toolResults.push({
161
- role: "tool",
162
- tool_call_id: tool.id,
163
- content: `please provide valid json string for tool.function.arguments String(error)`,
164
- });
165
- }
166
- }
167
- }
168
- if (taskCompletedBlock) {
169
- let [_, result] = await this.executeTool(taskCompletedBlock.function.name, JSON.parse(taskCompletedBlock.function.arguments || "{}"));
170
- if (result === "") {
171
- completed = true;
172
- result = "The user is satisfied with the result.";
173
- }
174
- let toolResult = this.getToolResult(taskCompletedBlock.id, result);
175
- toolResults.push({
176
- role: "tool",
177
- tool_call_id: toolResult.tool_call_id,
178
- content: toolResult.content,
179
- });
180
- if (toolResult.userMessage) {
181
- this.nextUserMessage = {
182
- role: "user",
183
- content: toolResult.userMessage
184
- };
185
- }
186
- }
187
- this.apiConversationHistory.push(...toolResults);
188
- if (this.nextUserMessage) {
189
- this.apiConversationHistory.push(this.nextUserMessage);
190
- }
191
- let nextUserMessage = toolResults;
192
- if (toolResults.length === 0) {
193
- nextUserMessage = [{
194
- role: "user",
195
- content: [{
196
- type: "text",
197
- text: "If you have completed the user's task, use the attempt_completion tool. If you require additional information from the user, use the ask_followup_question tool. Otherwise, if you have not completed the task and do not need additional information, then proceed with the next step of the task. (This is an automated message, so do not respond to it conversationally.)"
198
- }]
199
- }];
200
- if (nextUserMessage) {
201
- this.apiConversationHistory.push(nextUserMessage[0]);
202
- }
203
- }
204
- }
205
- catch (error) {
206
- console.error("Error in agent tool call:", error);
207
- return { success: false, error: error instanceof Error ? error.message : String(error), message: null };
208
- }
209
- }
210
- catch (error) {
211
- console.error("Error in agent tool call:", error);
212
- return { success: false, error: error instanceof Error ? error.message : String(error), message: null };
213
- }
214
- }
215
- return {
216
- success: completed,
217
- error: null,
218
- message: ((_b = this.apiConversationHistory
219
- .filter(msg => msg.role === 'assistant')
220
- .pop()) === null || _b === void 0 ? void 0 : _b.content) || ''
221
- };
222
- }
223
- /**
224
- * Attempts to make a request to the LLM with conversation history and tools.
225
- *
226
- * @param apiConversationHistory - The current conversation history
227
- * @param tools - The tools available to the LLM
228
- * @returns Promise with the LLM response
229
- */
230
- async attemptLlmRequest(apiConversationHistory, tools) {
231
- try {
232
- let systemPrompt = await this.systemPrompt.toPromptText();
233
- const aiMessages = [
234
- { role: "system", content: systemPrompt },
235
- ...apiConversationHistory,
236
- ];
237
- const createParams = {
238
- full: true,
239
- messages: aiMessages,
240
- tools: tools,
241
- tool_choice: "auto",
242
- };
243
- //@ts-ignore
244
- const { completion } = await llm.inference(createParams);
245
- return completion;
246
- }
247
- catch (error) {
248
- return this.attemptApiRequest();
249
- }
250
- }
251
- /**
252
- * Executes a tool with given name and input.
253
- *
254
- * @param toolName - The name of the tool to execute
255
- * @param toolInput - The input parameters for the tool
256
- * @returns Promise with tuple [userRejected, result]
257
- */
258
- async executeTool(toolName, toolInput) {
259
- //codebolttools--readfile
260
- const [toolboxName, actualToolName] = toolName.split('--');
261
- console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
262
- const { data } = await mcp.executeTool(toolboxName, actualToolName, toolInput);
263
- console.log("Tool result: ", data);
264
- return data;
265
- }
266
- /**
267
- * Starts a sub-agent to handle a specific task.
268
- *
269
- * @param agentName - The name of the sub-agent to start
270
- * @param params - Parameters for the sub-agent
271
- * @returns Promise with tuple [userRejected, result]
272
- */
273
- async startSubAgent(agentName, params) {
274
- return [false, await codeboltAgent.startAgent(agentName, params.task)];
275
- }
276
- /**
277
- * Extracts tool details from a tool call object.
278
- *
279
- * @param tool - The tool call object from the LLM response
280
- * @returns ToolDetails object with name, input, and ID
281
- */
282
- getToolDetail(tool) {
283
- return {
284
- toolName: tool.function.name,
285
- toolInput: JSON.parse(tool.function.arguments || "{}"),
286
- toolUseId: tool.id
287
- };
288
- }
289
- /**
290
- * Creates a tool result object from the tool execution response.
291
- *
292
- * @param tool_call_id - The ID of the tool call
293
- * @param content - The content returned by the tool
294
- * @returns ToolResult object
295
- */
296
- getToolResult(tool_call_id, content) {
297
- let userMessage = undefined;
298
- try {
299
- let parsed = JSON.parse(content);
300
- if (parsed.payload && parsed.payload.content) {
301
- content = `The browser action has been executed. The screenshot have been captured for your analysis. The tool response is provided in the next user message`;
302
- // this.apiConversationHistory.push()
303
- userMessage = parsed.payload.content;
304
- }
305
- }
306
- catch (error) {
307
- }
308
- return {
309
- role: "tool",
310
- tool_call_id,
311
- content,
312
- userMessage
313
- };
314
- }
315
- /**
316
- * Fallback method for API requests in case of failures.
317
- *
318
- * @throws Error API request fallback not implemented
319
- */
320
- attemptApiRequest() {
321
- throw new Error("API request fallback not implemented");
322
- }
323
- }
324
- exports.Agent = Agent;
@@ -1,86 +0,0 @@
1
- import { SystemPrompt } from "./systemprompt";
2
- import { TaskInstruction } from "./taskInstruction";
3
- /**
4
- * Agent class that manages conversations with LLMs and tool executions.
5
- * Handles the conversation flow, tool calls, and task completions.
6
- */
7
- declare class Agent {
8
- /** Available tools for the agent to use */
9
- private tools;
10
- /** Full conversation history for API calls */
11
- private apiConversationHistory;
12
- /** Maximum number of conversation turns (0 means unlimited) */
13
- private maxRun;
14
- /** System prompt that provides instructions to the model */
15
- private systemPrompt;
16
- /** Messages from the user */
17
- private userMessage;
18
- /** The next user message to be added to the conversation */
19
- private nextUserMessage;
20
- /**
21
- * Creates a new Agent instance.
22
- *
23
- * @param tools - The tools available to the agent
24
- * @param systemPrompt - The system prompt providing instructions to the LLM
25
- * @param maxRun - Maximum number of conversation turns (0 means unlimited)
26
- */
27
- constructor(tools: any | undefined, systemPrompt: SystemPrompt, maxRun?: number);
28
- /**
29
- * Runs the agent on a specific task until completion or max runs reached.
30
- *
31
- * @param task - The task instruction to be executed
32
- * @param successCondition - Optional function to determine if the task is successful
33
- * @returns Promise with success status, error (if any), and the last assistant message
34
- */
35
- run(task: TaskInstruction, successCondition?: () => boolean): Promise<{
36
- success: boolean;
37
- error: string | null;
38
- message: string | null;
39
- }>;
40
- /**
41
- * Attempts to make a request to the LLM with conversation history and tools.
42
- *
43
- * @param apiConversationHistory - The current conversation history
44
- * @param tools - The tools available to the LLM
45
- * @returns Promise with the LLM response
46
- */
47
- private attemptLlmRequest;
48
- /**
49
- * Executes a tool with given name and input.
50
- *
51
- * @param toolName - The name of the tool to execute
52
- * @param toolInput - The input parameters for the tool
53
- * @returns Promise with tuple [userRejected, result]
54
- */
55
- private executeTool;
56
- /**
57
- * Starts a sub-agent to handle a specific task.
58
- *
59
- * @param agentName - The name of the sub-agent to start
60
- * @param params - Parameters for the sub-agent
61
- * @returns Promise with tuple [userRejected, result]
62
- */
63
- private startSubAgent;
64
- /**
65
- * Extracts tool details from a tool call object.
66
- *
67
- * @param tool - The tool call object from the LLM response
68
- * @returns ToolDetails object with name, input, and ID
69
- */
70
- private getToolDetail;
71
- /**
72
- * Creates a tool result object from the tool execution response.
73
- *
74
- * @param tool_call_id - The ID of the tool call
75
- * @param content - The content returned by the tool
76
- * @returns ToolResult object
77
- */
78
- private getToolResult;
79
- /**
80
- * Fallback method for API requests in case of failures.
81
- *
82
- * @throws Error API request fallback not implemented
83
- */
84
- private attemptApiRequest;
85
- }
86
- export { Agent };