@@ -8,14 +8,32 @@ const chat_1 = __importDefault(require("./../chat"));
88const tools_1 = __importDefault ( require ( "./../tools" ) ) ;
99const llm_1 = __importDefault ( require ( "./../llm" ) ) ;
1010const agent_1 = __importDefault ( require ( "./../agent" ) ) ;
11+ /**
12+ * Agent class that manages conversations with LLMs and tool executions.
13+ * Handles the conversation flow, tool calls, and task completions.
14+ */
1115class Agent {
16+ /**
17+ * Creates a new Agent instance.
18+ *
19+ * @param tools - The tools available to the agent
20+ * @param systemPrompt - The system prompt providing instructions to the LLM
21+ * @param maxRun - Maximum number of conversation turns (0 means unlimited)
22+ */
1223 constructor ( tools = [ ] , systemPrompt , maxRun = 0 ) {
1324 this . tools = tools ;
1425 this . userMessage = [ ] ;
1526 this . apiConversationHistory = [ ] ;
1627 this . maxRun = maxRun ;
1728 this . systemPrompt = systemPrompt ;
1829 }
30+ /**
31+ * Runs the agent on a specific task until completion or max runs reached.
32+ *
33+ * @param task - The task instruction to be executed
34+ * @param successCondition - Optional function to determine if the task is successful
35+ * @returns Promise with success status, error (if any), and the last assistant message
36+ */
1937 async run ( task , successCondition = ( ) => true ) {
2038 var _a , _b ;
2139 let mentaionedMCPSTool = await task . userMessage . getMentionedMcpsTools ( ) ;
@@ -199,6 +217,13 @@ class Agent {
199217 . pop ( ) ) === null || _b === void 0 ? void 0 : _b . content ) || ''
200218 } ;
201219 }
220+ /**
221+ * Attempts to make a request to the LLM with conversation history and tools.
222+ *
223+ * @param apiConversationHistory - The current conversation history
224+ * @param tools - The tools available to the LLM
225+ * @returns Promise with the LLM response
226+ */
202227 async attemptLlmRequest ( apiConversationHistory , tools ) {
203228 try {
204229 let systemPrompt = await this . systemPrompt . toPromptText ( ) ;
@@ -221,21 +246,48 @@ class Agent {
221246 return this . attemptApiRequest ( ) ;
222247 }
223248 }
249+ /**
250+ * Executes a tool with given name and input.
251+ *
252+ * @param toolName - The name of the tool to execute
253+ * @param toolInput - The input parameters for the tool
254+ * @returns Promise with tuple [userRejected, result]
255+ */
224256 async executeTool ( toolName , toolInput ) {
225257 //codebolttools--readfile
226258 const [ toolboxName , actualToolName ] = toolName . split ( '--' ) ;
227259 return tools_1 . default . executeTool ( toolboxName , actualToolName , toolInput ) ;
228260 }
261+ /**
262+ * Starts a sub-agent to handle a specific task.
263+ *
264+ * @param agentName - The name of the sub-agent to start
265+ * @param params - Parameters for the sub-agent
266+ * @returns Promise with tuple [userRejected, result]
267+ */
229268 async startSubAgent ( agentName , params ) {
230269 return agent_1 . default . startAgent ( agentName , params . task ) ;
231270 }
271+ /**
272+ * Extracts tool details from a tool call object.
273+ *
274+ * @param tool - The tool call object from the LLM response
275+ * @returns ToolDetails object with name, input, and ID
276+ */
232277 getToolDetail ( tool ) {
233278 return {
234279 toolName : tool . function . name ,
235280 toolInput : JSON . parse ( tool . function . arguments || "{}" ) ,
236281 toolUseId : tool . id
237282 } ;
238283 }
284+ /**
285+ * Creates a tool result object from the tool execution response.
286+ *
287+ * @param tool_call_id - The ID of the tool call
288+ * @param content - The content returned by the tool
289+ * @returns ToolResult object
290+ */
239291 getToolResult ( tool_call_id , content ) {
240292 let userMessage = undefined ;
241293 try {
@@ -255,7 +307,11 @@ class Agent {
255307 userMessage
256308 } ;
257309 }
258- // Placeholder for error fallback method
310+ /**
311+ * Fallback method for API requests in case of failures.
312+ *
313+ * @throws Error API request fallback not implemented
314+ */
259315 attemptApiRequest ( ) {
260316 throw new Error ( "API request fallback not implemented" ) ;
261317 }
0 commit comments