Skip to content

Commit

Permalink
[FEAT][Create agents]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Apr 9, 2024
1 parent b755499 commit b36d0cf
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Swarm Orchestrator_state.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"agent_id": "<function agent_id at 0x12ecd6980>",
"agent_id": "<function agent_id at 0x133b7eb60>",
"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",
"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 problem into manageable components\",\n \"Build a 'divide and conquer' team\",\n \"Assign components to experts\",\n \"Regroup and integrate\"\n ],\n \"number_of_agents\": 10,\n \"agents\": [\n {\n \"name\": \"Computer Vision Agent\",\n \"system_prompt\": \"Object detection, recognition, and tracking\"\n },\n {\n \"name\": \"Localization Agent\",\n \"system_prompt\": \"Situational awareness, map data, geospatial positioning\"\n },\n {\n \"name\": \"Planning and Control Agent\", \n \"system_prompt\": \"Navigation, route planning, maneuvering\"\n },\n {\n \"name\": \"Sensors and Perception Agent\",\n \"system_prompt\": \"Integrate data from sensors like cameras, lidar etc.\"\n },\n {\n \"name\": \"Connectivity Agent\",\n \"system_prompt\": \"V2V and V2I communication protocols\"\n },\n {\n \"name\": \"Human Interaction Agent\",\n \"system_prompt\": \"Speech recognition and synthesis\" \n },\n {\n \"name\": \"AI and ML Agent\",\n \"system_prompt\": \"Continuous learning and model optimization\"\n }, \n {\n \"name\": \"Simulation Agent\", \n \"system_prompt\": \"Test efficacy and safety through simulations\"\n },\n {\n \"name\": \"Validation and Verification Agent\",\n \"system_prompt\": \"Rigorously test and validate all components\" \n },\n {\n \"name\": \"System Integration Agent\",\n \"system_prompt\": \"Coordinate efforts to deliver fully integrated system\"\n }\n ]\n}\n```\n\nI've created a team of 10 agents, each focused on a key aspect of developing an AI for self-driving vehicles. The plan involves decomposing the problem, assigning components to specialized agents, then re-integrating. I included name, system prompt and responsibility for each proposed agent. Let me know if you need any clarification or have additional requirements!\n\n",
"loop_interval": 0,
"retry_attempts": 3,
"retry_interval": 1,
Expand Down
Empty file added errors.txt
Empty file.
6 changes: 4 additions & 2 deletions neo_sapiens/few_shot_prompts.py → few_shot_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
}
"""


def merge_fewshots_into_str(
plan: List[str] = [data, data1, data2, data3, data5]
) -> str:
Expand All @@ -141,7 +142,6 @@ def merge_fewshots_into_str(
return "\n".join(plan)



def orchestrator_prompt_agent(objective: str):
prompt = (
"Create an instruction prompt for an swarm orchestrator to"
Expand All @@ -153,6 +153,8 @@ def orchestrator_prompt_agent(objective: str):
" 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}"
" say only return JSON data in markdown and nothing else."
f" Here are some examples: {data5} Follow the schema here:"
f" {data}"
)
return str(prompt)
90 changes: 52 additions & 38 deletions neo_sapiens/hass_schema.py → hass_schema.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import json
import os
from dotenv import load_dotenv
import re
from typing import List

from dotenv import load_dotenv
from pydantic import BaseModel, Field
from swarms import Agent, Anthropic
from swarms.utils.json_utils import base_model_to_json
from neo_sapiens.few_shot_prompts import orchestrator_prompt_agent
from neo_sapiens.few_shot_prompts import (
from swarms import Agent, Anthropic, SwarmNetwork

from few_shot_prompts import (
data,
data1,
data2,
data3,
orchestrator_prompt_agent,
)

# from neo_sapiens.main import browser, terminal
from swarms import SwarmNetwork
from swarms.utils.parse_code import extract_code_from_markdown

# Load environment variables
load_dotenv()

Expand Down Expand Up @@ -104,25 +101,28 @@ class HassSchema(BaseModel):
# )


# 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:
"""
Parses the Home Assistant schema data and returns a tuple containing the plan,
number of agents, and the agents themselves.
Args:
data (str): The Home Assistant schema data to be parsed.
Returns:
tuple: A tuple containing the plan, number of agents, and the agents themselves.
"""
parsed_data = json.loads(data)
hass_schema = HassSchema(**parsed_data)
# import json
def parse_json_from_input(input_str):
# Validate input is not None or empty
if not input_str:
print("Error: Input string is None or empty.")
return None, None, None

# Attempt to extract JSON from markdown using regular expression
json_pattern = re.compile(r"```json\n(.*?)\n```", re.DOTALL)
match = json_pattern.search(input_str)
json_str = match.group(1).strip() if match else input_str.strip()
# print(json_str)

# Attempt to parse the JSON string
try:
data = json.loads(json_str)
# print(str(data))
except json.JSONDecodeError as e:
print(f"Error: JSON decoding failed with message '{e}'")
return None, None, None

hass_schema = HassSchema(**data)
return (
hass_schema.plan,
hass_schema.number_of_agents,
Expand All @@ -131,6 +131,9 @@ def parse_hass_schema(data: str) -> tuple:
)


# You can test the function with a markdown string similar to the one provided.


def merge_plans_into_str(
plan: List[str] = [data, data1, data2, data3]
) -> str:
Expand Down Expand Up @@ -228,8 +231,7 @@ def run_task(task: str = None):
None
"""
system_prompt_daddy = orchestrator_prompt_agent(task)
print(system_prompt_daddy)

# print(system_prompt_daddy)
agent = Agent(
agent_name="Swarm Orchestrator",
system_prompt=system_prompt_daddy,
Expand All @@ -244,19 +246,31 @@ def run_task(task: str = None):
stopping_token="<DONE>",
# interactive=True,
)
out = agent(task)
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
out = agent.run(task)
# print(out)
out = str(out)
print(f"Output: {out}")
out = parse_json_from_input(out)
print(str(out))
plan, number_of_agents, agents = out
print(agents)
agents = create_agents(agents)
print(agents)
return agents
# return agents
# print(out)
# json_template = extract_code_from_markdown(str(out))
# print(json_template)
# parsed_schema = parse_json_from_markdown(json_template)
# plan, number_of_agents, agents = parsed_schema
# print(f"Plan: {agents}")
# # agents = create_agents(agents)
# print(agents)
# return agents
return out


out = run_task(
"Create a team of AI engineers to create an AI for a"
" self-driving car"
)
print(out)
# print(out)
24 changes: 0 additions & 24 deletions neo_sapiens/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
from neo_sapiens.few_shot_prompts import (
data,
data1,
data2,
data3,
data5,
)
from neo_sapiens.hass_schema import (
parse_hass_schema,
merge_plans_into_str,
merge_rules_into_str,
)


__all__ = [
"data",
"data1",
"data2",
"data3",
"data5",
"parse_hass_schema",
"merge_plans_into_str",
"merge_rules_into_str",
]
71 changes: 51 additions & 20 deletions neo_sapiens/self driving.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@

{
"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."
}
]
}
"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."
),
},
],
}

0 comments on commit b36d0cf

Please sign in to comment.