@@ -2,7 +2,10 @@ import { v4 as uuidv4 } from 'uuid';
22import { z } from 'zod' ;
33import { zodToJsonSchema } from 'zod-to-json-schema' ;
44
5- import { backgroundToolRegistry , BackgroundToolStatus , BackgroundToolType } from '../../core/backgroundTools.js' ;
5+ import {
6+ backgroundToolRegistry ,
7+ BackgroundToolStatus ,
8+ } from '../../core/backgroundTools.js' ;
69import {
710 getDefaultSystemPrompt ,
811 getModel ,
@@ -92,7 +95,7 @@ export const agentStartTool: Tool<Parameters, ReturnType> = {
9295 returnsJsonSchema : zodToJsonSchema ( returnSchema ) ,
9396 execute : async ( params , context ) => {
9497 const { logger, agentId } = context ;
95-
98+
9699 // Validate parameters
97100 const {
98101 description,
@@ -102,10 +105,10 @@ export const agentStartTool: Tool<Parameters, ReturnType> = {
102105 relevantFilesDirectories,
103106 enableUserPrompt = false ,
104107 } = parameterSchema . parse ( params ) ;
105-
108+
106109 // Create an instance ID
107110 const instanceId = uuidv4 ( ) ;
108-
111+
109112 // Register this agent with the background tool registry
110113 backgroundToolRegistry . registerAgent ( agentId || 'unknown' , goal ) ;
111114 logger . verbose ( `Registered agent with ID: ${ instanceId } ` ) ;
@@ -154,23 +157,33 @@ export const agentStartTool: Tool<Parameters, ReturnType> = {
154157 state . completed = true ;
155158 state . result = result ;
156159 state . output = result . result ;
157-
160+
158161 // Update background tool registry with completed status
159- backgroundToolRegistry . updateToolStatus ( instanceId , BackgroundToolStatus . COMPLETED , {
160- result : result . result . substring ( 0 , 100 ) + ( result . result . length > 100 ? '...' : '' )
161- } ) ;
162+ backgroundToolRegistry . updateToolStatus (
163+ instanceId ,
164+ BackgroundToolStatus . COMPLETED ,
165+ {
166+ result :
167+ result . result . substring ( 0 , 100 ) +
168+ ( result . result . length > 100 ? '...' : '' ) ,
169+ } ,
170+ ) ;
162171 }
163172 } catch ( error ) {
164173 // Update agent state with the error
165174 const state = agentStates . get ( instanceId ) ;
166175 if ( state && ! state . aborted ) {
167176 state . completed = true ;
168177 state . error = error instanceof Error ? error . message : String ( error ) ;
169-
178+
170179 // Update background tool registry with error status
171- backgroundToolRegistry . updateToolStatus ( instanceId , BackgroundToolStatus . ERROR , {
172- error : error instanceof Error ? error . message : String ( error )
173- } ) ;
180+ backgroundToolRegistry . updateToolStatus (
181+ instanceId ,
182+ BackgroundToolStatus . ERROR ,
183+ {
184+ error : error instanceof Error ? error . message : String ( error ) ,
185+ } ,
186+ ) ;
174187 }
175188 }
176189 return true ;
0 commit comments