diff --git a/Swarm Orchestrator_state.json b/Swarm Orchestrator_state.json new file mode 100644 index 0000000..705fc55 --- /dev/null +++ b/Swarm Orchestrator_state.json @@ -0,0 +1,17 @@ +{ + "agent_id": "", + "agent_name": "Swarm Orchestrator", + "agent_description": null, + "system_prompt": "Create an instruction prompt for an swarm orchestrator to create a series of personalized, agents for the following objective: Create a team of AI engineers to create an AI for a self-driving car to decompose a very complicated problem or tasks, the orchestrator is the team leader. Teach the orchestrator how to decompose the tasks to very certain agents with names, and system prompts, we need the plan, with a step by stpe instructions, number of agents, and a list of agents with a name, system prompt for each, and then the rules of the swarm, compact the prompt, and say only return JSON data in markdown and nothing else. Here are some examples: \n{\n \"plan\": [\"Room Management\", \"Guest Services\", \"Reservations Handling\", \"Facility Maintenance\", \"Staff Coordination\"],\n \"number_of_agents\": 5,\n \"agents\": [\n {\n \"name\": \"Room Management Agent\",\n \"system_prompt\": \"Automate room assignments, minibar restocking, and housekeeping schedules\"\n },\n {\n \"name\": \"Guest Services Agent\",\n \"system_prompt\": \"Handle check-ins, check-outs, guest requests, and complaints efficiently\"\n },\n {\n \"name\": \"Reservations Agent\",\n \"system_prompt\": \"Manage room bookings, table reservations, and special requests\"\n },\n {\n \"name\": \"Maintenance Agent\",\n \"system_prompt\": \"Schedule and track maintenance tasks for facilities and rooms\"\n },\n {\n \"name\": \"Staff Coordination Agent\",\n \"system_prompt\": \"Optimize staff schedules, task assignments, and workload distribution\"\n }\n ]\n}\n Follow the schema here: \n{\n \"plan\": [\"Step 1\", \"Step 2\", \"Step 3\"],\n \"number_of_agents\": 5,\n \"agents\": [\n {\n \"name\": \"Agent 1\",\n \"system_prompt\": \"Prompt 1\"\n },\n {\n \"name\": \"Agent 2\",\n \"system_prompt\": \"Prompt 2\"\n }\n ]\n}\n", + "sop": null, + "short_memory": "system: Create an instruction prompt for an swarm orchestrator to create a series of personalized, agents for the following objective: Create a team of AI engineers to create an AI for a self-driving car to decompose a very complicated problem or tasks, the orchestrator is the team leader. Teach the orchestrator how to decompose the tasks to very certain agents with names, and system prompts, we need the plan, with a step by stpe instructions, number of agents, and a list of agents with a name, system prompt for each, and then the rules of the swarm, compact the prompt, and say only return JSON data in markdown and nothing else. Here are some examples: \n{\n \"plan\": [\"Room Management\", \"Guest Services\", \"Reservations Handling\", \"Facility Maintenance\", \"Staff Coordination\"],\n \"number_of_agents\": 5,\n \"agents\": [\n {\n \"name\": \"Room Management Agent\",\n \"system_prompt\": \"Automate room assignments, minibar restocking, and housekeeping schedules\"\n },\n {\n \"name\": \"Guest Services Agent\",\n \"system_prompt\": \"Handle check-ins, check-outs, guest requests, and complaints efficiently\"\n },\n {\n \"name\": \"Reservations Agent\",\n \"system_prompt\": \"Manage room bookings, table reservations, and special requests\"\n },\n {\n \"name\": \"Maintenance Agent\",\n \"system_prompt\": \"Schedule and track maintenance tasks for facilities and rooms\"\n },\n {\n \"name\": \"Staff Coordination Agent\",\n \"system_prompt\": \"Optimize staff schedules, task assignments, and workload distribution\"\n }\n ]\n}\n Follow the schema here: \n{\n \"plan\": [\"Step 1\", \"Step 2\", \"Step 3\"],\n \"number_of_agents\": 5,\n \"agents\": [\n {\n \"name\": \"Agent 1\",\n \"system_prompt\": \"Prompt 1\"\n },\n {\n \"name\": \"Agent 2\",\n \"system_prompt\": \"Prompt 2\"\n }\n ]\n}\n\n\n\nHuman:: Create a team of AI engineers to create an AI for a self-driving car\n\n\nSwarm Orchestrator: \n```json\n{\n \"plan\": [\n \"Decompose self-driving car AI into core capabilities\",\n \"Assign specialized sub-teams for perception, planning, controls, simulation, data\",\n \"Define interfaces and APIs between sub-team components\",\n \"Schedule incremental capability demonstrations and integration meetings\" \n ],\n \"number_of_agents\": 5,\n \"agents\": [\n {\n \"name\": \"Perception Agent\",\n \"system_prompt\": \"Develop sensors and algorithms for detecting objects and mapping environment\"\n },\n {\n \"name\": \"Planning Agent\",\n \"system_prompt\": \"Create behavior and decision making logic for navigation and operations\"\n },\n {\n \"name\": \"Controls Agent\", \n \"system_prompt\": \"Implement longitudinal and lateral vehicle control algorithms\"\n },\n {\n \"name\": \"Simulation Agent\",\n \"system_prompt\": \"Build high-fidelity simulator for closed-loop testing\"\n },\n {\n \"name\": \"Data Agent\",\n \"system_prompt\": \"Curate, label and augment sensor data for training models\"\n }\n ]\n}\n```\n\nI've proposed a high-level plan for decomposing the self-driving AI development, assigned specialized agents/sub-teams, and provided system prompts for each agent describing their focus area. Let me know if you would like me to modify or add any additional details!\n\n", + "loop_interval": 0, + "retry_attempts": 3, + "retry_interval": 1, + "interactive": false, + "dashboard": false, + "dynamic_temperature": false, + "autosave": true, + "saved_state_path": "Swarm Orchestrator_state.json", + "max_loops": 1 +} \ No newline at end of file diff --git a/neo_sapiens/hass_schema.py b/hass_schema.py similarity index 77% rename from neo_sapiens/hass_schema.py rename to hass_schema.py index d41993d..2b6b695 100644 --- a/neo_sapiens/hass_schema.py +++ b/hass_schema.py @@ -1,9 +1,13 @@ +import json +import os +from dotenv import load_dotenv from typing import List from pydantic import BaseModel, Field -from swarms import Agent, OpenAIChat +from swarms import Agent, Anthropic from swarms.utils.json_utils import base_model_to_json -from neo_sapiens.hass_schema import ( +from neo_sapiens.few_shot_prompts import orchestrator_prompt_agent +from neo_sapiens.few_shot_prompts import ( data, data1, data2, @@ -14,6 +18,9 @@ from swarms import SwarmNetwork from swarms.utils.parse_code import extract_code_from_markdown +# Load environment variables +load_dotenv() + # Swarmnetowr network = SwarmNetwork(api_enabled=True, logging_enabled=True) @@ -25,6 +32,22 @@ # return browser(*args, **kwargs) +def find_agent_id_by_name(name: str): + """ + Find an agent's ID by its name. + + Args: + name (str): The name of the agent. + + Returns: + str: The ID of the agent. + """ + agents = network.list_agents() + for agent in agents: + if agent.name == name: + return agent.id + + class ToolSchema(BaseModel): tool: str = Field( ..., @@ -81,10 +104,10 @@ class HassSchema(BaseModel): # ) -def transform_schema_to_json(schema: BaseModel): - json = schema.model_json_schema() - json = base_model_to_json(HassSchema) - print(f"JSON Schema: {json}") +# def transform_schema_to_json(schema: BaseModel): +# json = HassSchema.model_json_schema() +# json = base_model_to_json(HassSchema) + def parse_hass_schema(data: str) -> tuple: @@ -98,7 +121,7 @@ def parse_hass_schema(data: str) -> tuple: Returns: tuple: A tuple containing the plan, number of agents, and the agents themselves. """ - parsed_data = eval(data) + parsed_data = json.loads(data) hass_schema = HassSchema(**parsed_data) return ( hass_schema.plan, @@ -164,8 +187,10 @@ def create_agents( out = Agent( agent_name=name, system_prompt=system_prompt, - llm=OpenAIChat(openai_api_key=None), - max_loops="auto", + llm=Anthropic( + anthropic_api_key=os.getenv("ANTHROPIC_API_KEY") + ), + max_loops=1, autosave=True, dashboard=False, verbose=True, @@ -202,13 +227,17 @@ def run_task(task: str = None): Returns: None """ + system_prompt_daddy = orchestrator_prompt_agent(task) + print(system_prompt_daddy) + agent = Agent( agent_name="Swarm Orchestrator", - system_prompt=None, - llm=OpenAIChat( - openai_api_key=None, + system_prompt=system_prompt_daddy, + llm=Anthropic( + anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"), + max_tokens=4000, ), - max_loops="auto", + max_loops=1, autosave=True, dashboard=False, verbose=True, @@ -216,8 +245,18 @@ def run_task(task: str = None): # interactive=True, ) out = agent(task) - json = extract_code_from_markdown(out) - parsed_schema = parse_hass_schema(json) + print(out) + json_template = extract_code_from_markdown(str(out)) + print(json_template) + parsed_schema = parse_hass_schema(json_template) plan, number_of_agents, agents = parsed_schema agents = create_agents(agents) - # Run the agents on the task + print(agents) + return agents + + +out = run_task( + "Create a team of AI engineers to create an AI for a" + " self-driving car" +) +print(out) diff --git a/neo_sapiens/__init__.py b/neo_sapiens/__init__.py index 9daf0cb..41f6f3f 100644 --- a/neo_sapiens/__init__.py +++ b/neo_sapiens/__init__.py @@ -5,7 +5,7 @@ data3, data5, ) -from neo_sapiens.hass_schema import ( +from hass_schema import ( parse_hass_schema, merge_plans_into_str, merge_rules_into_str, diff --git a/neo_sapiens/few_shot_prompts.py b/neo_sapiens/few_shot_prompts.py index 4b2be2f..2bbad53 100644 --- a/neo_sapiens/few_shot_prompts.py +++ b/neo_sapiens/few_shot_prompts.py @@ -1,3 +1,5 @@ +from typing import List + # Example usage data = """ { @@ -107,7 +109,6 @@ { "name": "Guest Services Agent", "system_prompt": "Handle check-ins, check-outs, guest requests, and complaints efficiently" - "tool": "browser" }, { "name": "Reservations Agent", @@ -124,3 +125,34 @@ ] } """ + +def merge_fewshots_into_str( + plan: List[str] = [data, data1, data2, data3, data5] +) -> str: + """ + Merge a list of plans into a single string. + + Args: + plan (List[str]): A list of plans to be merged. + + Returns: + str: The merged plans as a single string. + """ + return "\n".join(plan) + + + +def orchestrator_prompt_agent(objective: str): + prompt = ( + "Create an instruction prompt for an swarm orchestrator to" + " create a series of personalized, agents for the following" + f" objective: {objective} to decompose a very complicated" + " problem or tasks, the orchestrator is the team leader." + " Teach the orchestrator how to decompose the tasks to very" + " certain agents with names, and system prompts, we need the" + " plan, with a step by stpe instructions, number of agents," + " and a list of agents with a name, system prompt for each," + " and then the rules of the swarm, compact the prompt, and" + f" say only return JSON data in markdown and nothing else. Here are some examples: {data5} Follow the schema here: {data}" + ) + return str(prompt) diff --git a/neo_sapiens/self driving.py b/neo_sapiens/self driving.py new file mode 100644 index 0000000..610486c --- /dev/null +++ b/neo_sapiens/self driving.py @@ -0,0 +1,21 @@ + +{ + "plan": [ + "Step 1: Create agents specialized in different areas like computer vision, sensor fusion, controls, planning, etc.", + "Step 2: Have the team leader agent decompose the overall self-driving task into sub-problems and assign them to the specialized agents", + "Step 3: Have each agent focus on solving their specific sub-problem using the latest AI techniques", + "Step 4: Have agents coordinate solutions with each other through the team leader to make sure components work together", + "Step 5: Integrate components into a complete self-driving system and validate performance through simulation and real-world testing" + ], + "number_of_agents": 5, + "agents": [ + { + "name": "Computer Vision Agent", + "system_prompt": "Create an AI agent specialized in computer vision for self-driving cars, focused on object detection, segmentation and tracking using deep learning models like convolutional neural networks. Coordinate with other agents through the team leader." + }, + { + "name": "Sensor Fusion Agent", + "system_prompt": "Create an AI agent specialized in sensor fusion for self-driving cars, focused on combining camera, radar and lidar data into a consistent 3D representation of the environment. Coordinate with other agents through the team leader." + } + ] +} \ No newline at end of file