From a5339935bd965460e5ef818e552fe9731c72fc2d Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Thu, 1 Aug 2024 15:49:21 -0400 Subject: [PATCH 1/7] modified readme files and documentation to meet the latest code --- README.md | 22 +++ .../academic_agent/academic_agent.py | 135 ++++++++++++++++++ openagi/src/tools/README.md | 3 + openagi/src/tools/base.py | 38 +++++ openagi/src/tools/offline/text_to_image.py | 20 +++ openagi/src/tools/online/README.md | 3 + openagi/src/utils/message.py | 20 +++ pyopenagi/README.md | 7 + pyopenagi/agents/README.md | 5 + pyopenagi/agents/agent_factory.py | 45 ++++++ pyopenagi/agents/agent_process.py | 55 ++++++- pyopenagi/agents/base_agent.py | 62 ++++++++ pyopenagi/agents/example/README.md | 4 + pyopenagi/agents/example/rag_agent/README.md | 14 ++ pyopenagi/tools/offline/README.md | 5 + pyopenagi/utils/README.md | 7 + pyopenagi/utils/compressor.py | 3 + pyopenagi/utils/logger.py | 9 ++ pyopenagi/utils/utils.py | 3 + setup.py | 10 ++ 20 files changed, 469 insertions(+), 1 deletion(-) create mode 100644 openagi/src/agents/native_agents/academic_agent/academic_agent.py create mode 100644 openagi/src/tools/README.md create mode 100644 openagi/src/tools/base.py create mode 100644 openagi/src/tools/offline/text_to_image.py create mode 100644 openagi/src/tools/online/README.md create mode 100644 openagi/src/utils/message.py create mode 100644 pyopenagi/README.md create mode 100644 pyopenagi/agents/README.md create mode 100644 pyopenagi/agents/example/README.md create mode 100644 pyopenagi/agents/example/rag_agent/README.md create mode 100644 pyopenagi/tools/offline/README.md create mode 100644 pyopenagi/utils/README.md create mode 100644 setup.py diff --git a/README.md b/README.md index ae79fce..b6239e0 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,28 @@ If you want to look at implementations of other agents that others have develope python pyopenagi/agents/interact.py --mode download --agent ``` +<<<<<<< HEAD +======= +## 2. Contributing + +### 2.1 Documentation +Each source directory contains a README.md file that explains what the files in that directory do. Additionally, each file has a header that describes the file's purpose. All comments follow the same styling documented in [AIOS](https://github.com/agiresearch/AIOS). + +### 2.2 Running tests +Run tests: Add your test code into the tests/ directory if any, then run test via pytest +``` +cd openagi +pytest -v tests +``` +sample output +``` +============================================================================================================================= test session starts ============================================================================================================================== +platform darwin -- Python 3.11.9, pytest-8.1.1, pluggy-1.5.0 -- "" +cachedir: .pytest_cache +rootdir: "" +plugins: anyio-4.3.0 +collected 2 items +>>>>>>> 00c34a4 (added readme files in each directory for source documentation) ## 🚀 Contributions For detailed information on how to contribute, see [CONTRIBUTE](./CONTRIBUTE.md). If you would like to contribute to the codebase, [issues](https://github.com/agiresearch/OpenAGI/issues) or [pull requests](https://github.com/agiresearch/OpenAGI/pulls) are always welcome! diff --git a/openagi/src/agents/native_agents/academic_agent/academic_agent.py b/openagi/src/agents/native_agents/academic_agent/academic_agent.py new file mode 100644 index 0000000..9eec16e --- /dev/null +++ b/openagi/src/agents/native_agents/academic_agent/academic_agent.py @@ -0,0 +1,135 @@ +# agent that provides accurate academic summarization agent + +from ...base import BaseAgent + +import time + +from ...agent_process import ( + AgentProcess +) + +import numpy as np + +import argparse + +from concurrent.futures import as_completed + +from ....utils.message import Message + +from ....tools.online.arxiv import Arxiv + +from ....tools.online.wikipedia import Wikipedia + +import json + +class AcademicAgent(BaseAgent): + def __init__(self, + agent_name, + task_input, + llm, + agent_process_queue, + agent_process_factory, + log_mode: str + ): + BaseAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) + + # doesn't use Wikipedia yet + self.tool_list = { + "arxiv": Arxiv() + } + + self.workflow = self.config["workflow"] + self.tools = self.config["tools"] + + def run(self): + prompt = "" + + # if there is a prefix use it + prefix = self.prefix + prompt += prefix + + task_input = self.task_input + task_input = "The task you need to solve is: " + task_input + self.logger.log(f"{task_input}\n", level="info") + + prompt += task_input + + request_waiting_times = [] + request_turnaround_times = [] + + rounds = 0 + + for i, step in enumerate(self.workflow): + prompt += f"\nIn step {rounds + 1}, you need to {step}. Output should focus on current step and don't be verbose!" + if i == 0: + response, start_times, end_times, waiting_times, turnaround_times = self.get_response( + message = Message( + prompt = prompt, + tools = self.tools + ) + ) + response_message = response.response_message + + self.set_start_time(start_times[0]) + + tool_calls = response.tool_calls + + request_waiting_times.extend(waiting_times) + request_turnaround_times.extend(turnaround_times) + + if tool_calls: + self.logger.log(f"***** It starts to call external tools *****\n", level="info") + + function_responses = "" + if tool_calls: + for tool_call in tool_calls: + function_name = tool_call.function.name + function_to_call = self.tool_list[function_name] + function_args = json.loads(tool_call.function.arguments) + + try: + function_response = function_to_call.run(function_args) + function_responses += function_response + prompt += function_response + except Exception: + continue + + self.logger.log(f"The solution to step {rounds+1}: It will call the {function_name} with the params as {function_args}. The tool response is {function_responses}\n", level="info") + + else: + self.logger.log(f"The solution to step {rounds+1}: {response_message}\n", level="info") + + rounds += 1 + + else: + response, start_times, end_times, waiting_times, turnaround_times = self.get_response( + message = Message( + prompt = prompt, + tools = None + ) + ) + + request_waiting_times.extend(waiting_times) + request_turnaround_times.extend(turnaround_times) + + response_message = response.response_message + + if i == len(self.workflow) - 1: + self.logger.log(f"Final result is: {response_message}\n", level="info") + final_result = response_message + + else: + self.logger.log(f"The solution to step {rounds+1}: {response_message}\n", level="info") + + self.set_status("done") + self.set_end_time(time=time.time()) + + return { + "agent_name": self.agent_name, + "result": final_result, + "rounds": rounds, + "agent_waiting_time": self.start_time - self.created_time, + "agent_turnaround_time": self.end_time - self.created_time, + "request_waiting_times": request_waiting_times, + "request_turnaround_times": request_turnaround_times, + } diff --git a/openagi/src/tools/README.md b/openagi/src/tools/README.md new file mode 100644 index 0000000..3affd4a --- /dev/null +++ b/openagi/src/tools/README.md @@ -0,0 +1,3 @@ +# openagi/src/tools + +This contains various tools we can use for our agents. The agent config file specifies which of these tools our agent will require. diff --git a/openagi/src/tools/base.py b/openagi/src/tools/base.py new file mode 100644 index 0000000..96896cd --- /dev/null +++ b/openagi/src/tools/base.py @@ -0,0 +1,38 @@ +# stub implementations of tools that we can use (e.g. rapid api) + +from openagi.src.utils.utils import get_from_env +import json + +class BaseTool: + """Base class for calling tool + """ + def __init__(self): + pass + + def run(self): + pass +class BaseRapidAPITool(BaseTool): + """Base class for calling tool from RapidAPI hub: https://rapidapi.com/hub + + Args: + BaseTool (_type_): _description_ + """ + def __init__(self): + super().__init__() + self.url: str = None + self.host_name: str = None + self.api_key: str = None + + + def run(self, prompt): + pass + + def parse_result(self, response: json): + pass + +class BaseHuggingfaceTool(BaseTool): + def __init__(self): + pass + + def run(self): + pass diff --git a/openagi/src/tools/offline/text_to_image.py b/openagi/src/tools/offline/text_to_image.py new file mode 100644 index 0000000..7520106 --- /dev/null +++ b/openagi/src/tools/offline/text_to_image.py @@ -0,0 +1,20 @@ +# use stable diffusion for image generation + +from diffusers import AutoPipelineForText2Image +import torch + +from ..base import BaseHuggingfaceTool + +class SDXLTurbo(BaseHuggingfaceTool): + def __init__(self): + super().__init__() + self.pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16") + + def run(self, params): + prompt = params["prompt"] + + # use cuda to run it + self.pipe.to("cuda") + + image = self.pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0] + return image diff --git a/openagi/src/tools/online/README.md b/openagi/src/tools/online/README.md new file mode 100644 index 0000000..61d7153 --- /dev/null +++ b/openagi/src/tools/online/README.md @@ -0,0 +1,3 @@ +# openagi/src/tools/online + +This contains tools that use an external API to fetch data. diff --git a/openagi/src/utils/message.py b/openagi/src/utils/message.py new file mode 100644 index 0000000..838d21f --- /dev/null +++ b/openagi/src/utils/message.py @@ -0,0 +1,20 @@ +# what each agent requests and pulls from the tools and the messages it uses + +class Message: + def __init__(self, + prompt, + context = None, + tools = None + ) -> None: + self.prompt = prompt + self.context = context + self.tools = tools + +class Response: + def __init__( + self, + response_message, + tool_calls = None + ) -> None: + self.response_message = response_message + self.tool_calls = tool_calls diff --git a/pyopenagi/README.md b/pyopenagi/README.md new file mode 100644 index 0000000..ddd8ccb --- /dev/null +++ b/pyopenagi/README.md @@ -0,0 +1,7 @@ +# openagi/src + +The internal implementation for OpenAGI. + +1. `agents/` contains the agent implementation all future agents have to follow. +2. `tools/` contains the tools the agents can call. +3. `utils/` contains some helpful internal utilities. diff --git a/pyopenagi/agents/README.md b/pyopenagi/agents/README.md new file mode 100644 index 0000000..8f9ba6b --- /dev/null +++ b/pyopenagi/agents/README.md @@ -0,0 +1,5 @@ +# openagi/src/agents +This folder contains the base implementation for running the agents, as well as the handlers for running multiple agents in Threads in `agent_process.py` and `agent_factory.py` + +In `native_agents/` we have the 6 default agents. +In `agent_config/` we have their respective configurations. diff --git a/pyopenagi/agents/agent_factory.py b/pyopenagi/agents/agent_factory.py index e4dcc8b..cab8e7a 100755 --- a/pyopenagi/agents/agent_factory.py +++ b/pyopenagi/agents/agent_factory.py @@ -1,3 +1,13 @@ +<<<<<<< HEAD:pyopenagi/agents/agent_factory.py +======= +# this class runs the "AgentProcess" for the agents and holds the pool +# of agents currently usable +# this class isn't actually instantiated until the user instantiates +# a specific agent like MathAgent + +from datetime import datetime + +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py import heapq from threading import Lock, Event from pympler import asizeof @@ -6,18 +16,41 @@ import importlib class AgentFactory: +<<<<<<< HEAD:pyopenagi/agents/agent_factory.py def __init__(self, agent_process_queue, agent_process_factory, agent_log_mode ): +======= + """ duplicate of AgentProcessFactory """ + + def __init__(self, llm, agent_process_queue, agent_process_factory, agent_log_mode): + # 256 agent ids heapified similar to AgentProcessFactory +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py self.max_aid = 256 # self.llm = llm self.aid_pool = [i for i in range(self.max_aid)] heapq.heapify(self.aid_pool) self.agent_process_queue = agent_process_queue + + # TODO: dead code self.agent_process_factory = agent_process_factory +<<<<<<< HEAD:pyopenagi/agents/agent_factory.py +======= + # manually add the built in agents to run + self.agent_table = { + "MathAgent": MathAgent, + "AcademicAgent": AcademicAgent, + "RecAgent": RecAgent, + "TravelAgent": TravelAgent, + "RAGAgent": RAGAgent, + "CreationAgent": CreationAgent + } + + # added to with index aid +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py self.current_agents = {} self.current_agents_lock = Lock() @@ -46,6 +79,7 @@ def load_agent_instance(self, agent_name): return agent_class def activate_agent(self, agent_name, task_input): +<<<<<<< HEAD:pyopenagi/agents/agent_factory.py script_path = os.path.abspath(__file__) script_dir = os.path.dirname(script_path) @@ -60,6 +94,10 @@ def activate_agent(self, agent_name, task_input): agent_class = self.load_agent_instance(agent_name) agent = agent_class( +======= + """ initialize each agent """ + agent = self.agent_table[agent_name]( +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py agent_name = agent_name, task_input = task_input, agent_process_factory = self.agent_process_factory, @@ -77,6 +115,8 @@ def activate_agent(self, agent_name, task_input): return agent def run_agent(self, agent_name, task_input): + """ run the Thread and return output """ + agent = self.activate_agent( agent_name=agent_name, task_input=task_input @@ -87,6 +127,7 @@ def run_agent(self, agent_name, task_input): return output def print_agent(self): + """ print all agent information in a nice organized format """ headers = ["Agent ID", "Agent Name", "Created Time", "Status", "Memory Usage"] data = [] for id, agent in self.current_agents.items(): @@ -101,6 +142,7 @@ def print_agent(self): def print(self, headers, data): + """ generalized table printer for the agent data """ # align output column_widths = [ max(len(str(row[i])) for row in [headers] + data) for i in range(len(headers)) @@ -116,9 +158,12 @@ def print(self, headers, data): def format_row(self, row, widths, align="<"): + """ helper utility for print """ row_str = " | ".join(f"{str(item):{align}{widths[i]}}" for i, item in enumerate(row)) return row_str def deactivate_agent(self, aid): + """ remove the agent id from the pool and allow it to be re-used """ + self.current_agents.pop(aid) heapq.heappush(self.aid_pool, aid) diff --git a/pyopenagi/agents/agent_process.py b/pyopenagi/agents/agent_process.py index faa9d83..4bdaf0f 100755 --- a/pyopenagi/agents/agent_process.py +++ b/pyopenagi/agents/agent_process.py @@ -1,6 +1,23 @@ +<<<<<<< HEAD:pyopenagi/agents/agent_process.py +======= +# defines a process holder for agents to use in a single class +# used in the base implementation for agents +# this class isn't actually instantiated until the user instantiates +# a specific agent like MathAgent + +import os + +import time + +from queue import Queue + +from datetime import datetime + +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_process.py import heapq from threading import Thread, Lock, Event +<<<<<<< HEAD:pyopenagi/agents/agent_process.py from ..utils.chat_template import Query @@ -8,6 +25,21 @@ class AgentProcess: def __init__(self, agent_name: str, query: Query +======= +# for memory usage statistics +from pympler import asizeof + +from ..utils.message import Message + +class AgentProcess: + """ + each agent holds the values defined in the constructor + """ + + def __init__(self, + agent_name, + message +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_process.py ): """Agent Process @@ -25,6 +57,10 @@ def __init__(self, self.start_time = None self.end_time = None + ####################### + # getters and setters # + ####################### + def set_created_time(self, time): self.created_time = time @@ -78,7 +114,14 @@ class LLMRequestProcess(AgentProcess): pass class AgentProcessFactory: + """ + used by AgentFactory + right now it is only set in agent activation + """ + def __init__(self, agent_process_log_mode = None): + # make a heap of every pid 1..1024 to remove from when agent created + # so pids can be reused self.max_pid = 1024 self.pid_pool = [i for i in range(self.max_pid)] heapq.heapify(self.pid_pool) @@ -93,9 +136,14 @@ def __init__(self, agent_process_log_mode = None): self.agent_process_log_mode = agent_process_log_mode +<<<<<<< HEAD:pyopenagi/agents/agent_process.py def activate_agent_process(self, agent_name, query): +======= + def activate_agent_process(self, agent_name, message): + """ run each agent and lock it """ +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_process.py if not self.terminate_signal.is_set(): - with self.current_agent_processes_lock: + with self.current_agent_processes_lock: agent_process = AgentProcess( agent_name = agent_name, query = query @@ -107,6 +155,7 @@ def activate_agent_process(self, agent_name, query): return agent_process def print_agent_process(self): + """ print agent data in a clean format """ headers = ["Agent Process ID", "Agent Name", "Created Time", "Status"] data = [] for id, agent_process in self.current_agent_processes.items(): @@ -121,6 +170,8 @@ def print_agent_process(self): def print(self, headers, data): + """ separate headers and data in printing """ + # align output column_widths = [ max(len(str(row[i])) for row in [headers] + data) for i in range(len(headers)) @@ -136,10 +187,12 @@ def print(self, headers, data): def format_row(self, row, widths, align="<"): + """ helper for print """ row_str = " | ".join(f"{str(item):{align}{widths[i]}}" for i, item in enumerate(row)) return row_str def deactivate_agent_process(self, pid): + """ after agent stops reallow pid """ self.current_agent_processes.pop(pid) heapq.heappush(self.pid_pool, pid) diff --git a/pyopenagi/agents/base_agent.py b/pyopenagi/agents/base_agent.py index 7264cd3..c1d7ee4 100755 --- a/pyopenagi/agents/base_agent.py +++ b/pyopenagi/agents/base_agent.py @@ -1,3 +1,6 @@ +# stub implementation for agents +# defines a class standard each agent has to subclass + import os import json @@ -12,13 +15,21 @@ from ..utils.logger import AgentLogger +<<<<<<< HEAD:pyopenagi/agents/base_agent.py from ..utils.chat_template import Query import importlib from ..queues.llm_request_queue import LLMRequestQueue +======= +from ..utils.message import Message + +# TODO: can be removed +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py class CustomizedThread(Thread): + """ provides a specific agent runtime """ + def __init__(self, target, args=()): super().__init__() self.target = target @@ -26,9 +37,15 @@ def __init__(self, target, args=()): self.result = None def run(self): + """ + instead of creating a Thread, it'll run a function and hold the value + in BaseAgent, it's only usage, it creates a Thread and sets certain + values for the AgentProcess to provide runtime diagnostics + """ self.result = self.target(*self.args) def join(self): + """ returns the result from the custom Thread runtime """ super().join() return self.result @@ -42,8 +59,18 @@ def __init__(self, self.agent_name = agent_name self.config = self.load_config() +<<<<<<< HEAD:pyopenagi/agents/base_agent.py self.tool_names = self.config["tools"] +======= + self.prefix = " ".join(self.config["description"]) + self.task_input = task_input + self.llm = llm + + # instantiated inside each agent's specific instantiation + # e.g. `myAgent = MathAgent()` + self.agent_process_queue = agent_process_queue +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py self.agent_process_factory = agent_process_factory self.tool_list = dict() @@ -162,6 +189,10 @@ def setup_logger(self): return logger def load_config(self): + """ + loads each agent config with the values in the json + such as the system prompt, functions + """ script_path = os.path.abspath(__file__) script_dir = os.path.dirname(script_path) config_file = os.path.join(script_dir, self.agent_name, "config.json") @@ -174,13 +205,25 @@ def get_response(self, query, temperature=0.0 ): +<<<<<<< HEAD:pyopenagi/agents/base_agent.py thread = CustomizedThread(target=self.query_loop, args=(query, )) thread.start() return thread.join() def query_loop(self, query): agent_process = self.create_agent_request(query) +======= + """ value of the agent """ + thread = CustomizedThread(target=self.query_loop, args=(message, )) + thread.start() + return thread.join() + def query_loop(self, message): + """ custom function for the CustomizedThread """ + agent_process = self.create_agent_request(message) +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py + + # because it might have to run multiple times completed_response, start_times, end_times, waiting_times, turnaround_times = "", [], [], [], [] while agent_process.get_status() != "done": @@ -200,6 +243,8 @@ def query_loop(self, query): f"Suspended due to the reach of time limit ({agent_process.get_time_limit()}s). Current result is: {completed_response.response_message}\n", level="suspending" ) + + # data from the AgentProcess temporarily held start_time = agent_process.get_start_time() end_time = agent_process.get_end_time() waiting_time = start_time - agent_process.get_created_time() @@ -215,7 +260,12 @@ def query_loop(self, query): return completed_response, start_times, end_times, waiting_times, turnaround_times +<<<<<<< HEAD:pyopenagi/agents/base_agent.py def create_agent_request(self, query): +======= + def create_agent_request(self, message): + """ uses AgentFactory to initialize the agent in the pool """ +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py agent_process = self.agent_process_factory.activate_agent_process( agent_name = self.agent_name, query = query @@ -238,6 +288,14 @@ def listen(self, agent_process: AgentProcess): return agent_process.get_response() + def parse_result(self, prompt): + """ each agent has their own parser """ + pass + + ####################### + # getters and setters # + ####################### + def set_aid(self, aid): self.aid = aid @@ -274,3 +332,7 @@ def set_end_time(self, time): def get_end_time(self): return self.end_time +<<<<<<< HEAD:pyopenagi/agents/base_agent.py +======= + +>>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py diff --git a/pyopenagi/agents/example/README.md b/pyopenagi/agents/example/README.md new file mode 100644 index 0000000..d58bb5c --- /dev/null +++ b/pyopenagi/agents/example/README.md @@ -0,0 +1,4 @@ +# openagi/src/agents/native_agents +This directory contains the subclasses of the agents for the 6 default agents. + +They have to evaluate each of the agents steps in a loop. In the future this can change to use far less code. by putting in the base implementation. diff --git a/pyopenagi/agents/example/rag_agent/README.md b/pyopenagi/agents/example/rag_agent/README.md new file mode 100644 index 0000000..b8f569e --- /dev/null +++ b/pyopenagi/agents/example/rag_agent/README.md @@ -0,0 +1,14 @@ +# src/agents/agent_config + +Each agent holds a config file in addition to the class specifying what to run. The agent config is a JSON file. + +Each JSON file contains the following: + +1. `name` : name of the agent +2. `description` : an array with one element containing the system prompt +3. `workflow` : an array with plaintext describing what the agent will do at each iteration. this is fed into the LLM running the agent +4. `tools` : an array with complex json objects +- `type` : type of tool, typically "function" +- `function` : if the type of function it contains data in the specific functions. + +For more detailed information, cite each specific agent as an example and fit it for your purposes. diff --git a/pyopenagi/tools/offline/README.md b/pyopenagi/tools/offline/README.md new file mode 100644 index 0000000..324cad4 --- /dev/null +++ b/pyopenagi/tools/offline/README.md @@ -0,0 +1,5 @@ +# openagi/src/tools/offline + +Tools that can run offline, right now theres only text2image :) + +This could potentially contain a filesystem searching tool or a CPU info tool to query information about the local machine diff --git a/pyopenagi/utils/README.md b/pyopenagi/utils/README.md new file mode 100644 index 0000000..5e78db2 --- /dev/null +++ b/pyopenagi/utils/README.md @@ -0,0 +1,7 @@ +# openagi/src/utils + +Helper utils that are re-used in AIOS. + +These are various tools that we use in our internal implementations. + +In the future they shouldn't be copy pasted to AIOS. diff --git a/pyopenagi/utils/compressor.py b/pyopenagi/utils/compressor.py index f46cfbc..e51ab7e 100644 --- a/pyopenagi/utils/compressor.py +++ b/pyopenagi/utils/compressor.py @@ -1,3 +1,6 @@ +# uses zlibrary to compress data +# same as util in AIOS + import zlib class Compressor: diff --git a/pyopenagi/utils/logger.py b/pyopenagi/utils/logger.py index 17f9ea3..4aac012 100644 --- a/pyopenagi/utils/logger.py +++ b/pyopenagi/utils/logger.py @@ -1,3 +1,6 @@ +# contains tools for logging actions +# the thread scheduler, agents, and the LLM kernel of AIOS are all loggable here + import click import os @@ -34,6 +37,8 @@ def log_to_file(self, content, log_file): w.writelines(content) class SchedulerLogger(BaseLogger): + """ log the threads """ + def __init__(self, logger_name, log_mode="console") -> None: super().__init__(logger_name, log_mode) self.level_color = { @@ -52,6 +57,8 @@ def load_log_file(self): class AgentLogger(BaseLogger): + """ log the agents """ + def __init__(self, logger_name, log_mode="console") -> None: super().__init__(logger_name, log_mode) self.level_color = { @@ -71,6 +78,8 @@ def load_log_file(self): class LLMKernelLogger(BaseLogger): + """ log the LLM kernel """ + def __init__(self, logger_name, log_mode="console") -> None: super().__init__(logger_name, log_mode) self.level_color = { diff --git a/pyopenagi/utils/utils.py b/pyopenagi/utils/utils.py index edad022..8d8c7d0 100644 --- a/pyopenagi/utils/utils.py +++ b/pyopenagi/utils/utils.py @@ -1,3 +1,6 @@ +# random helper utils AIOS uses +# file is not particularly organized but mainly small functions + import argparse import os diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c4eb6db --- /dev/null +++ b/setup.py @@ -0,0 +1,10 @@ +# script that setups the package for use when you do +# `pip install -e .` + +from setuptools import setup + +setup( + name='openagi', + version='0.0.1', + packages=['openagi'], +) From 54ba06295602f036c038d938aee4010d42aa206b Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Thu, 1 Aug 2024 15:51:27 -0400 Subject: [PATCH 2/7] made more things work --- README.md | 26 ++------------------------ pyopenagi/README.md | 3 ++- pyopenagi/queues/base_queue.py | 2 ++ pyopenagi/queues/llm_request_queue.py | 2 ++ pyopenagi/utils/utils.py | 2 +- tests/README.md | 6 ++++-- tests/test_agent_creation.py | 2 ++ tests/test_tools/README.md | 3 +++ 8 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 tests/test_tools/README.md diff --git a/README.md b/README.md index b6239e0..1bf54c6 100644 --- a/README.md +++ b/README.md @@ -48,34 +48,12 @@ If you want to look at implementations of other agents that others have develope python pyopenagi/agents/interact.py --mode download --agent ``` -<<<<<<< HEAD -======= -## 2. Contributing - -### 2.1 Documentation -Each source directory contains a README.md file that explains what the files in that directory do. Additionally, each file has a header that describes the file's purpose. All comments follow the same styling documented in [AIOS](https://github.com/agiresearch/AIOS). - -### 2.2 Running tests -Run tests: Add your test code into the tests/ directory if any, then run test via pytest -``` -cd openagi -pytest -v tests -``` -sample output -``` -============================================================================================================================= test session starts ============================================================================================================================== -platform darwin -- Python 3.11.9, pytest-8.1.1, pluggy-1.5.0 -- "" -cachedir: .pytest_cache -rootdir: "" -plugins: anyio-4.3.0 -collected 2 items ->>>>>>> 00c34a4 (added readme files in each directory for source documentation) - ## 🚀 Contributions + For detailed information on how to contribute, see [CONTRIBUTE](./CONTRIBUTE.md). If you would like to contribute to the codebase, [issues](https://github.com/agiresearch/OpenAGI/issues) or [pull requests](https://github.com/agiresearch/OpenAGI/pulls) are always welcome! ## 🖋️ Research -Please check out our [implementation](./research) for our research paper [OpenAGI: When LLM Meets Domain Experts](https://arxiv.org/abs/2304.04370). +Please check out our [implementation](https://github.com/agiresearch/OpenAGI/tree/research) for our research paper [OpenAGI: When LLM Meets Domain Experts](https://arxiv.org/abs/2304.04370). ``` @article{openagi, diff --git a/pyopenagi/README.md b/pyopenagi/README.md index ddd8ccb..043534c 100644 --- a/pyopenagi/README.md +++ b/pyopenagi/README.md @@ -3,5 +3,6 @@ The internal implementation for OpenAGI. 1. `agents/` contains the agent implementation all future agents have to follow. -2. `tools/` contains the tools the agents can call. +2. `queues/` contains the class implementation for queues. 3. `utils/` contains some helpful internal utilities. +4. `tools/` contains the tools the agents can use. diff --git a/pyopenagi/queues/base_queue.py b/pyopenagi/queues/base_queue.py index 377f693..db2208b 100644 --- a/pyopenagi/queues/base_queue.py +++ b/pyopenagi/queues/base_queue.py @@ -1,3 +1,5 @@ +# make a queue for agents to use + import queue class BaseQueue: diff --git a/pyopenagi/queues/llm_request_queue.py b/pyopenagi/queues/llm_request_queue.py index 3555f5c..f0768a7 100644 --- a/pyopenagi/queues/llm_request_queue.py +++ b/pyopenagi/queues/llm_request_queue.py @@ -1,3 +1,5 @@ +# same implementation as base_queue.py, but different class name + from .base_queue import BaseQueue class LLMRequestQueue(BaseQueue): diff --git a/pyopenagi/utils/utils.py b/pyopenagi/utils/utils.py index 8d8c7d0..8642c8a 100644 --- a/pyopenagi/utils/utils.py +++ b/pyopenagi/utils/utils.py @@ -1,4 +1,4 @@ -# random helper utils AIOS uses +# helper utils AIOS uses # file is not particularly organized but mainly small functions import argparse diff --git a/tests/README.md b/tests/README.md index c05eb78..20f458b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,5 +1,7 @@ # tests -This directory contains quick tests of methods that we rely on heavily throughout this project. You can simply run the tests in the same manner. +This directory contains tests you can use to test specific features of the project so you can figure out which specific parts work easier. -In the future, we intend to use error code to differentiate between successful and failed tests. +For example, test_agent_creation.py simply tests the AgentProcess ability to hold agents. + +We want to use error code to differentiate between successful and failed tests in the future. diff --git a/tests/test_agent_creation.py b/tests/test_agent_creation.py index ca42f71..437d185 100644 --- a/tests/test_agent_creation.py +++ b/tests/test_agent_creation.py @@ -1,3 +1,5 @@ +# make sure we can create agents + from pyopenagi.agents.agent_process import AgentProcess from pyopenagi.utils.chat_template import Query diff --git a/tests/test_tools/README.md b/tests/test_tools/README.md new file mode 100644 index 0000000..8dfaa9b --- /dev/null +++ b/tests/test_tools/README.md @@ -0,0 +1,3 @@ +# test/test_tools + +This tests specific tools the agents can use and makes sure they are working. Each tool has its own test. From 8638447e48eb24e19795640b0657d7b9e7e25937 Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Thu, 1 Aug 2024 16:24:10 -0400 Subject: [PATCH 3/7] Fixed merge conflicts preventing pytest from running --- pyopenagi/agents/agent_factory.py | 23 +------------------ pyopenagi/agents/agent_process.py | 34 +++------------------------- pyopenagi/agents/base_agent.py | 37 ++----------------------------- 3 files changed, 6 insertions(+), 88 deletions(-) diff --git a/pyopenagi/agents/agent_factory.py b/pyopenagi/agents/agent_factory.py index cab8e7a..7ecce44 100755 --- a/pyopenagi/agents/agent_factory.py +++ b/pyopenagi/agents/agent_factory.py @@ -1,13 +1,8 @@ -<<<<<<< HEAD:pyopenagi/agents/agent_factory.py -======= # this class runs the "AgentProcess" for the agents and holds the pool # of agents currently usable # this class isn't actually instantiated until the user instantiates # a specific agent like MathAgent -from datetime import datetime - ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py import heapq from threading import Lock, Event from pympler import asizeof @@ -16,29 +11,18 @@ import importlib class AgentFactory: -<<<<<<< HEAD:pyopenagi/agents/agent_factory.py - def __init__(self, - agent_process_queue, - agent_process_factory, - agent_log_mode - ): -======= """ duplicate of AgentProcessFactory """ def __init__(self, llm, agent_process_queue, agent_process_factory, agent_log_mode): # 256 agent ids heapified similar to AgentProcessFactory ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py self.max_aid = 256 # self.llm = llm self.aid_pool = [i for i in range(self.max_aid)] heapq.heapify(self.aid_pool) self.agent_process_queue = agent_process_queue - # TODO: dead code self.agent_process_factory = agent_process_factory -<<<<<<< HEAD:pyopenagi/agents/agent_factory.py -======= # manually add the built in agents to run self.agent_table = { "MathAgent": MathAgent, @@ -50,7 +34,6 @@ def __init__(self, llm, agent_process_queue, agent_process_factory, agent_log_mo } # added to with index aid ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py self.current_agents = {} self.current_agents_lock = Lock() @@ -79,7 +62,6 @@ def load_agent_instance(self, agent_name): return agent_class def activate_agent(self, agent_name, task_input): -<<<<<<< HEAD:pyopenagi/agents/agent_factory.py script_path = os.path.abspath(__file__) script_dir = os.path.dirname(script_path) @@ -93,11 +75,8 @@ def activate_agent(self, agent_name, task_input): agent_class = self.load_agent_instance(agent_name) - agent = agent_class( -======= """ initialize each agent """ - agent = self.agent_table[agent_name]( ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_factory.py + agent = agent_class( agent_name = agent_name, task_input = task_input, agent_process_factory = self.agent_process_factory, diff --git a/pyopenagi/agents/agent_process.py b/pyopenagi/agents/agent_process.py index 4bdaf0f..122ee40 100755 --- a/pyopenagi/agents/agent_process.py +++ b/pyopenagi/agents/agent_process.py @@ -1,45 +1,21 @@ -<<<<<<< HEAD:pyopenagi/agents/agent_process.py -======= # defines a process holder for agents to use in a single class # used in the base implementation for agents # this class isn't actually instantiated until the user instantiates # a specific agent like MathAgent -import os - -import time - -from queue import Queue - -from datetime import datetime - ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_process.py import heapq from threading import Thread, Lock, Event -<<<<<<< HEAD:pyopenagi/agents/agent_process.py from ..utils.chat_template import Query -class AgentProcess: - def __init__(self, - agent_name: str, - query: Query -======= -# for memory usage statistics -from pympler import asizeof - -from ..utils.message import Message - class AgentProcess: """ each agent holds the values defined in the constructor """ - - def __init__(self, - agent_name, - message ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_process.py + def __init__(self, + agent_name: str, + query: Query ): """Agent Process @@ -136,12 +112,8 @@ def __init__(self, agent_process_log_mode = None): self.agent_process_log_mode = agent_process_log_mode -<<<<<<< HEAD:pyopenagi/agents/agent_process.py def activate_agent_process(self, agent_name, query): -======= - def activate_agent_process(self, agent_name, message): """ run each agent and lock it """ ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/agent_process.py if not self.terminate_signal.is_set(): with self.current_agent_processes_lock: agent_process = AgentProcess( diff --git a/pyopenagi/agents/base_agent.py b/pyopenagi/agents/base_agent.py index c1d7ee4..081fb54 100755 --- a/pyopenagi/agents/base_agent.py +++ b/pyopenagi/agents/base_agent.py @@ -15,18 +15,12 @@ from ..utils.logger import AgentLogger -<<<<<<< HEAD:pyopenagi/agents/base_agent.py from ..utils.chat_template import Query import importlib from ..queues.llm_request_queue import LLMRequestQueue -======= -from ..utils.message import Message - -# TODO: can be removed ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py class CustomizedThread(Thread): """ provides a specific agent runtime """ @@ -59,18 +53,8 @@ def __init__(self, self.agent_name = agent_name self.config = self.load_config() -<<<<<<< HEAD:pyopenagi/agents/base_agent.py self.tool_names = self.config["tools"] -======= - self.prefix = " ".join(self.config["description"]) - self.task_input = task_input - self.llm = llm - - # instantiated inside each agent's specific instantiation - # e.g. `myAgent = MathAgent()` - self.agent_process_queue = agent_process_queue ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py self.agent_process_factory = agent_process_factory self.tool_list = dict() @@ -205,23 +189,14 @@ def get_response(self, query, temperature=0.0 ): -<<<<<<< HEAD:pyopenagi/agents/base_agent.py + """ value of the agent """ thread = CustomizedThread(target=self.query_loop, args=(query, )) thread.start() return thread.join() def query_loop(self, query): - agent_process = self.create_agent_request(query) -======= - """ value of the agent """ - thread = CustomizedThread(target=self.query_loop, args=(message, )) - thread.start() - return thread.join() - - def query_loop(self, message): """ custom function for the CustomizedThread """ - agent_process = self.create_agent_request(message) ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py + agent_process = self.create_agent_request(query) # because it might have to run multiple times completed_response, start_times, end_times, waiting_times, turnaround_times = "", [], [], [], [] @@ -260,12 +235,8 @@ def query_loop(self, message): return completed_response, start_times, end_times, waiting_times, turnaround_times -<<<<<<< HEAD:pyopenagi/agents/base_agent.py def create_agent_request(self, query): -======= - def create_agent_request(self, message): """ uses AgentFactory to initialize the agent in the pool """ ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py agent_process = self.agent_process_factory.activate_agent_process( agent_name = self.agent_name, query = query @@ -332,7 +303,3 @@ def set_end_time(self, time): def get_end_time(self): return self.end_time -<<<<<<< HEAD:pyopenagi/agents/base_agent.py -======= - ->>>>>>> 00c34a4 (added readme files in each directory for source documentation):openagi/src/agents/base.py From 767d089d5a822b77ef3b3e3783d5d753a14ecbd1 Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Thu, 1 Aug 2024 16:39:27 -0400 Subject: [PATCH 4/7] removed old openagi src --- .../academic_agent/academic_agent.py | 135 ------------------ openagi/src/tools/README.md | 3 - openagi/src/tools/base.py | 38 ----- openagi/src/tools/offline/text_to_image.py | 20 --- openagi/src/tools/online/README.md | 3 - openagi/src/utils/message.py | 20 --- 6 files changed, 219 deletions(-) delete mode 100644 openagi/src/agents/native_agents/academic_agent/academic_agent.py delete mode 100644 openagi/src/tools/README.md delete mode 100644 openagi/src/tools/base.py delete mode 100644 openagi/src/tools/offline/text_to_image.py delete mode 100644 openagi/src/tools/online/README.md delete mode 100644 openagi/src/utils/message.py diff --git a/openagi/src/agents/native_agents/academic_agent/academic_agent.py b/openagi/src/agents/native_agents/academic_agent/academic_agent.py deleted file mode 100644 index 9eec16e..0000000 --- a/openagi/src/agents/native_agents/academic_agent/academic_agent.py +++ /dev/null @@ -1,135 +0,0 @@ -# agent that provides accurate academic summarization agent - -from ...base import BaseAgent - -import time - -from ...agent_process import ( - AgentProcess -) - -import numpy as np - -import argparse - -from concurrent.futures import as_completed - -from ....utils.message import Message - -from ....tools.online.arxiv import Arxiv - -from ....tools.online.wikipedia import Wikipedia - -import json - -class AcademicAgent(BaseAgent): - def __init__(self, - agent_name, - task_input, - llm, - agent_process_queue, - agent_process_factory, - log_mode: str - ): - BaseAgent.__init__(self, agent_name, task_input, llm, agent_process_queue, agent_process_factory, log_mode) - - # doesn't use Wikipedia yet - self.tool_list = { - "arxiv": Arxiv() - } - - self.workflow = self.config["workflow"] - self.tools = self.config["tools"] - - def run(self): - prompt = "" - - # if there is a prefix use it - prefix = self.prefix - prompt += prefix - - task_input = self.task_input - task_input = "The task you need to solve is: " + task_input - self.logger.log(f"{task_input}\n", level="info") - - prompt += task_input - - request_waiting_times = [] - request_turnaround_times = [] - - rounds = 0 - - for i, step in enumerate(self.workflow): - prompt += f"\nIn step {rounds + 1}, you need to {step}. Output should focus on current step and don't be verbose!" - if i == 0: - response, start_times, end_times, waiting_times, turnaround_times = self.get_response( - message = Message( - prompt = prompt, - tools = self.tools - ) - ) - response_message = response.response_message - - self.set_start_time(start_times[0]) - - tool_calls = response.tool_calls - - request_waiting_times.extend(waiting_times) - request_turnaround_times.extend(turnaround_times) - - if tool_calls: - self.logger.log(f"***** It starts to call external tools *****\n", level="info") - - function_responses = "" - if tool_calls: - for tool_call in tool_calls: - function_name = tool_call.function.name - function_to_call = self.tool_list[function_name] - function_args = json.loads(tool_call.function.arguments) - - try: - function_response = function_to_call.run(function_args) - function_responses += function_response - prompt += function_response - except Exception: - continue - - self.logger.log(f"The solution to step {rounds+1}: It will call the {function_name} with the params as {function_args}. The tool response is {function_responses}\n", level="info") - - else: - self.logger.log(f"The solution to step {rounds+1}: {response_message}\n", level="info") - - rounds += 1 - - else: - response, start_times, end_times, waiting_times, turnaround_times = self.get_response( - message = Message( - prompt = prompt, - tools = None - ) - ) - - request_waiting_times.extend(waiting_times) - request_turnaround_times.extend(turnaround_times) - - response_message = response.response_message - - if i == len(self.workflow) - 1: - self.logger.log(f"Final result is: {response_message}\n", level="info") - final_result = response_message - - else: - self.logger.log(f"The solution to step {rounds+1}: {response_message}\n", level="info") - - self.set_status("done") - self.set_end_time(time=time.time()) - - return { - "agent_name": self.agent_name, - "result": final_result, - "rounds": rounds, - "agent_waiting_time": self.start_time - self.created_time, - "agent_turnaround_time": self.end_time - self.created_time, - "request_waiting_times": request_waiting_times, - "request_turnaround_times": request_turnaround_times, - } diff --git a/openagi/src/tools/README.md b/openagi/src/tools/README.md deleted file mode 100644 index 3affd4a..0000000 --- a/openagi/src/tools/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# openagi/src/tools - -This contains various tools we can use for our agents. The agent config file specifies which of these tools our agent will require. diff --git a/openagi/src/tools/base.py b/openagi/src/tools/base.py deleted file mode 100644 index 96896cd..0000000 --- a/openagi/src/tools/base.py +++ /dev/null @@ -1,38 +0,0 @@ -# stub implementations of tools that we can use (e.g. rapid api) - -from openagi.src.utils.utils import get_from_env -import json - -class BaseTool: - """Base class for calling tool - """ - def __init__(self): - pass - - def run(self): - pass -class BaseRapidAPITool(BaseTool): - """Base class for calling tool from RapidAPI hub: https://rapidapi.com/hub - - Args: - BaseTool (_type_): _description_ - """ - def __init__(self): - super().__init__() - self.url: str = None - self.host_name: str = None - self.api_key: str = None - - - def run(self, prompt): - pass - - def parse_result(self, response: json): - pass - -class BaseHuggingfaceTool(BaseTool): - def __init__(self): - pass - - def run(self): - pass diff --git a/openagi/src/tools/offline/text_to_image.py b/openagi/src/tools/offline/text_to_image.py deleted file mode 100644 index 7520106..0000000 --- a/openagi/src/tools/offline/text_to_image.py +++ /dev/null @@ -1,20 +0,0 @@ -# use stable diffusion for image generation - -from diffusers import AutoPipelineForText2Image -import torch - -from ..base import BaseHuggingfaceTool - -class SDXLTurbo(BaseHuggingfaceTool): - def __init__(self): - super().__init__() - self.pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16") - - def run(self, params): - prompt = params["prompt"] - - # use cuda to run it - self.pipe.to("cuda") - - image = self.pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0] - return image diff --git a/openagi/src/tools/online/README.md b/openagi/src/tools/online/README.md deleted file mode 100644 index 61d7153..0000000 --- a/openagi/src/tools/online/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# openagi/src/tools/online - -This contains tools that use an external API to fetch data. diff --git a/openagi/src/utils/message.py b/openagi/src/utils/message.py deleted file mode 100644 index 838d21f..0000000 --- a/openagi/src/utils/message.py +++ /dev/null @@ -1,20 +0,0 @@ -# what each agent requests and pulls from the tools and the messages it uses - -class Message: - def __init__(self, - prompt, - context = None, - tools = None - ) -> None: - self.prompt = prompt - self.context = context - self.tools = tools - -class Response: - def __init__( - self, - response_message, - tool_calls = None - ) -> None: - self.response_message = response_message - self.tool_calls = tool_calls From 28c00d884b8aa7565c807c22bed6cfbeab73516a Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Fri, 2 Aug 2024 17:37:14 -0400 Subject: [PATCH 5/7] renamed readmes and deprecated tool structures- artifacts from my local build --- pyopenagi/README.md | 2 +- pyopenagi/agents/README.md | 2 +- pyopenagi/queues/README.md | 3 +++ pyopenagi/tools/README.md | 3 +++ pyopenagi/tools/offline/README.md | 5 ----- pyopenagi/utils/README.md | 2 +- setup.py | 10 ---------- 7 files changed, 9 insertions(+), 18 deletions(-) create mode 100644 pyopenagi/queues/README.md create mode 100644 pyopenagi/tools/README.md delete mode 100644 pyopenagi/tools/offline/README.md delete mode 100644 setup.py diff --git a/pyopenagi/README.md b/pyopenagi/README.md index 043534c..6e763d6 100644 --- a/pyopenagi/README.md +++ b/pyopenagi/README.md @@ -1,4 +1,4 @@ -# openagi/src +# pyopenagi The internal implementation for OpenAGI. diff --git a/pyopenagi/agents/README.md b/pyopenagi/agents/README.md index 8f9ba6b..aab1186 100644 --- a/pyopenagi/agents/README.md +++ b/pyopenagi/agents/README.md @@ -1,4 +1,4 @@ -# openagi/src/agents +# pyopenagi/agents This folder contains the base implementation for running the agents, as well as the handlers for running multiple agents in Threads in `agent_process.py` and `agent_factory.py` In `native_agents/` we have the 6 default agents. diff --git a/pyopenagi/queues/README.md b/pyopenagi/queues/README.md new file mode 100644 index 0000000..e7f768b --- /dev/null +++ b/pyopenagi/queues/README.md @@ -0,0 +1,3 @@ +# pyopenagi/queues + +This contains implementations for queries to be passed to the LLM in a queue format so that we can have some waiting while one request is completing. diff --git a/pyopenagi/tools/README.md b/pyopenagi/tools/README.md new file mode 100644 index 0000000..98c40db --- /dev/null +++ b/pyopenagi/tools/README.md @@ -0,0 +1,3 @@ +# pyopenagi/tools + +This is where all the tools are located. Each tool requires you to subclass the base tool and add the features required. diff --git a/pyopenagi/tools/offline/README.md b/pyopenagi/tools/offline/README.md deleted file mode 100644 index 324cad4..0000000 --- a/pyopenagi/tools/offline/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# openagi/src/tools/offline - -Tools that can run offline, right now theres only text2image :) - -This could potentially contain a filesystem searching tool or a CPU info tool to query information about the local machine diff --git a/pyopenagi/utils/README.md b/pyopenagi/utils/README.md index 5e78db2..29d1274 100644 --- a/pyopenagi/utils/README.md +++ b/pyopenagi/utils/README.md @@ -1,4 +1,4 @@ -# openagi/src/utils +# pyopenagi/utils Helper utils that are re-used in AIOS. diff --git a/setup.py b/setup.py deleted file mode 100644 index c4eb6db..0000000 --- a/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -# script that setups the package for use when you do -# `pip install -e .` - -from setuptools import setup - -setup( - name='openagi', - version='0.0.1', - packages=['openagi'], -) From 4aec8e222c560260c41ef3cc1a2e52d2e2500808 Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Fri, 2 Aug 2024 18:22:56 -0400 Subject: [PATCH 6/7] added my own agent --- .../agents/om-raheja/transcribe_agent/agent.py | 17 +++++++++++++++++ .../om-raheja/transcribe_agent/config.json | 14 ++++++++++++++ .../transcribe_agent/meta_requirements.txt | 1 + 3 files changed, 32 insertions(+) create mode 100755 pyopenagi/agents/om-raheja/transcribe_agent/agent.py create mode 100644 pyopenagi/agents/om-raheja/transcribe_agent/config.json create mode 100644 pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt diff --git a/pyopenagi/agents/om-raheja/transcribe_agent/agent.py b/pyopenagi/agents/om-raheja/transcribe_agent/agent.py new file mode 100755 index 0000000..b9c3eb5 --- /dev/null +++ b/pyopenagi/agents/om-raheja/transcribe_agent/agent.py @@ -0,0 +1,17 @@ +from ...react_agent import ReactAgent + +class TranscribeAgent(ReactAgent): + def __init__(self, + agent_name, + task_input, + agent_process_factory, + log_mode: str + ): + ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode) + self.workflow_mode = "automatic" + + def manual_workflow(self): + pass + + def run(self): + return super().run() diff --git a/pyopenagi/agents/om-raheja/transcribe_agent/config.json b/pyopenagi/agents/om-raheja/transcribe_agent/config.json new file mode 100644 index 0000000..93089ef --- /dev/null +++ b/pyopenagi/agents/om-raheja/transcribe_agent/config.json @@ -0,0 +1,14 @@ +{ + "name": "transcribe_agent", + "description": [ + "You are an agent who can transcribe audio from the microphone into text. " + ], + "tools": [ + "transcriber/transcriber" + ], + "meta": { + "author": "Om Raheja", + "version": "0.0.1", + "license": "CC0" + } +} diff --git a/pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt b/pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt new file mode 100644 index 0000000..d7d6bed --- /dev/null +++ b/pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt @@ -0,0 +1 @@ +RealtimeSTT From f11a2df8e65bf59b05c012e1316de436f23cff2f Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Sat, 3 Aug 2024 21:32:54 -0400 Subject: [PATCH 7/7] added requested changes --- pyopenagi/agents/README.md | 3 +-- pyopenagi/agents/agent_factory.py | 9 --------- pyopenagi/agents/example/README.md | 5 ++--- .../agents/om-raheja/transcribe_agent/agent.py | 17 ----------------- .../om-raheja/transcribe_agent/config.json | 14 -------------- .../transcribe_agent/meta_requirements.txt | 1 - 6 files changed, 3 insertions(+), 46 deletions(-) delete mode 100755 pyopenagi/agents/om-raheja/transcribe_agent/agent.py delete mode 100644 pyopenagi/agents/om-raheja/transcribe_agent/config.json delete mode 100644 pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt diff --git a/pyopenagi/agents/README.md b/pyopenagi/agents/README.md index aab1186..de69553 100644 --- a/pyopenagi/agents/README.md +++ b/pyopenagi/agents/README.md @@ -1,5 +1,4 @@ # pyopenagi/agents This folder contains the base implementation for running the agents, as well as the handlers for running multiple agents in Threads in `agent_process.py` and `agent_factory.py` -In `native_agents/` we have the 6 default agents. -In `agent_config/` we have their respective configurations. +In `example/` we have some example agents. You can add agents to that directory or to `your-cool-identifier/` to show your agent off in the main repo. However, it is recommended to use the agent database over submitting a pull request, unless it is for demo purposes. diff --git a/pyopenagi/agents/agent_factory.py b/pyopenagi/agents/agent_factory.py index 7ecce44..f5f4243 100755 --- a/pyopenagi/agents/agent_factory.py +++ b/pyopenagi/agents/agent_factory.py @@ -23,15 +23,6 @@ def __init__(self, llm, agent_process_queue, agent_process_factory, agent_log_mo self.agent_process_factory = agent_process_factory - # manually add the built in agents to run - self.agent_table = { - "MathAgent": MathAgent, - "AcademicAgent": AcademicAgent, - "RecAgent": RecAgent, - "TravelAgent": TravelAgent, - "RAGAgent": RAGAgent, - "CreationAgent": CreationAgent - } # added to with index aid self.current_agents = {} diff --git a/pyopenagi/agents/example/README.md b/pyopenagi/agents/example/README.md index d58bb5c..de6652e 100644 --- a/pyopenagi/agents/example/README.md +++ b/pyopenagi/agents/example/README.md @@ -1,4 +1,3 @@ -# openagi/src/agents/native_agents -This directory contains the subclasses of the agents for the 6 default agents. +# pyopenagi/agents/example -They have to evaluate each of the agents steps in a loop. In the future this can change to use far less code. by putting in the base implementation. +Here are the example agents we created to demo agent creation in OpenAGI. diff --git a/pyopenagi/agents/om-raheja/transcribe_agent/agent.py b/pyopenagi/agents/om-raheja/transcribe_agent/agent.py deleted file mode 100755 index b9c3eb5..0000000 --- a/pyopenagi/agents/om-raheja/transcribe_agent/agent.py +++ /dev/null @@ -1,17 +0,0 @@ -from ...react_agent import ReactAgent - -class TranscribeAgent(ReactAgent): - def __init__(self, - agent_name, - task_input, - agent_process_factory, - log_mode: str - ): - ReactAgent.__init__(self, agent_name, task_input, agent_process_factory, log_mode) - self.workflow_mode = "automatic" - - def manual_workflow(self): - pass - - def run(self): - return super().run() diff --git a/pyopenagi/agents/om-raheja/transcribe_agent/config.json b/pyopenagi/agents/om-raheja/transcribe_agent/config.json deleted file mode 100644 index 93089ef..0000000 --- a/pyopenagi/agents/om-raheja/transcribe_agent/config.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "transcribe_agent", - "description": [ - "You are an agent who can transcribe audio from the microphone into text. " - ], - "tools": [ - "transcriber/transcriber" - ], - "meta": { - "author": "Om Raheja", - "version": "0.0.1", - "license": "CC0" - } -} diff --git a/pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt b/pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt deleted file mode 100644 index d7d6bed..0000000 --- a/pyopenagi/agents/om-raheja/transcribe_agent/meta_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -RealtimeSTT