Skip to content

Commit 31f2a89

Browse files
changes
1 parent f57b443 commit 31f2a89

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

.github/workflows/publish-to-npm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
node-version: '20.x'
1515
registry-url: 'https://registry.npmjs.org'
1616
- run: npm install
17-
- run: npm run package
17+
- run: npm run build
1818
- run: npm publish --access public
1919
env:
2020
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

modules/agentlib/agent.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ declare class Agent {
1111
run(task: TaskInstruction, successCondition?: () => boolean): Promise<{
1212
success: boolean;
1313
error: string | null;
14+
message: string | null;
1415
}>;
1516
private attemptLlmRequest;
1617
private executeTool;
18+
private startSubAgent;
1719
private getToolDetail;
1820
private getToolResult;
1921
private attemptApiRequest;

modules/agentlib/agent.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Agent {
1717
this.subAgents = subAgents;
1818
}
1919
async run(task, successCondition = () => true) {
20-
var _a;
20+
var _a, _b;
2121
let mentaionedMCPSTool = await task.userMessage.getMentionedMcpsTools();
2222
this.tools = [
2323
...this.tools,
@@ -60,12 +60,24 @@ class Agent {
6060
taskCompletedBlock = tool;
6161
}
6262
else {
63-
console.log("calling tool with params", toolName, toolInput);
64-
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
65-
console.log("tool result", result);
66-
toolResults.push(this.getToolResult(toolUseId, result));
67-
if (didUserReject) {
68-
userRejectedToolUse = true;
63+
let [serverName, nameOfTool] = toolName.replace('--', ':').split(':');
64+
if (serverName == 'subagent') {
65+
console.log("calling agent with params", nameOfTool, toolInput);
66+
const [didUserReject, result] = await this.startSubAgent(toolName, toolInput);
67+
console.log("tool result", result);
68+
toolResults.push(this.getToolResult(toolUseId, result));
69+
if (didUserReject) {
70+
userRejectedToolUse = true;
71+
}
72+
}
73+
else {
74+
console.log("calling tool with params", toolName, toolInput);
75+
const [didUserReject, result] = await this.executeTool(toolName, toolInput);
76+
console.log("tool result", result);
77+
toolResults.push(this.getToolResult(toolUseId, result));
78+
if (didUserReject) {
79+
userRejectedToolUse = true;
80+
}
6981
}
7082
}
7183
}
@@ -98,14 +110,20 @@ class Agent {
98110
}
99111
}
100112
catch (error) {
101-
return { success: false, error: error instanceof Error ? error.message : String(error) };
113+
return { success: false, error: error instanceof Error ? error.message : String(error), message: null };
102114
}
103115
}
104116
catch (error) {
105-
return { success: false, error: error instanceof Error ? error.message : String(error) };
117+
return { success: false, error: error instanceof Error ? error.message : String(error), message: null };
106118
}
107119
}
108-
return { success: completed, error: null };
120+
return {
121+
success: completed,
122+
error: null,
123+
message: ((_b = this.apiConversationHistory
124+
.filter(msg => msg.role === 'assistant')
125+
.pop()) === null || _b === void 0 ? void 0 : _b.content) || ''
126+
};
109127
}
110128
async attemptLlmRequest(apiConversationHistory, tools) {
111129
try {
@@ -132,6 +150,9 @@ class Agent {
132150
async executeTool(toolName, toolInput) {
133151
return mcp_1.default.executeTool(toolName, toolInput);
134152
}
153+
async startSubAgent(agentName, params) {
154+
return mcp_1.default.executeTool(agentName, params);
155+
}
135156
getToolDetail(tool) {
136157
return {
137158
toolName: tool.function.name,

0 commit comments

Comments
 (0)