@@ -61,7 +61,7 @@ class Agent {
6161 /** Messages from the user */
6262 private userMessage : Message [ ] ;
6363 /** The next user message to be added to the conversation */
64- private nextUserMessage :any ;
64+ private nextUserMessage : any ;
6565
6666 /**
6767 * Creates a new Agent instance.
@@ -94,7 +94,7 @@ class Agent {
9494 this . tools = [
9595 ...this . tools ,
9696 ...mentaionedMCPSTool ,
97-
97+
9898 ]
9999 let mentionedAgents = await task . userMessage . getMentionedAgents ( ) ;
100100
@@ -118,7 +118,7 @@ class Agent {
118118 }
119119 } ;
120120 } ) ;
121-
121+
122122 this . tools = this . tools . concat ( agentTools ) ;
123123
124124
@@ -158,75 +158,86 @@ class Agent {
158158
159159 if ( contentBlock . message ?. tool_calls ) {
160160 for ( const tool of contentBlock . message . tool_calls ) {
161- const { toolInput, toolName, toolUseId } = this . getToolDetail ( tool ) ;
161+ try {
162+ const { toolInput, toolName, toolUseId } = this . getToolDetail ( tool ) ;
162163
163- if ( ! userRejectedToolUse ) {
164- if ( toolName . includes ( "attempt_completion" ) ) {
165- taskCompletedBlock = tool ;
166- } else {
164+ if ( ! userRejectedToolUse ) {
165+ if ( toolName . includes ( "attempt_completion" ) ) {
166+ taskCompletedBlock = tool ;
167+ } else {
167168
168- let [ serverName ] = toolName . replace ( '--' , ':' ) . split ( ':' ) ;
169+ let [ serverName ] = toolName . replace ( '--' , ':' ) . split ( ':' ) ;
169170
170171
171- if ( serverName == 'subagent' ) {
172+ if ( serverName == 'subagent' ) {
172173
173- const agentResponse = await codeboltAgent . startAgent ( toolName . replace ( "subagent--" , '' ) , toolInput . task ) ;
174- const [ didUserReject , result ] = [ false , "tool result is successful" ] ;
175- let toolResult = this . getToolResult ( toolUseId , result )
176- toolResults . push ( {
177- role : "tool" ,
178- tool_call_id : toolResult . tool_call_id ,
179- content : toolResult . content ,
174+ const agentResponse = await codeboltAgent . startAgent ( toolName . replace ( "subagent--" , '' ) , toolInput . task ) ;
175+ const [ didUserReject , result ] = [ false , "tool result is successful" ] ;
176+ let toolResult = this . getToolResult ( toolUseId , result )
177+ toolResults . push ( {
178+ role : "tool" ,
179+ tool_call_id : toolResult . tool_call_id ,
180+ content : toolResult . content ,
180181
181- } ) ;
182- if ( toolResult . userMessage ) {
183- this . nextUserMessage = {
184- role : "user" ,
185- content : toolResult . userMessage
182+ } ) ;
183+ if ( toolResult . userMessage ) {
184+ this . nextUserMessage = {
185+ role : "user" ,
186+ content : toolResult . userMessage
187+ }
188+ }
189+ if ( didUserReject ) {
190+ userRejectedToolUse = true ;
186191 }
192+
187193 }
188- if ( didUserReject ) {
189- userRejectedToolUse = true ;
194+ else {
195+ const [ didUserReject , result ] = await this . executeTool ( toolName , toolInput ) ;
196+ // toolResults.push(this.getToolResult(toolUseId, result));
197+ let toolResult = this . getToolResult ( toolUseId , result )
198+ toolResults . push ( {
199+ role : "tool" ,
200+ tool_call_id : toolResult . tool_call_id ,
201+ content : toolResult . content ,
202+
203+ } ) ;
204+ if ( toolResult . userMessage ) {
205+ this . nextUserMessage = {
206+ role : "user" ,
207+ content : toolResult . userMessage
208+ }
209+ }
210+ if ( didUserReject ) {
211+ userRejectedToolUse = true ;
212+ }
190213 }
191214
192215 }
193- else {
194- const [ didUserReject , result ] = await this . executeTool ( toolName , toolInput ) ;
195- // toolResults.push(this.getToolResult(toolUseId, result));
196- let toolResult = this . getToolResult ( toolUseId , result )
197- toolResults . push ( {
198- role : "tool" ,
199- tool_call_id : toolResult . tool_call_id ,
200- content : toolResult . content ,
201-
202- } ) ;
203- if ( toolResult . userMessage ) {
204- this . nextUserMessage = {
205- role : "user" ,
206- content : toolResult . userMessage
207- }
208- }
209- if ( didUserReject ) {
210- userRejectedToolUse = true ;
216+ } else {
217+ let toolResult = this . getToolResult ( toolUseId , "Skipping tool execution due to previous tool user rejection." )
218+
219+ toolResults . push ( {
220+ role : "tool" ,
221+ tool_call_id : toolResult . tool_call_id ,
222+ content : toolResult . content ,
223+
224+ } ) ;
225+ if ( toolResult . userMessage ) {
226+ this . nextUserMessage = {
227+ role : "user" ,
228+ content : toolResult . userMessage
211229 }
212230 }
213231
214232 }
215- } else {
216- let toolResult = this . getToolResult ( toolUseId , "Skipping tool execution due to previous tool user rejection." )
217-
233+ } catch ( error ) {
234+
218235 toolResults . push ( {
219236 role : "tool" ,
220- tool_call_id : toolResult . tool_call_id ,
221- content : toolResult . content ,
237+ tool_call_id : tool . id ,
238+ content : String ( error ) ,
222239
223240 } ) ;
224- if ( toolResult . userMessage ) {
225- this . nextUserMessage = {
226- role : "user" ,
227- content : toolResult . userMessage
228- }
229- }
230241
231242 }
232243 }
@@ -373,7 +384,7 @@ class Agent {
373384 * @returns ToolResult object
374385 */
375386 private getToolResult ( tool_call_id : string , content : string ) : ToolResult {
376- let userMessage = undefined
387+ let userMessage = undefined
377388 try {
378389 let parsed = JSON . parse ( content ) ;
379390
0 commit comments