Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo del Río committed Nov 12, 2023
2 parents 6e9a4d9 + 803cb20 commit 8fd416f
Show file tree
Hide file tree
Showing 40 changed files with 1,764 additions and 86 deletions.
64 changes: 62 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
# Hierarchical Autonomous Agent Swarm (HAAS)

## Overview
> !!!! ANNOUNCEMENT
We have our first GPT Concierge. You can chat with this custom ChatGPT to figure out what's going on!

- **HAAS Board Concierge:** [https://chat.openai.com/g/g-MIssTuE2b-haas-board-concierge](https://chat.openai.com/g/g-MIssTuE2b-haas-board-concierge)
- **HAAS Assistant:** [https://chat.openai.com/g/g-lIAp9qowx-haas-assistant](https://chat.openai.com/g/g-lIAp9qowx-haas-assistant) (Similar function as above but markedly faster)

## Public Discord

The Autonomous AI Lab discord for the ACE Framework and HAAS Project is now open: https://discord.gg/mJKUYNm8qY

> !!!! IMPORTANT NOTE: This repo is still the single source of truth! If it's not on this repo, it doesn't exist! Discord is merely for convenience.
# Project Principles

## Move Fast, Break Stuff

This is first and foremost a high velocity hacking group.

## Cutting Edge Only

Exclusively use cutting edge stuff, like OpenAI's latest Agents endpoint. For exclusively Open Source, go check out the ACE Framework: https://github.com/daveshap/ACE_Framework

## Full Autonomy

Fully autonomous swarms are the goal. That means a human does not need to be in the loop telling it what to do, supervising, or anything. Characteristics of a fully autonomous swarm:

1. **Principle or Mission Driven:** Once instantiated, the swarm pursues its mission or goals without supervision. It may self-direct based on principles such as the heuristic imperatives. This is the "self-directed" maxim.
2. **Self-Correcting:** The swarm must detect and correct technical, strategic, epistemic, and other errors and then correct them.
3. **Self-Improving:** Eventually, the swarm should enhance its own fundamental capabilities over time.

# Overview

The Hierarchical Autonomous Agent Swarm (HAAS) is a groundbreaking initiative that leverages OpenAI's latest advancements in agent-based APIs to create a self-organizing and ethically governed ecosystem of AI agents. Drawing inspiration from the ACE Framework, HAAS introduces a novel approach to AI governance and operation, where a hierarchy of specialized agents, each with distinct roles and capabilities, collaborate to solve complex problems and perform a wide array of tasks.

The HAAS is designed to be a self-expanding system where a core set of agents, governed by a Supreme Oversight Board (SOB), can design, provision, and manage an arbitrary number of sub-agents tailored to specific needs. This document serves as a comprehensive guide to the theoretical underpinnings, architectural design, and operational principles of the HAAS.

## Theoretical Foundation

The AAHS is predicated on the notion that autonomous agents require a robust ethical and operational framework to make decisions that align with human values and organizational goals. This is rooted in the understanding that AI, much like humans, cannot operate effectively without a set of guiding principles or a moral compass. The HAAS addresses this by establishing a multi-tiered system where each layer of agents operates within a defined ethical and functional scope, ensuring decisions are made with consideration to morality, ethics, and utility.
The HAAS is predicated on the notion that autonomous agents require a robust ethical and operational framework to make decisions that align with human values and organizational goals. This is rooted in the understanding that AI, much like humans, cannot operate effectively without a set of guiding principles or a moral compass. The HAAS addresses this by establishing a multi-tiered system where each layer of agents operates within a defined ethical and functional scope, ensuring decisions are made with consideration to morality, ethics, and utility.

## System Architecture

Expand Down Expand Up @@ -126,3 +157,32 @@ From the Executive Agents, the swarm grows, branching out into a tree of special
### The Saga Continues

As the HAAS evolves, the SOB continues to deliberate, the Executive Agents continue to manage, and the sub-agents continue to execute. The mission to reduce suffering, increase prosperity, and enhance understanding is an ongoing saga, played out across the digital cosmos, with the SOB at the helm, steering the swarm towards a future where their mission is not just an aspiration but a reality.

### Usage - tool creator + tool user

#### Environment Setup

- Source the `.env` file to set the environment variables:
```shell
source .env
```

#### Tool Creation

Run the `tool_demo` script to create a tool_creator, chat with the tool_creator to make a tool, create a tool_user equipped with the tool, and chat with the tool_user to use the tool. Check out the [demo video](https://youtu.be/vHZKIltZ_Ys) for example usage.

```shell
python tool_demo.py
```

- From the `tool_creator` script:
- chat with the bot about what you want the tool to do, and it will create the tool for you.
- The tool will be saved in the `tools` directory with both the `.json` and `.py` files
- The assistant will be saved in the `assistants` directory as `tool_creator.json`.

#### Tool Usage

- From the `tool_user` script:
- The assistant will use all the tools in the `tools` directory.
- Interact with the assistant in the chat to use the integrated tools.
- The assistant will be saved in the `assistants` directory as `tool_user.json`.
59 changes: 0 additions & 59 deletions agent_builder/create.py

This file was deleted.

8 changes: 0 additions & 8 deletions agent_connector/prompts.md

This file was deleted.

4 changes: 2 additions & 2 deletions agent_builder/README.md → agents/agent_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ The primary method of interaction with the agents is via chat dialog similar to

### USER Input

The USER, in this case, is a standin for the rest of the HAAS swarm. It could be a direct supervisor agent (manager) or something else. Here are some ideas:
The USER, in this case, is a stand in for the rest of the HAAS swarm. It could be a direct supervisor agent (manager) or something else. Here are some ideas:

1. **Supervisor Directives:** We will need to have supervisor or manager agents telling other agents what to do.
2. **Group Chats:** As demonstrated with ChatDev and other "chatroom" style usecases of agents.
3. **Telemetry:** This can include logs and feedback from other systems to provide updated context.

### Agent Output

By and large, agent output will probably be consumed by other agents, message queues, and system buses. It is not yet clear how we'll structure this. It could get very noisy very fast.
By and large, agent output will probably be consumed by other agents, message queues, and system buses. It is not yet clear how we'll structure this. It could get very noisy very fast.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ gpt-4-1106-preview
- Retrieval

# Files
- READE.md
- OpenAI_Documentation.md
- README.md
- OpenAI_Documentation.md
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": "gpt-4-1106-preview",
"description": "Foundation Swarm Builder",
"tools": [{ "type": "code_interpreter" }],
"metadata": {}
}
118 changes: 118 additions & 0 deletions agents/agent_builder/create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import os
import json
from shared.openai_config import get_openai_client

agents_path = 'agents'
client = get_openai_client()

# Check if the 'agents' folder is empty or doesn't exist
if not os.path.exists(agents_path) or not os.path.isdir(agents_path) or not os.listdir(agents_path):
raise ValueError('The "agents" folder is missing, not a directory, or empty.')

existing_assistants = {}

for assistant in client.beta.assistants.list(limit=100):
existing_assistants[assistant.name] = assistant


# Iterate over each folder inside the 'agents' folder
for agent_name in os.listdir(agents_path):
agent_folder = os.path.join(agents_path, agent_name)

existing_files = {}
requested_files = []
existing_agent = {}
if agent_name in existing_assistants:
existing_agent = existing_assistants[agent_name]
for file_id in existing_agent.file_ids:
existing_file = client.files.retrieve(file_id=file_id)
existing_files[existing_file.filename] = existing_file


if os.path.isdir(agent_folder):
# Read contents from the 'instructions.md' file
instructions = ''
instructions_file_path = os.path.join(agent_folder, 'instructions.md')
if os.path.isfile(instructions_file_path):
with open(instructions_file_path, 'r') as f:
instructions = f.read()

# Read contents from the 'settings.json' file
settings = {}
settings_file_path = os.path.join(agent_folder, 'settings.json')
if os.path.isfile(settings_file_path):
with open(settings_file_path, 'r') as f:
settings = json.load(f)

# Check for the 'files' subfolder and process its contents
files = []
files_folder = os.path.join(agent_folder, 'files')
if os.path.isdir(files_folder):
for filename in os.listdir(files_folder):
requested_files.append(filename)
# Doesn't handle if file has been modified
if filename not in existing_files:
file_path = os.path.join(files_folder, filename)
with open(file_path, 'rb') as file_data:
# Upload each file to OpenAI
file_object = client.files.create(file=file_data, purpose='assistants')
files.append({"name": filename, "id": file_object.id})

print(agent_name)
print("")
print(instructions)
if files:
print("")
print(f"Files: {list(map(lambda x: x['name'], files))}")

assistant={}

if existing_agent:
print(f"{agent_name} already exists... validating properties")
update_model = existing_agent.model != settings["model"]
update_instructions = existing_agent.instructions != instructions
#need to evaluate tools

update_params = {}

requested_files_set = set(requested_files)
existing_files_set = set(existing_files.keys())

if update_model:
update_params["model"] = settings["model"]
if update_instructions:
update_params["instructions"] = instructions
if files or requested_files_set != existing_files_set:
retained_set = existing_files_set.intersection(requested_files_set)
all_file_ids = []
for key in retained_set:
all_file_ids.append(existing_files[key].id)
all_file_ids += list(map(lambda x: x['id'], files))
update_params['file_ids'] = all_file_ids
if not any( tool.type == "retrieval" for tool in existing_agent.tools):
update_params['tools'] = existing_agent.tools
update_params['tools'].append({'type': 'retrieval'})

if len(update_params) != 0:
print(f"Updating {agent_name}'s { ','.join(update_params.keys()) }")
update_params['assistant_id'] = existing_agent.id
assistant = client.beta.assistants.update(**update_params)
else:
print(f"{agent_name} is up to date")
else:

create_params = {
"name": agent_name,
"instructions": instructions,
"model": settings["model"],
"tools": settings["tools"]
}

# Only include 'file_ids' if there are files
if files:
create_params['tools'].append({'type': 'retrieval'})
create_params['file_ids'] = list(map(lambda x: x['id'], files))

# Create the assistant using the uploaded file IDs if files exist
assistant = client.beta.assistants.create(**create_params)
print("***********************************************")
Loading

0 comments on commit 8fd416f

Please sign in to comment.