Skip to content

Commit

Permalink
Merge branch 'main' of github.com:TransformerOptimus/SuperAGI into to…
Browse files Browse the repository at this point in the history
…ols_logic
  • Loading branch information
COLONAYUSH committed May 18, 2023
2 parents ab5864c + 2a6fd5d commit 0761060
Show file tree
Hide file tree
Showing 14 changed files with 428 additions and 83 deletions.
75 changes: 58 additions & 17 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,89 @@
° [![Join our Discord Server](https://img.shields.io/badge/Discord-SuperAGI-blueviolet?logo=discord&logoColor=white)](https://discord.gg/dXbRe5BHJC) ° [![Follow us on Twitter](https://img.shields.io/twitter/follow/_superAGI?label=_superAGI&style=social)](https://twitter.com/_superAGI) ° [![Join the discussion on Reddit](https://img.shields.io/reddit/subreddit-subscribers/Super_AGI?label=%2Fr/Super_AGI&style=social)](https://www.reddit.com/r/Super_AGI)
</p>

### *Infrastructure for building useful Autonomous Agents*
### *Infrastructure for building useful Autonomous Agents *

## 💡Features
# 💡 Features

### 🚀**Provision, Spawn & Deploy Autonomous AI Agents**
### 🚀 **Provision, Spawn & Deploy Autonomous AI Agents**
Seamless provision and run agents

### 🛠️**Extend Agent Capabilities with Tools**
### 🛠️ **Extend Agent Capabilities with Tools**
Give capabilities to your agents by selecting tools from growing library or build your own custom tool

### 🔄**Run Concurrent Agents Seamlessly**
### 🔄 **Run Concurrent Agents Seamlessly**
Run agents concurrently

### 🔓**Open Source:**
### 🔓 **Open Source:**
SuperAGI is an open-source platform, enabling developers to join a community of contributors constantly working to make it better.

### 🖥️**GUI:**
### 🖥️ **GUI:**
Access your agents through a user-friendly graphical interface, simplifying agent management and interaction.

### ⌨️**Action Console:**
### ⌨️ **Action Console:**
Interact with agents by providing input, permissions, and more.

### 📊**Multiple Vector DBs:**
### 📊 **Multiple Vector DBs:**
Connect to multiple Vector DBs to enhance your agent's performance and access additional data sources.

### 🤖**Multi-Model Agents:**
### 🤖 **Multi-Model Agents:**
Customize your agents by using different models of your choice, tailoring their behavior to specific tasks.

### 🎯**Agent Trajectory Fine-Tuning:**
### 🎯 **Agent Trajectory Fine-Tuning:**
Agents learn and improve their performance over time through feedback loops, allowing for fine-tuning and optimization.

### 📈**Performance Telemetry:**
### 📈 **Performance Telemetry:**
Gain insights into your agent's performance through telemetry data, enabling optimization and improvement.

### 💰**Optimized Token Usage:**
### 💰 **Optimized Token Usage:**
Control token usage to effectively manage costs associated with the platform.

### 🧠**Agent Memory Storage:**
### 🧠 **Agent Memory Storage:**
Enable agents to learn and adapt by storing their memory, facilitating continuous improvement.

### 🔁**Looping Detection Heuristics:**
### 🔁 **Looping Detection Heuristics:**
Receive notifications when agents get stuck in a loop and take proactive measures to resolve the issue.

### 🚀**Concurrent Agents:**
### 🚀 **Concurrent Agents:**
Run multiple agents simultaneously, maximizing efficiency and achieving parallel processing.

### 💾**Resource Manager:**
### 💾 **Resource Manager:**
Read and store files generated by agents, facilitating data management and analysis.

# 🛣 Roadmap
[Click here to checkout the latest roadmap 🔗](https://github.com/TransformerOptimus/SuperAGI/wiki/Roadmap-%F0%9F%9B%A3)

# ⚙️ Setting up

1. Download the repo using `git clone https://github.com/TransformerOptimus/SuperAGI.git` in your terminal or directly from github page in zip format and unzip in your desired folder
2. Navigate to the directory where you downloaded the repository `cd SuperAGI`

# 🛠 Configuration

1. Find the file named .env.template in the main SuperAGI folder. This file may be hidden by default in some operating systems due to the dot prefix. To reveal hidden files, follow the instructions for your specific operating system: [Windows](https://support.microsoft.com/en-us/windows/view-hidden-files-and-folders-in-windows-97fbc472-c603-9d90-91d0-1166d1d9f4b5), [macOS](https://www.pcmag.com/how-to/how-to-access-your-macs-hidden-files).
2. Create a copy of .env.template and call it .env; if you're already in a command prompt/terminal window: cp .env.template .env.
Open the .env file in a text editor.
3. Find the line that says OPENAI_API_KEY=.
4. After the =, enter your unique OpenAI API Key without any quotes or spaces.
5. Enter any other API keys or tokens for services you would like to use.
6. Save and close the .env file

# 🏃‍♂️ Running SuperAGI
Simply run the startup script in your terminal. This will install any necessary Python packages and launch SuperAGI

* On Linux/MacOS:
`./run.sh`
* On Windows:
`.\run.bat`
> If this gives errors, make sure you have a compatible Python version installed.
# ⚠️ Under Development!
This project is under active development and may still have issues. We appreciate your understanding and patience. If you encounter any problems, please first check the open issues. If your issue is not listed, kindly create a new issue detailing the error or problem you experienced. Thank you for your support!


# 👩‍💻Contributors
[![TransformerOptimus](https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/133493246?v=4&w=50&h=50&mask=circle)](https://github.com/TransformerOptimus) [![Cptsnowcrasher](https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/133322218?v=4&w=50&h=50&mask=circle)](https://github.com/Cptsnowcrasher) [![vectorcrow](https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/133646556?v=4&w=50&h=50&mask=circle)](https://github.com/vectorcrow) [![Akki-jain](https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/92881074?v=4&w=50&h=50&mask=circle)](https://github.com/Akki-jain) [![Autocop-Agent](https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/129729746?v=4&w=50&h=50&mask=circle)](https://github.com/Autocop-Agent)

# ⭐Star History

[![Star History Chart](https://api.star-history.com/svg?repos=TransformerOptimus/SuperAGI&type=Date)](https://star-history.com/#TransformerOptimus/SuperAGI&Date)
28 changes: 0 additions & 28 deletions superagi/agent/agent_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,5 @@ def __int__(self) -> None:
self.evaluations: List[str] = []
self.response_format: str = ""

def construct_full_prompt(self) -> str:
# Construct full prompt
full_prompt = (
f"You are {self.ai_name}, {self.ai_role}\n{self.base_prompt}\n\nGOALS:\n\n"
)
for i, goal in enumerate(self.goals):
full_prompt += f"{i + 1}. {goal}\n"

for i, goal in enumerate(self.goals):
full_prompt += f"{i + 1}. {goal}\n"

full_prompt += f"\n\n{get_prompt(self.tools)}"
return full_prompt

def build_agent_prompt(self):
agent_prompt = AgentPrompt()
prompt_start = (
"Your decisions must always be made independently "
"without seeking user assistance.\n"
"Play to your strengths as an LLM and pursue simple "
"strategies with no legal complications.\n"
"If you have completed all your tasks, make sure to "
'use the "finish" command.'
)
agent_prompt.set_base_system_prompt(prompt_start)
agent_prompt.goals(prompt_start)




88 changes: 58 additions & 30 deletions superagi/agent/agent_prompt_builder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from pydantic.types import List

from superagi.agent.agent_prompt import AgentPrompt
from superagi.tools.base_tool import BaseTool


class AgentPromptBuilder:
def __init__(self, agent):
self.agent_prompt = AgentPrompt()

def set_ai_name(self, ai_name):
self.agent_prompt.ai_name = ai_name

def set_ai_role(self, ai_role):
self.agent_prompt.ai_role = ai_role

def set_base_prompt(self, base_prompt):
self.agent_prompt.set_base_system_prompt(base_prompt)

Expand All @@ -26,24 +35,43 @@ def add_evaluation(self, evaluation: str) -> None:
def set_response_format(self, response_format: str) -> None:
self.agent_prompt.set_response_format(response_format)


def build_agent_prompt(self):
agent_prompt = AgentPrompt()
prompt_start = (
"Your decisions must always be made independently "
"without seeking user assistance.\n"
"Play to your strengths as an LLM and pursue simple "
"strategies with no legal complications.\n"
"If you have completed all your tasks, make sure to "
'use the "finish" command.'
)
agent_prompt.set_base_system_prompt(prompt_start)
agent_prompt.goals(prompt_start)
def generate_prompt_string(self):
final_string = ""
final_string += f"I am {self.agent_prompt.ai_name}. My role is {self.agent_prompt.ai_role}\n"
final_string += self.agent_prompt.base_system_prompt
final_string += "\n\n"
final_string += "Goals:\n"
for goal in self.agent_prompt.goals:
final_string += f"- {goal}\n"
final_string += "\n"
final_string += "Constraints:\n"
for constraint in self.agent_prompt.constraints:
final_string += f"- {constraint}\n"
final_string += "\n"
final_string += "Tools:\n"
for tool in self.agent_prompt.tools:
final_string += f"- {tool.name}\n"
final_string += "\n"
final_string += "Resources:\n"
for resource in self.agent_prompt.resources:
final_string += f"- {resource}\n"
final_string += "\n"
final_string += "Evaluations:\n"
for evaluation in self.agent_prompt.evaluations:
final_string += f"- {evaluation}\n"
final_string += "\n"
final_string += "Response Format:\n"
final_string += f"- {self.agent_prompt.response_format}\n"

final_string += "Ensure the response can be parsed by Python json.loads\n"
return final_string

@classmethod
def get_autogpt_prompt(cls) -> str:
def get_autogpt_prompt(cls, ai_name:str, ai_role: str, tools: List[BaseTool]) -> str:
# Initialize the PromptGenerator object
prompt_builder = AgentPromptBuilder()
prompt_builder.set_ai_name(ai_name)
prompt_builder.set_ai_role(ai_role)
base_prompt = (
"Your decisions must always be made independently "
"without seeking user assistance.\n"
Expand All @@ -56,23 +84,23 @@ def get_autogpt_prompt(cls) -> str:

# Add constraints to the PromptGenerator object
prompt_builder.add_constraint(
"~4000 word limit for short term memory. "
"Your short term memory is short, "
"so immediately save important information to files."
"~4000 word limit for short term memory. "
"Your short term memory is short, "
"so immediately save important information to files."
)
prompt_builder.add_constraint(
"If you are unsure how you previously did something "
"or want to recall past events, "
"thinking about similar events will help you remember."
"If you are unsure how you previously did something "
"or want to recall past events, "
"thinking about similar events will help you remember."
)
prompt_builder.add_constraint("No user assistance")
prompt_builder.add_constraint(
'Exclusively use the commands listed in double quotes e.g. "command name"'
'Exclusively use the commands listed in double quotes e.g. "command name"'
)

# Add commands to the PromptGenerator object
for tool in tools:
prompt_generator.add_tool(tool)
prompt_builder.add_tool(tool)

resources = ["Internet access for searches and information gathering.",
"Long Term memory management.",
Expand All @@ -83,17 +111,17 @@ def get_autogpt_prompt(cls) -> str:

# Add performance evaluations to the PromptGenerator object
evaluations = [
"Continuously review and analyze your actions "
"to ensure you are performing to the best of your abilities.",
"Constructively self-criticize your big-picture behavior constantly.",
"Reflect on past decisions and strategies to refine your approach.",
"Every command has a cost, so be smart and efficient. "
"Aim to complete tasks in the least number of steps.",
"Continuously review and analyze your actions "
"to ensure you are performing to the best of your abilities.",
"Constructively self-criticize your big-picture behavior constantly.",
"Reflect on past decisions and strategies to refine your approach.",
"Every command has a cost, so be smart and efficient. "
"Aim to complete tasks in the least number of steps.",
]
for evaluation in evaluations:
prompt_builder.add_evaluation(evaluation)

# Generate the prompt string
prompt_string = prompt_generator.generate_prompt_string()
prompt_string = prompt_builder.generate_prompt_string()

return prompt_string
return prompt_string
48 changes: 48 additions & 0 deletions superagi/agent/output_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json
from abc import ABC, abstractmethod
from typing import Dict, NamedTuple


class AgentGPTAction(NamedTuple):
name: str
args: Dict


class BaseOutputParser(ABC):
@abstractmethod
def parse(self, text: str) -> AutoGPTAction:
"""Return AgentGPTAction"""


def preprocess_json_input(input_str: str) -> str:
# Replace single backslashes with double backslashes,
# while leaving already escaped ones intact
corrected_str = re.sub(
r'(?<!\\)\\(?!["\\/bfnrt]|u[0-9a-fA-F]{4})', r"\\\\", input_str
)
return corrected_str


class AgentOutputParser(BaseOutputParser):
def parse(self, text: str) -> AgentGPTAction:
try:
parsed = json.loads(text, strict=False)
except json.JSONDecodeError:
preprocessed_text = preprocess_json_input(text)
try:
parsed = json.loads(preprocessed_text, strict=False)
except Exception:
return AgentGPTAction(
name="ERROR",
args={"error": f"Could not parse invalid json: {text}"},
)
try:
return AgentGPTAction(
name=parsed["command"]["name"],
args=parsed["command"]["args"],
)
except (KeyError, TypeError):
# If the command is null or incomplete, return an erroneous tool
return AgentGPTAction(
name="ERROR", args={"error": f"Incomplete command args: {parsed}"}
)
Loading

0 comments on commit 0761060

Please sign in to comment.