@@ -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