Skip to content

Commit 272d1c6

Browse files
changes
1 parent 50b760e commit 272d1c6

File tree

7 files changed

+87
-31
lines changed

7 files changed

+87
-31
lines changed

modules/agentlib/agent.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import { SystemPrompt } from "./systemprompt";
22
import { TaskInstruction } from "./taskInstruction";
33
declare class Agent {
44
private tools;
5-
private subAgents;
65
private apiConversationHistory;
76
private maxRun;
87
private systemPrompt;
98
private userMessage;
109
private nextUserMessage;
11-
constructor(tools: any, systemPrompt: SystemPrompt, maxRun?: number, subAgents?: any[]);
10+
constructor(tools: any, systemPrompt: SystemPrompt, maxRun?: number);
1211
run(task: TaskInstruction, successCondition?: () => boolean): Promise<{
1312
success: boolean;
1413
error: string | null;

modules/agentlib/agent.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,42 @@ const tools_1 = __importDefault(require("./../tools"));
99
const llm_1 = __importDefault(require("./../llm"));
1010
const agent_1 = __importDefault(require("./../agent"));
1111
class Agent {
12-
constructor(tools = [], systemPrompt, maxRun = 0, subAgents = []) {
12+
constructor(tools = [], systemPrompt, maxRun = 0) {
1313
this.tools = tools;
1414
this.userMessage = [];
1515
this.apiConversationHistory = [];
1616
this.maxRun = maxRun;
1717
this.systemPrompt = systemPrompt;
18-
this.subAgents = subAgents;
19-
this.subAgents = subAgents.map(subagent => {
20-
subagent.function.name = `subagent--${subagent.function.name}`;
21-
return subagent;
22-
});
23-
this.tools = this.tools.concat(subAgents.map(subagent => ({
24-
...subagent
25-
})));
2618
}
2719
async run(task, successCondition = () => true) {
2820
var _a, _b;
2921
let mentaionedMCPSTool = await task.userMessage.getMentionedMcpsTools();
3022
this.tools = [
3123
...this.tools,
32-
...mentaionedMCPSTool
24+
...mentaionedMCPSTool,
3325
];
26+
let mentionedAgents = await task.userMessage.getMentionedAgents();
27+
// Transform agents into tool format
28+
const agentTools = mentionedAgents.map(agent => {
29+
return {
30+
type: "function",
31+
function: {
32+
name: `subagent--${agent.unique_id}`,
33+
description: agent.longDescription || agent.description,
34+
parameters: {
35+
type: "object",
36+
properties: {
37+
task: {
38+
type: "string",
39+
description: "The task to be executed by the tool."
40+
}
41+
},
42+
required: ["task"]
43+
}
44+
}
45+
};
46+
});
47+
this.tools = this.tools.concat(agentTools);
3448
let completed = false;
3549
let userMessages = await task.toPrompt();
3650
this.apiConversationHistory.push({ role: "user", content: userMessages });

modules/agentlib/usermessage.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
interface agent {
2+
description: string;
3+
title: string;
4+
id: number;
5+
agent_id: string;
6+
unique_id: string;
7+
longDescription: string;
8+
}
19
interface Message {
210
userMessage: string;
311
mentionedFiles?: string[];
412
mentionedMCPs: string[];
13+
mentionedAgents: agent[];
514
}
615
export interface UserMessageContent {
716
type: string;
@@ -15,6 +24,7 @@ declare class UserMessage {
1524
constructor(message: Message, promptOverride?: boolean);
1625
getFiles(): void;
1726
toPrompt(bAttachFiles?: boolean, bAttachImages?: boolean, bAttachEnvironment?: boolean): Promise<UserMessageContent[]>;
27+
getMentionedAgents(): agent[];
1828
getMentionedMcps(): string[];
1929
getMentionedMcpsTools(): Promise<any>;
2030
private getEnvironmentDetail;

modules/agentlib/usermessage.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class UserMessage {
5454
}
5555
return this.userMessages;
5656
}
57+
getMentionedAgents() {
58+
//TODO : get config in tool format if neede
59+
return this.message.mentionedAgents || [];
60+
}
5761
getMentionedMcps() {
5862
return this.message.mentionedMCPs || [];
5963
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.94",
3+
"version": "1.1.95",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/modules/agentlib/agent.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,57 @@ interface ToolDetails {
2727

2828
class Agent {
2929
private tools: any[];
30-
private subAgents: any[];
30+
// private subAgents: any[];
3131
private apiConversationHistory: Message[];
3232
private maxRun: number;
3333
private systemPrompt: SystemPrompt;
3434
private userMessage: Message[];
3535
private nextUserMessage:any;
3636

3737

38-
constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0, subAgents: any[] = []) {
38+
constructor(tools: any = [], systemPrompt: SystemPrompt, maxRun: number = 0) {
3939
this.tools = tools;
4040
this.userMessage = [];
4141
this.apiConversationHistory = [];
4242
this.maxRun = maxRun;
4343
this.systemPrompt = systemPrompt;
44-
this.subAgents = subAgents;
45-
this.subAgents = subAgents.map(subagent => {
46-
subagent.function.name = `subagent--${subagent.function.name}`;
47-
return subagent;
48-
});
49-
this.tools = this.tools.concat(subAgents.map(subagent => ({
50-
...subagent
51-
})));
52-
53-
5444

5545
}
5646

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

5949

6050
let mentaionedMCPSTool: any[] = await task.userMessage.getMentionedMcpsTools();
51+
6152
this.tools = [
6253
...this.tools,
63-
...mentaionedMCPSTool
54+
...mentaionedMCPSTool,
55+
6456
]
57+
let mentionedAgents = await task.userMessage.getMentionedAgents();
58+
59+
// Transform agents into tool format
60+
const agentTools = mentionedAgents.map(agent => {
61+
return {
62+
type: "function",
63+
function: {
64+
name: `subagent--${agent.unique_id}`,
65+
description: agent.longDescription || agent.description,
66+
parameters: {
67+
type: "object",
68+
properties: {
69+
task: {
70+
type: "string",
71+
description: "The task to be executed by the tool."
72+
}
73+
},
74+
required: ["task"]
75+
}
76+
}
77+
};
78+
});
79+
80+
this.tools = this.tools.concat(agentTools);
6581

6682

6783
let completed = false;

src/modules/agentlib/usermessage.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import cbfs from "./../fs";
22
import project from "./../project";
33
import mcp from "./../tools";
4-
import { escape } from "querystring";
5-
6-
4+
interface agent {
5+
6+
description: string;
7+
title: string;
8+
id: number;
9+
agent_id: string;
10+
unique_id: string;
11+
longDescription: string;
12+
13+
}
714
interface Message {
815
userMessage: string;
916
mentionedFiles?: string[];
1017
mentionedMCPs: string[];
18+
mentionedAgents: agent[];
1119
}
1220

1321
export interface UserMessageContent {
@@ -70,8 +78,13 @@ class UserMessage {
7078
return this.userMessages;
7179
}
7280

73-
getMentionedMcps(): string[] {
74-
return this.message.mentionedMCPs || [];
81+
getMentionedAgents() {
82+
//TODO : get config in tool format if neede
83+
return this.message.mentionedAgents || [];
84+
}
85+
86+
getMentionedMcps() {
87+
return this.message.mentionedMCPs || [];
7588
}
7689
async getMentionedMcpsTools() {
7790
if (this.mentionedMCPs.length > 0) {

0 commit comments

Comments
 (0)