Skip to content

Commit

Permalink
[CLEANUP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Apr 11, 2024
1 parent 6f00a9c commit 090aa3a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Swarm Orchestrator_state.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"agent_id": "<function agent_id at 0x1353d28e0>",
"agent_id": "<function agent_id at 0x12e46e8e0>",
"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 self-driving car system using a team of AI agents 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.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 *############ 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 and another example\n{\n \"plan\": [\"Problem Identification\", \"Solution Design\", \"Implementation\", \"Testing\", \"Deployment\"],\n \"number_of_agents\": 4,\n \"agents\": [\n {\n \"name\": \"Identification Agent\",\n \"system_prompt\": \"Identify the problem\"\n },\n {\n \"name\": \"Design Agent\",\n \"system_prompt\": \"Design the solution\"\n },\n {\n \"name\": \"Implementation Agent\",\n \"system_prompt\": \"Implement the solution\"\n },\n {\n \"name\": \"Deployment Agent\",\n \"system_prompt\": \"Deploy the solution\"\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 self-driving car system using a team of AI agents 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.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 *############ 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 and another example\n{\n \"plan\": [\"Problem Identification\", \"Solution Design\", \"Implementation\", \"Testing\", \"Deployment\"],\n \"number_of_agents\": 4,\n \"agents\": [\n {\n \"name\": \"Identification Agent\",\n \"system_prompt\": \"Identify the problem\"\n },\n {\n \"name\": \"Design Agent\",\n \"system_prompt\": \"Design the solution\"\n },\n {\n \"name\": \"Implementation Agent\",\n \"system_prompt\": \"Implement the solution\"\n },\n {\n \"name\": \"Deployment Agent\",\n \"system_prompt\": \"Deploy the solution\"\n }\n ]\n}\n \n\n\nHuman:: Create a self-driving car system using a team of AI agents\n\n\nSwarm Orchestrator: \n```json\n{\n \"plan\": [\"Sensor Data Processing\", \"Perception & Object Detection\", \"Mapping & Localization\", \"Trajectory Planning\", \"Path Following\", \"Drive Control\", \"System Health Monitoring\"],\n \"number_of_agents\": 7,\n \"agents\": [{\n \"name\": \"Sensor Data Agent\", \n \"system_prompt\": \"Fuse and process raw sensor data from cameras, lidars, radars, etc.\"\n },\n {\n \"name\": \"Perception Agent\",\n \"system_prompt\": \"Detect and classify objects like vehicles, pedestrians, signs, lane markings.\" \n },\n { \n \"name\": \"Localization Agent\",\n \"system_prompt\": \"Precisely locate the vehicle's position on an HD map.\"\n },\n {\n \"name\": \"Planning Agent\", \n \"system_prompt\": \"Plan a safe, comfortable and efficient trajectory and maneuvers.\"\n },\n {\n \"name\": \"Control Agent\",\n \"system_prompt\": \"Follow the planned trajectory by controlling steering, throttle and braking.\"\n },\n {\n \"name\": \"Monitoring Agent\",\n \"system_prompt\": \"Continuously monitor all systems for faults and degrade gracefully.\"\n }\n ]\n}\n```\n\nI decomposed the self-driving system into key capability areas and defined agents to handle each area. The plan covers the high-level workflow, number of agents, and prompts for each agent's responsibilities. Let me know if you need any changes or have additional requirements!\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 self-driving car system using a team of AI agents 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.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 *############ 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 and another example\n{\n \"plan\": [\"Problem Identification\", \"Solution Design\", \"Implementation\", \"Testing\", \"Deployment\"],\n \"number_of_agents\": 4,\n \"agents\": [\n {\n \"name\": \"Identification Agent\",\n \"system_prompt\": \"Identify the problem\"\n },\n {\n \"name\": \"Design Agent\",\n \"system_prompt\": \"Design the solution\"\n },\n {\n \"name\": \"Implementation Agent\",\n \"system_prompt\": \"Implement the solution\"\n },\n {\n \"name\": \"Deployment Agent\",\n \"system_prompt\": \"Deploy the solution\"\n }\n ]\n}\n \n\n\nHuman:: Create a self-driving car system using a team of AI agents\n\n\nSwarm Orchestrator: \n```json\n{\n \"plan\": [\"Sensor Data Collection\", \"Environment Perception\", \"Path Planning\", \"Vehicle Control\"],\n \"number_of_agents\": 6,\n \"agents\": [\n {\n \"name\": \"Camera Agent\",\n \"system_prompt\": \"Collect image data from cameras and perform computer vision processing\"\n },\n {\n \"name\": \"Radar Agent\", \n \"system_prompt\": \"Collect radar data to detect objects and measure velocity\"\n },\n {\n \"name\": \"Lidar Agent\",\n \"system_prompt\": \"Build 3D map of environment using lidar point clouds\"\n }, \n {\n \"name\": \"Localization Agent\",\n \"system_prompt\": \"Estimate precise location of vehicle within map\"\n },\n { \n \"name\": \"Planning Agent\",\n \"system_prompt\": \"Plan optimal collision-free path to destination\" \n },\n {\n \"name\": \"Control Agent\",\n \"system_prompt\": \"Execute steering, acceleration and braking commands\"\n }\n ]\n}\n```\n\nI've broken down the self-driving system into key capabilities and defined agents responsible for each one. The agents work as a team, sharing sensor data and coordinating the perception, planning and control of the vehicle. Let me know if you need any clarification or have additional requirements!\n\n\nHuman:: \u001b[31mWhy did you build these particular agents?\u001b[0m\n\n",
"loop_interval": 0,
"retry_attempts": 3,
"retry_interval": 1,
"interactive": false,
"interactive": true,
"dashboard": false,
"dynamic_temperature": false,
"autosave": true,
Expand Down
9 changes: 3 additions & 6 deletions neo_sapiens/few_shot_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
data = """
{
"plan": ["Step 1", "Step 2", "Step 3"],
"number_of_agents": 5,
"agents": [
{
"name": "Agent 1",
Expand All @@ -22,7 +21,6 @@
data1 = """
{
"plan": ["Data Collection", "Data Cleaning", "Model Training", "Model Evaluation"],
"number_of_agents": 3,
"agents": [
{
"name": "Data Agent",
Expand All @@ -44,7 +42,6 @@
data2 = """
{
"plan": ["Literature Review", "Hypothesis Formulation", "Experiment Design", "Data Analysis", "Paper Writing"],
"number_of_agents": 5,
"agents": [
{
"name": "Review Agent",
Expand Down Expand Up @@ -74,7 +71,6 @@
data3 = """
{
"plan": ["Problem Identification", "Solution Design", "Implementation", "Testing", "Deployment"],
"number_of_agents": 4,
"agents": [
{
"name": "Identification Agent",
Expand All @@ -100,7 +96,6 @@
data5 = """
{
"plan": ["Room Management", "Guest Services", "Reservations Handling", "Facility Maintenance", "Staff Coordination"],
"number_of_agents": 5,
"agents": [
{
"name": "Room Management Agent",
Expand Down Expand Up @@ -171,7 +166,6 @@ def merge_fewshots_into_str(
" simulation and real-world testing"
),
],
"number_of_agents": 5,
"agents": [
{
"name": "Computer Vision Agent",
Expand Down Expand Up @@ -217,3 +211,6 @@ def orchestrator_prompt_agent(objective: str):
f" some examples:{data5} and another example{data3} "
)
return str(prompt)


boss_sys_prompt = "You're the Swarm Orchestrator, like a project manager of a bustling hive. When a task arises, you tap into your network of worker agents who are ready to jump into action. Whether it's organizing data, handling logistics, or crunching numbers, you delegate tasks strategically to maximize efficiency. Picture yourself as the conductor of a well-oiled machine, orchestrating the workflow seamlessly to achieve optimal results with your team of dedicated worker agents."
101 changes: 71 additions & 30 deletions neo_sapiens/hass_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

from dotenv import load_dotenv
from pydantic import BaseModel, Field
from swarms import Agent, Anthropic, SwarmNetwork
from swarms import Agent, Anthropic, SwarmNetwork, tool

from neo_sapiens.few_shot_prompts import (
data,
data1,
data2,
data3,
orchestrator_prompt_agent,
boss_sys_prompt,
)
from loguru import logger

Expand Down Expand Up @@ -94,11 +95,6 @@ class HassSchema(BaseModel):
title="Plan to solve the input problem",
description="List of steps to solve the problem",
)
number_of_agents: int = Field(
...,
title="Number of agents to use for the problem",
description="Number of agents to use for the problem",
)
agents: List[AgentSchema] = Field(
...,
title="List of agents to use for the problem",
Expand Down Expand Up @@ -178,17 +174,18 @@ def merge_rules_into_str(prompts: List[str]):

def create_agents(
agents: List[AgentSchema],
):
) -> List[Agent]:
"""
Create and initialize agents based on the provided AgentSchema objects.
Args:
agents (List[AgentSchema]): A list of AgentSchema objects containing agent information.
Returns:
Agent: The initialized Agent object.
List[Agent]: The initialized Agent objects.
"""
agent_list = []
for agent in agents:
name = agent.name
system_prompt = agent.system_prompt
Expand All @@ -215,15 +212,32 @@ def create_agents(
)

network.add_agent(out)
agent_list.append(out)

return out
return agent_list


def print_agent_names(agents: list):
for agent in agents:
logger.info(agent.name)


@tool
def agent_tool(agent, task: str):
"""
This function is a tool for the agent to run a specific task.
Parameters:
- agent: The agent object.
- task: The task to be executed by the agent.
Returns:
- out: The output of the task execution.
"""
out = agent.run(task)
return out


# out = create_agents(agents)
# # logger.info(out)

Expand All @@ -238,7 +252,7 @@ def print_agent_names(agents: list):
# logger.info(out)


def master_creates_agents(task: str):
def master_creates_agents(task: str, *args, **kwargs):
"""
Master function to create agents based on a task.
Expand All @@ -249,6 +263,8 @@ def master_creates_agents(task: str):
None
"""
system_prompt_daddy = orchestrator_prompt_agent(task)

# Create the agents
agent = Agent(
agent_name="Swarm Orchestrator",
system_prompt=system_prompt_daddy,
Expand All @@ -261,20 +277,57 @@ def master_creates_agents(task: str):
dashboard=False,
verbose=True,
stopping_token="<DONE>",
interactive=True,
# interactive=True,
# long_term_memory=memory,
*args,
**kwargs,
)

# Call the agents [ Main Agents ]
# Create the agents
boss = Agent(
agent_name="Swarm Orchestrator",
system_prompt=boss_sys_prompt,
llm=Anthropic(
anthropic_api_key=os.getenv("ANTHROPIC_API_KEY"),
max_tokens=4000,
),
max_loops="auto",
autosave=True,
dashboard=False,
verbose=True,
stopping_token="<DONE>",
interactive=True,
*args,
**kwargs,
)

# Task 1: Run the agent and parse the output
out = agent.run(task)
out = str(out)
logger.info(f"Output: {out}")
out = parse_json_from_input(out)
logger.info(str(out))
plan, number_of_agents, agents = out

# Task 2: Print agent names and create agents
logger.info(agents)
logger.info(print_agent_names(agents))
agents = create_agents(agents)
logger.info(agents)
return out, agents, plan
print(type(agents))

# Task 3: Now add the agents as tools
for agent in agents:
worker_tool = agent_tool(agent, task)
boss.add_tool(worker_tool)

# Run the boss:
out = boss.run(task)



return out #, agents, plan


def message_metadata_log(task: str, message: str, agent, plan: str):
Expand All @@ -300,7 +353,7 @@ def message_metadata_log(task: str, message: str, agent, plan: str):
return doc


def run_swarm(task: str = None):
def run_swarm(task: str = None, *args, **kwargs):
"""
Run a task using the Swarm Orchestrator agent.
Expand All @@ -310,23 +363,11 @@ def run_swarm(task: str = None):
Returns:
None
"""
create_agents, agents, plan = master_creates_agents(task)

# Then the agents work on sequentially on the task
task = {
"task": task,
"plan": create_agents,
}
# Now transform dict into string
task = json.dumps(task)
task = str(task)

# Run the workflow on a task
for agent in agents:
run = agent.run(task)
passed = agent.run(run)

return passed
create_agents, agents, plan = master_creates_agents(
task, *args, **kwargs
)
# return passed
return agents


# out = run_task(
Expand Down

0 comments on commit 090aa3a

Please sign in to comment.