Skip to content

Commit b712bac

Browse files
changes
1 parent 1402cd4 commit b712bac

File tree

6 files changed

+71
-32
lines changed

6 files changed

+71
-32
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ declare class Codebolt {
244244
getEnabledMCPS: () => Promise<any>;
245245
};
246246
AGENT: {
247-
findAgent: (task: string, maxResult?: number, agents?: never[], agentLocaltion?: import("./modules/agent").AgentLocation) => Promise<any>;
247+
findAgent: (task: string, maxResult: number | undefined, agents: never[] | undefined, agentLocaltion: import("./modules/agent").AgentLocation | undefined, getFrom: import("./modules/agent").FilterUsing.USE_VECTOR_DB) => Promise<any>;
248248
startAgent: (agentId: string, task: string) => Promise<any>;
249249
getAgentsList: (type?: import("./modules/agent").Agents) => Promise<any>;
250250
getAgentsDetail: (agentList?: never[]) => Promise<any>;

modules/agent.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ export declare enum Agents {
88
ALL = "all",
99
DOWNLOADED = "downloaded"
1010
}
11+
export declare enum FilterUsing {
12+
USE_AI = "use_ai",
13+
USE_VECTOR_DB = "use_vector_db",
14+
USE_BOTH = "use_both"
15+
}
1116
declare const codeboltAgent: {
1217
/**
1318
* Retrieves an agent based on the specified task.
1419
* @param {string} task - The task for which an agent is needed.
1520
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
1621
*/
17-
findAgent: (task: string, maxResult?: number, agents?: never[], agentLocaltion?: AgentLocation) => Promise<any>;
22+
findAgent: (task: string, maxResult: number | undefined, agents: never[] | undefined, agentLocaltion: AgentLocation | undefined, getFrom: FilterUsing.USE_VECTOR_DB) => Promise<any>;
1823
/**
1924
* Starts an agent for the specified task.
2025
* @param {string} task - The task for which the agent should be started.

modules/agent.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6-
exports.Agents = exports.AgentLocation = void 0;
6+
exports.FilterUsing = exports.Agents = exports.AgentLocation = void 0;
77
const websocket_1 = __importDefault(require("./websocket"));
88
var AgentLocation;
99
(function (AgentLocation) {
@@ -17,25 +17,32 @@ var Agents;
1717
Agents["ALL"] = "all";
1818
Agents["DOWNLOADED"] = "downloaded";
1919
})(Agents || (exports.Agents = Agents = {}));
20+
var FilterUsing;
21+
(function (FilterUsing) {
22+
FilterUsing["USE_AI"] = "use_ai";
23+
FilterUsing["USE_VECTOR_DB"] = "use_vector_db";
24+
FilterUsing["USE_BOTH"] = "use_both";
25+
})(FilterUsing || (exports.FilterUsing = FilterUsing = {}));
2026
const codeboltAgent = {
2127
/**
2228
* Retrieves an agent based on the specified task.
2329
* @param {string} task - The task for which an agent is needed.
2430
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
2531
*/
26-
findAgent: (task, maxResult = 1, agents = [], agentLocaltion = AgentLocation.ALL) => {
32+
findAgent: (task, maxResult = 1, agents = [], agentLocaltion = AgentLocation.ALL, getFrom) => {
2733
return new Promise((resolve, reject) => {
2834
websocket_1.default.getWebsocket.send(JSON.stringify({
2935
"type": "agentEvent",
30-
"action": "getAgentByTask",
36+
"action": "findAgent",
3137
"task": task,
32-
"agents": agents,
38+
"agents": agents, // for filter in vector db
3339
"maxResult": maxResult,
34-
"location": agentLocaltion
40+
"location": agentLocaltion,
41+
"getFrom": getFrom
3542
}));
3643
websocket_1.default.getWebsocket.on('message', (data) => {
3744
const response = JSON.parse(data);
38-
if (response.type === "getAgentByTaskResponse") {
45+
if (response.type === "findAgentByTaskResponse") {
3946
resolve(response); // Resolve the Promise with the agent details
4047
}
4148
});

modules/agentlib/agent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Agent {
6262
else {
6363
console.log("calling tool with params", toolName, toolInput);
6464
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
65+
console.log("tool result", result);
6566
toolResults.push(this.getToolResult(toolUseId, result));
6667
if (didUserReject) {
6768
userRejectedToolUse = true;

src/modules/agent.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ export enum AgentLocation {
1010

1111

1212
export enum Agents {
13-
1413
LOCAL = 'local',
1514
ALL = 'all',
1615
DOWNLOADED = 'downloaded',
1716
}
1817

18+
export enum FilterUsing {
19+
USE_AI = 'use_ai',
20+
USE_VECTOR_DB = 'use_vector_db',
21+
USE_BOTH = 'use_both',
22+
}
23+
1924

2025

2126
const codeboltAgent = {
@@ -24,19 +29,20 @@ const codeboltAgent = {
2429
* @param {string} task - The task for which an agent is needed.
2530
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
2631
*/
27-
findAgent: (task: string, maxResult = 1, agents = [], agentLocaltion: AgentLocation = AgentLocation.ALL): Promise<any> => {
32+
findAgent: (task: string, maxResult = 1, agents = [], agentLocaltion: AgentLocation = AgentLocation.ALL, getFrom: FilterUsing.USE_VECTOR_DB): Promise<any> => {
2833
return new Promise((resolve, reject) => {
2934
cbws.getWebsocket.send(JSON.stringify({
3035
"type": "agentEvent",
31-
"action": "getAgentByTask",
36+
"action": "findAgent",
3237
"task": task,
33-
"agents": agents,
38+
"agents": agents,// for filter in vector db
3439
"maxResult": maxResult,
35-
"location": agentLocaltion
40+
"location": agentLocaltion,
41+
"getFrom": getFrom
3642
}));
3743
cbws.getWebsocket.on('message', (data: string) => {
3844
const response = JSON.parse(data);
39-
if (response.type === "getAgentByTaskResponse") {
45+
if (response.type === "findAgentByTaskResponse") {
4046
resolve(response); // Resolve the Promise with the agent details
4147
}
4248
});
@@ -65,19 +71,17 @@ const codeboltAgent = {
6571
});
6672
},
6773

68-
69-
7074
/**
7175
* Lists all available agents.
7276
* @returns {Promise<any>} A promise that resolves with the list of agents.
7377
*/
74-
getAgentsList: ( type: Agents = Agents.DOWNLOADED): Promise<any> => {
78+
getAgentsList: (type: Agents = Agents.DOWNLOADED): Promise<any> => {
7579
return new Promise((resolve, reject) => {
7680
cbws.getWebsocket.send(JSON.stringify({
7781
"type": "agentEvent",
7882
"action": "listAgents",
7983
"agentType": type,
80-
84+
8185
}));
8286
cbws.getWebsocket.on('message', (data: string) => {
8387
const response = JSON.parse(data);
@@ -91,7 +95,7 @@ const codeboltAgent = {
9195
* Lists all available agents.
9296
* @returns {Promise<any>} A promise that resolves with the list of agents.
9397
*/
94-
getAgentsDetail: (agentList=[]): Promise<any> => {
98+
getAgentsDetail: (agentList = []): Promise<any> => {
9599
return new Promise((resolve, reject) => {
96100
cbws.getWebsocket.send(JSON.stringify({
97101
"type": "agentEvent",

src/modules/agentlib/agent.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Agent {
3232
private userMessage: Message[];
3333

3434

35-
constructor(tools:any = [], systemPrompt: SystemPrompt, maxRun: number = 0, subAgents: Agent[] = []) {
35+
constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0, subAgents: Agent[] = []) {
3636
this.tools = tools;
3737
this.userMessage = [];
3838
this.apiConversationHistory = [];
@@ -42,10 +42,10 @@ class Agent {
4242

4343
}
4444

45-
async run(task: TaskInstruction, successCondition: () => boolean = () => true): Promise<{ success: boolean; error: string | null }> {
45+
async run(task: TaskInstruction, successCondition: () => boolean = () => true): Promise<{ success: boolean; error: string | null, message: string | null }> {
4646

4747

48-
let mentaionedMCPSTool:any[] = await task.userMessage.getMentionedMcpsTools();
48+
let mentaionedMCPSTool: any[] = await task.userMessage.getMentionedMcpsTools();
4949
this.tools = [
5050
...this.tools,
5151
...mentaionedMCPSTool
@@ -56,7 +56,6 @@ class Agent {
5656
let userMessages = await task.toPrompt();
5757
this.apiConversationHistory.push({ role: "user", content: userMessages });
5858
let runcomplete = 0;
59-
6059
while (!completed && (runcomplete <= this.maxRun || this.maxRun === 0)) {
6160
try {
6261
runcomplete++;
@@ -95,14 +94,28 @@ class Agent {
9594
if (toolName.includes("attempt_completion")) {
9695
taskCompletedBlock = tool;
9796
} else {
98-
console.log("calling tool with params", toolName, toolInput);
99-
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
100-
console.log("tool result", result);
101-
toolResults.push(this.getToolResult(toolUseId, result));
10297

103-
if (didUserReject) {
104-
userRejectedToolUse = true;
98+
let [serverName, nameOfTool] = toolName.replace('--', ':').split(':');
99+
if (serverName == 'subagent') {
100+
console.log("calling agent with params", nameOfTool, toolInput);
101+
const [didUserReject, result] = await this.startSubAgent(toolName, toolInput);
102+
console.log("tool result", result);
103+
toolResults.push(this.getToolResult(toolUseId, result));
104+
if (didUserReject) {
105+
userRejectedToolUse = true;
106+
}
107+
}
108+
else {
109+
console.log("calling tool with params", toolName, toolInput);
110+
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
111+
console.log("tool result", result);
112+
toolResults.push(this.getToolResult(toolUseId, result));
113+
114+
if (didUserReject) {
115+
userRejectedToolUse = true;
116+
}
105117
}
118+
106119
}
107120
} else {
108121
toolResults.push(this.getToolResult(toolUseId, "Skipping tool execution due to previous tool user rejection."));
@@ -140,14 +153,20 @@ class Agent {
140153
}
141154
}
142155
} catch (error) {
143-
return { success: false, error: error instanceof Error ? error.message : String(error) };
156+
return { success: false, error: error instanceof Error ? error.message : String(error), message: null };
144157
}
145158
} catch (error) {
146-
return { success: false, error: error instanceof Error ? error.message : String(error) };
159+
return { success: false, error: error instanceof Error ? error.message : String(error), message: null };
147160
}
148161
}
149162

150-
return { success: completed, error: null };
163+
return {
164+
success: completed,
165+
error: null,
166+
message: this.apiConversationHistory
167+
.filter(msg => msg.role === 'assistant')
168+
.pop()?.content as string || ''
169+
};
151170
}
152171

153172
private async attemptLlmRequest(apiConversationHistory: Message[], tools: Record<string, any>): Promise<any> {
@@ -178,6 +197,9 @@ class Agent {
178197
private async executeTool(toolName: string, toolInput: any): Promise<[boolean, any]> {
179198
return mcp.executeTool(toolName, toolInput);
180199
}
200+
private async startSubAgent(agentName: string, params: any): Promise<[boolean, any]> {
201+
return mcp.executeTool(agentName, params);
202+
}
181203

182204
private getToolDetail(tool: any): ToolDetails {
183205
return {

0 commit comments

Comments
 (0)