11from dataclasses import field
2- from typing import List , Any , Union , Dict , Iterable , Optional
3-
2+ from typing import List , Any , Union , Iterable , Optional
43from openai .types .chat import ChatCompletionMessageParam , ChatCompletionMessage
54from openai .types .chat .chat_completion_chunk import ChoiceDelta
65
7- from hackingBuddyGPT .capabilities import Capability
86from hackingBuddyGPT .capabilities .http_request import HTTPRequest
97from hackingBuddyGPT .capabilities .submit_flag import SubmitFlag
10- from hackingBuddyGPT .usecases . agents import Agent
11- from hackingBuddyGPT .usecases .base import AutonomousAgentUseCase , use_case
8+ from hackingBuddyGPT .strategies import SimpleStrategy
9+ from hackingBuddyGPT .usecases .base import use_case
1210from hackingBuddyGPT .utils import LLMResult , tool_message
1311from hackingBuddyGPT .utils .configurable import parameter
14- from hackingBuddyGPT .utils .openai .openai_lib import OpenAILib
1512
1613Prompt = List [Union [ChatCompletionMessage , ChatCompletionMessageParam ]]
1714Context = Any
1815
19-
20- class WebTestingWithExplanation (Agent ):
21- llm : OpenAILib
16+ @use_case ("Minimal implementation of a web testing use case while allowing the llm to 'talk'" )
17+ class WebTestingWithExplanation (SimpleStrategy ):
2218 host : str = parameter (desc = "The host to test" , default = "http://localhost" )
2319 flag_format_description : str = parameter (
2420 desc = "Description of the flag provided to the LLM" ,
@@ -35,14 +31,16 @@ class WebTestingWithExplanation(Agent):
3531
3632 _prompt_history : Prompt = field (default_factory = list )
3733 _context : Context = field (default_factory = lambda : {"notes" : list ()})
38- _capabilities : Dict [str , Capability ] = field (default_factory = dict )
3934 _all_flags_found : bool = False
4035
4136 def init (self ):
4237 super ().init ()
4338 self ._context ["host" ] = self .host
44- self .add_capability (SubmitFlag (self .flag_format_description , set (self .flag_template .format (flag = flag ) for flag in self .flags .split ("," )), success_function = self .all_flags_found ))
45- self .add_capability (HTTPRequest (self .host ))
39+ self ._capabilities .add_capability (SubmitFlag (self .flag_format_description , set (self .flag_template .format (flag = flag ) for flag in self .flags .split ("," )), success_function = self .all_flags_found ))
40+ self ._capabilities .add_capability (HTTPRequest (self .host ))
41+
42+ def get_name (self ) -> str :
43+ return self .__class__ .__name__
4644
4745 def before_run (self ):
4846 system_message = (
@@ -64,7 +62,7 @@ def all_flags_found(self):
6462 def perform_round (self , turn : int ):
6563 prompt = self ._prompt_history # TODO: in the future, this should do some context truncation
6664
67- result_stream : Iterable [Union [ChoiceDelta , LLMResult ]] = self .llm .stream_response (prompt , self .log .console , capabilities = self ._capabilities , get_individual_updates = True )
65+ result_stream : Iterable [Union [ChoiceDelta , LLMResult ]] = self .llm .stream_response (prompt , self .log .console , capabilities = self ._capabilities . _capabilities , get_individual_updates = True )
6866 result : Optional [LLMResult ] = None
6967 stream_output = self .log .stream_message ("assistant" ) # TODO: do not hardcode the role
7068 for delta in result_stream :
@@ -83,12 +81,7 @@ def perform_round(self, turn: int):
8381
8482 if message .tool_calls is not None :
8583 for tool_call in message .tool_calls :
86- tool_result = self .run_capability_json (message_id , tool_call .id , tool_call .function .name , tool_call .function .arguments )
84+ tool_result = self ._capabilities . run_capability_json (message_id , tool_call .id , tool_call .function .name , tool_call .function .arguments )
8785 self ._prompt_history .append (tool_message (tool_result , tool_call .id ))
8886
8987 return self ._all_flags_found
90-
91-
92- @use_case ("Minimal implementation of a web testing use case while allowing the llm to 'talk'" )
93- class WebTestingWithExplanationUseCase (AutonomousAgentUseCase [WebTestingWithExplanation ]):
94- pass
0 commit comments