11import os
22from dataclasses import field
3- from typing import Dict
43
54from rich .panel import Panel
65
7- from hackingBuddyGPT .capabilities import Capability
86from hackingBuddyGPT .capabilities .http_request import HTTPRequest
97from hackingBuddyGPT .capabilities .record_note import RecordNote
10- from hackingBuddyGPT .usecases .agents import Agent
11- from hackingBuddyGPT .usecases .base import AutonomousAgentUseCase , use_case
8+ from hackingBuddyGPT .usecases .base import AutonomousUseCase , use_case
129from hackingBuddyGPT .usecases .web_api_testing .documentation .openapi_specification_handler import \
1310 OpenAPISpecificationHandler
11+ from hackingBuddyGPT .utils .capability_manager import CapabilityManager
1412from hackingBuddyGPT .utils .prompt_generation import PromptGenerationHelper
1513from hackingBuddyGPT .utils .prompt_generation .information import PromptContext
1614from hackingBuddyGPT .utils .prompt_generation .prompt_engineer import PromptEngineer
2321from hackingBuddyGPT .utils .openai .openai_lib import OpenAILib
2422
2523
26- class SimpleWebAPIDocumentation (Agent ):
24+ @use_case ("Minimal implementation of a web API testing use case" )
25+ class SimpleWebAPIDocumentation (AutonomousUseCase ):
2726 """
2827 SimpleWebAPIDocumentation is an agent class for automating REST API documentation.
2928
@@ -41,10 +40,10 @@ class SimpleWebAPIDocumentation(Agent):
4140 found_all_http_methods (bool): Flag indicating whether all HTTP methods have been found.
4241 all_steps_done (bool): Flag to indicate whether the full documentation process is complete.
4342 """
44- llm : OpenAILib
43+ llm : OpenAILib = None
4544 _prompt_history : Prompt = field (default_factory = list )
4645 _context : Context = field (default_factory = lambda : {"notes" : list ()})
47- _capabilities : Dict [ str , Capability ] = field ( default_factory = dict )
46+ _capabilities : CapabilityManager = None
4847 _all_http_methods_found : bool = False
4948 config_path : str = parameter (
5049 desc = "Configuration file path" ,
@@ -75,6 +74,8 @@ class SimpleWebAPIDocumentation(Agent):
7574 default = "GET,POST,PUT,PATCH,DELETE" ,
7675 )
7776
77+ def get_name (self ) -> str :
78+ return self .__class__ .__name__
7879
7980 def init (self ):
8081 """Initialize the agent with configurations, capabilities, and handlers."""
@@ -90,7 +91,11 @@ def init(self):
9091
9192 self .categorized_endpoints = self .categorize_endpoints (self ._correct_endpoints , query_params )
9293
93- self ._setup_capabilities ()
94+ # setup capabilities
95+ self ._capabilities .init ()
96+ self ._capabilities .add_capability (HTTPRequest (self .host ))
97+ self ._capabilities .add_capability (RecordNote (self ._context ["notes" ]))
98+
9499 self ._prompt_context = PromptContext .DOCUMENTATION
95100 name , initial_prompt = self ._setup_initial_prompt (description = description )
96101 self ._initialize_handlers (config = config , description = description , token = token , name = name ,
@@ -150,7 +155,7 @@ def _initialize_handlers(self, config, description, token, name, initial_prompt)
150155 """
151156 self .all_capabilities = {
152157 "http_request" : HTTPRequest (self .host )}
153- self ._llm_handler = LLMHandler (self .llm , self ._capabilities , all_possible_capabilities = self .all_capabilities )
158+ self ._llm_handler = LLMHandler (self .llm , self ._capabilities . _capabilities , all_possible_capabilities = self .all_capabilities )
154159
155160 self ._response_handler = ResponseHandler (llm_handler = self ._llm_handler , prompt_context = self ._prompt_context ,
156161 prompt_helper = self .prompt_helper , config = config )
@@ -226,25 +231,6 @@ def categorize_endpoints(self, endpoints, query: dict):
226231 "multi-level_resource" : multi_level_resource ,
227232 }
228233
229-
230-
231- def _setup_capabilities (self ):
232- """
233- Initializes the LLM agent's capabilities for interacting with the API.
234-
235- This sets up tool wrappers that the language model can call, such as:
236- - `http_request`: For performing HTTP calls against the target API.
237- - `record_note`: For storing observations, notes, or documentation artifacts.
238-
239- Side Effects:
240- - Populates `self._capabilities` with callable tools used during exploration and documentation.
241- """
242- """Initializes agent's capabilities for API documentation."""
243- self ._capabilities = {
244- "http_request" : HTTPRequest (self .host ),
245- "record_note" : RecordNote (self ._context ["notes" ])
246- }
247-
248234 def all_http_methods_found (self , turn : int ) -> bool :
249235 """
250236 Checks whether all expected HTTP methods (GET, POST, PUT, DELETE) have been discovered
@@ -441,10 +427,4 @@ def run_documentation(self, turn: int, move_type: str) -> None:
441427 self ._evaluator .finalize_documentation_metrics (
442428 file_path = self ._documentation_handler .file .split (".yaml" )[0 ] + ".txt" )
443429
444- self .all_http_methods_found (turn )
445-
446-
447- @use_case ("Minimal implementation of a web API testing use case" )
448- class SimpleWebAPIDocumentationUseCase (AutonomousAgentUseCase [SimpleWebAPIDocumentation ]):
449- """Use case for the SimpleWebAPIDocumentation agent."""
450- pass
430+ self .all_http_methods_found (turn )
0 commit comments