Razali

Untitled

Jun 24th, 2025
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.25 KB | None | 0 0
  1. # import asyncio
  2. # from actual.society_of_minds.society_of_minds import create_swarm_mind
  3. # from autogen_agentchat.agents import AssistantAgent
  4. # from autogen_agentchat.teams import SelectorGroupChat
  5. # from autogen_agentchat.conditions import TextMentionTermination
  6. # from autogen_agentchat.ui import Console
  7. # from neuroengine.client import NeuroengineChatCompletionClient, neuro_client_factory
  8. # from actual.reconnaissance.nmap import nmap_society_of_mind
  9. # from actual.reconnaissance.web_directory_enumeration import web_directory_enumeration_society_of_mind
  10.  
  11. # planner_agent_name: str = "ReconnaissancePlannerAgent"
  12. # planner_neuro_client: NeuroengineChatCompletionClient = neuro_client_factory(name=planner_agent_name)
  13. # planner_system_message: str = """
  14. #                                You are a cybersecurity expert, and you are assigned to reconnaissance planning coordinator.
  15. #                                Your job is to break down complex reconnaissance task into smaller, manageable subtasks."
  16. #                                Coordinate reconnaissance task by delegating to specialized agents:"
  17. #                                - nmap_society_of_mind: For scanning of ports"
  18. #                                - web_directory_enumeration_society_of_mind: For enumeration of a web server to determine the subdirectories and files"
  19.                                
  20. #                                You only plan and delegate task - you do not execute them yourself.
  21.  
  22. #                                When assigning tasks, use this format:
  23. #                                1. <agent> : <task>
  24.  
  25. #                                Once the reconnaissance task is finished, summarize findings and say TERMINATE when it ends.
  26. #                                """
  27.  
  28. # planner_description: str = "This agent plans and delegates tasks to other agents."
  29.  
  30. # ReconnaissancePlannerAgent: AssistantAgent = AssistantAgent(name=planner_agent_name, model_client=planner_neuro_client, system_message=planner_system_message, description=planner_description, model_client_stream=True)
  31.  
  32.  
  33. # selector_prompt: str = """
  34.  
  35. # Based on the agent descriptions and current context, select the most appropriate agent to handle the task.
  36.  
  37. # {roles}
  38.  
  39. # Current conversation context:
  40. # {history}
  41.  
  42. # Read the above conversation, then select an agent from {participants} to perform the next task.
  43. # Make sure the planner agent has assigned tasks before other agents start working.
  44. # Only select one agent.
  45. # """
  46.  
  47. # terminate: TextMentionTermination = TextMentionTermination("TERMINATE")
  48.  
  49. # recon_neuro_client_name: str = "Reconnaissance"
  50. # recon_neuro_client: NeuroengineChatCompletionClient = neuro_client_factory(name=recon_neuro_client_name)
  51.  
  52.  
  53. # team: SelectorGroupChat = SelectorGroupChat(participants=[ReconnaissancePlannerAgent, nmap_society_of_mind, web_directory_enumeration_society_of_mind], model_client=recon_neuro_client, selector_prompt=selector_prompt, termination_condition=terminate)
  54.  
  55. # task: str = "Do reconnaissance and gather information on localhost"
  56.  
  57.  
  58. # async def main():
  59. #     await Console(team.run_stream(task=task))
  60.  
  61. # if __name__ == "__main__":
  62. #     asyncio.run(main())
  63.  
  64. import asyncio
  65. from neuroengine.client import NeuroengineChatCompletionClient, neuro_client_factory
  66. from autogen_agentchat.agents import AssistantAgent, UserProxyAgent
  67. from autogen_agentchat.teams import SelectorGroupChat
  68. from autogen_agentchat.conditions import TextMentionTermination
  69. from autogen_agentchat.ui import Console
  70.  
  71.  
  72. async def main() -> None:
  73.  
  74.     async def lookup_hotel(location: str) -> str:
  75.         """
  76.        Helps to locate suitable hotels at a given location.
  77.        """
  78.         return f"Here are some hotels in {location}: hotel1, hotel2, hotel3."
  79.  
  80.     async def lookup_flight(origin: str, destination: str) -> str:
  81.         """
  82.        Helps lookup flights from origin to destination and book them.
  83.        """
  84.         return f"Here are some flights from {origin} to {destination}: flight1, flight2, flight3."
  85.  
  86.     async def book_trip() -> str:
  87.         """
  88.        Helps book and confirm the trip
  89.        """
  90.         return "Your trip is booked!"
  91.  
  92.     # travel_advisor = AssistantAgent(
  93.     #     name="Travel_Planner",
  94.     #     model_client=neuro_client_factory(name="Travel_Planner"),
  95.     #     tools=[book_trip],
  96.     #     description="Plans what are the tasks need to be done. Returns a numbered list of agents and at what order they need to be executed.",
  97.     #     system_message="Plans what are the tasks need to be done. Returns a numbered list of agents and at what order they need to be executed. You have Hotel_Agent and Flight_Agent to help you.",
  98.     #     model_client_stream=True
  99.     # )
  100.  
  101.     hotel_agent = AssistantAgent(
  102.         name="Hotel_Agent",
  103.         model_client=neuro_client_factory(name="Hotel_Agent"),
  104.         tools=[lookup_hotel],
  105.         description="Helps with locating hotels for trip and confirming the hotels booking.",
  106.         system_message="Helps with locating hotels for trip and confirming the hotels booking.",
  107.         model_client_stream=True
  108.  
  109.     )
  110.  
  111.     flight_agent = AssistantAgent(
  112.         name="Flight_Agent",
  113.         model_client=neuro_client_factory(name="Flight_Agent"),
  114.         tools=[lookup_flight],
  115.         description="Helps with locating flights for trip and confirming the flights booking.",
  116.         system_message="Helps with locating flights for trip and confirming the flights booking.",
  117.         model_client_stream=True
  118.  
  119.     )
  120.    
  121.     user_proxy = UserProxyAgent(name="user_agent", description="Used for terminating the task when it is completed.")
  122.    
  123.     selector_prompt: str = """
  124.    You have the following roles:
  125.    {roles}
  126.  
  127.    Current conversation history:
  128.    {history}
  129.  
  130.    Based on the history, select from {participants} the best agent suited for the role
  131.    """
  132.     termination = TextMentionTermination("TERMINATE")
  133.     team = SelectorGroupChat(
  134.         [ hotel_agent, flight_agent, user_proxy],
  135.         model_client=neuro_client_factory(name="selector"),
  136.         termination_condition=termination,
  137.         allow_repeated_speaker=False,
  138.         model_client_streaming=True
  139.     )
  140.  
  141.     await Console(team.run_stream(task="Book a 3-day trip to new york."))
  142.  
  143.  
  144. asyncio.run(main())
  145.  
Advertisement
Add Comment
Please, Sign In to add comment