@@ -17,7 +17,7 @@ class Agent {
17
17
this . subAgents = subAgents ;
18
18
}
19
19
async run ( task , successCondition = ( ) => true ) {
20
- var _a ;
20
+ var _a , _b ;
21
21
let mentaionedMCPSTool = await task . userMessage . getMentionedMcpsTools ( ) ;
22
22
this . tools = [
23
23
...this . tools ,
@@ -60,12 +60,24 @@ class Agent {
60
60
taskCompletedBlock = tool ;
61
61
}
62
62
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
+ }
69
81
}
70
82
}
71
83
}
@@ -98,14 +110,20 @@ class Agent {
98
110
}
99
111
}
100
112
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 } ;
102
114
}
103
115
}
104
116
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 } ;
106
118
}
107
119
}
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
+ } ;
109
127
}
110
128
async attemptLlmRequest ( apiConversationHistory , tools ) {
111
129
try {
@@ -132,6 +150,9 @@ class Agent {
132
150
async executeTool ( toolName , toolInput ) {
133
151
return mcp_1 . default . executeTool ( toolName , toolInput ) ;
134
152
}
153
+ async startSubAgent ( agentName , params ) {
154
+ return mcp_1 . default . executeTool ( agentName , params ) ;
155
+ }
135
156
getToolDetail ( tool ) {
136
157
return {
137
158
toolName : tool . function . name ,
0 commit comments