From a3219385bfa8dc7c6fc112f1c005f7e3b5498b1d Mon Sep 17 00:00:00 2001 From: Om Raheja Date: Sat, 31 Aug 2024 11:17:57 -0400 Subject: [PATCH] added getch and other helpful stuff in terminal --- .gitignore | 2 + agent_repl.py | 116 ++++++++++-------- .../source/agent_developer/agent_database.rst | 2 + .../agents/example/transcribe_agent/agent.py | 2 +- 4 files changed, 69 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 0bb3e374..ecba4bde 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ __pycache__ .env temp/ pyopenagi/environments/ +deplogs.txt +web/deplogs.txt # IPython profile_default/ diff --git a/agent_repl.py b/agent_repl.py index fdce5dda..b48ace59 100644 --- a/agent_repl.py +++ b/agent_repl.py @@ -27,34 +27,10 @@ def get_all_agents() -> dict[str, str]: return agent_names -def get_agent_list() -> List[Tuple[str, str]]: - return [ - ("academic_agent", "Research academic topics"), - ("travel_planner_agent", "Plan trips and vacations"), - ("creation_agent", "Create content for social media"), - ("cocktail_mixologist", "Design cocktails"), - ("cook_therapist", "Develop recipes and meal plans"), - ("fashion_stylist", "Design outfits and styles"), - ("festival_card_designer", "Design festival cards"), - ("fitness_trainer", "Create workout plans"), - ("game_agent", "Recommend games"), - ("interior_decorator", "Design interior spaces"), - ("language_tutor", "Provide language learning assistance"), - ("logo_creator", "Design logos"), - ("math_agent", "Solve mathematical problems"), - ("meme_creator", "Create memes"), - ("music_composer", "Compose music"), - ("plant_care_assistant", "Provide plant care advice"), - ("rec_agent", "Recommend movies and TV shows"), - ("story_teller", "Create short stories"), - ("tech_support_agent", "Provide tech support"), - ("travel_agent", "Plan travel itineraries") - ] - -def display_agents(agents: List[Tuple[str, str]]): +def display_agents(agents: List[str]): print("Available Agents:") - for i, (name, description) in enumerate(agents, 1): - print(f"{i}. {name}: {description}") + for i, (name) in enumerate(agents, 1): + print(f"{i}. {name}") def get_user_choice(agents: List[Tuple[str, str]]) -> Tuple[str, str]: while True: @@ -98,37 +74,73 @@ def main(): max_workers=500 ) + startScheduler() - # try to load pyfzf - chosen_agent = "" - try: - from pyfzf.pyfzf import FzfPrompt - fzf = FzfPrompt() - agents = get_all_agents() - chosen_agent = agents[fzf.prompt(list(agents.keys()))[0]] + print(""" + \033c + Welcome to the Agent REPL. + Please select an agent by pressing tab. + To exit, press Ctrl+C. + """) + + # check for getch + getch = None + try: + from getch import getch except ImportError: - print("pyfzf is not installed. Falling back to default reader.") - agents = get_agent_list() - display_agents(agents) - chosen_agent, _ = "example/" + get_user_choice(agents) + print(""" +The terminal will NOT look pretty without getch. Please install it. +pip install getch + """) + getch = input - task = get_user_task() - startScheduler() + # shell loop + try: + while True: + chosen_agent = "" + agents = get_all_agents() + + # shell prompt + print(f"[{args.llm_name}]> ", end="") + + # check if the user put in a tab + if getch() != "\t": + continue - try: - agent_id = submitAgent( - agent_name=chosen_agent, - task_input=task - ) - - awaitAgentExecution(agent_id) - except Exception as e: - print(f"An error occurred: {str(e)}") - finally: - stopScheduler() - clean_cache(root_directory="./") + + try: + from pyfzf.pyfzf import FzfPrompt + fzf = FzfPrompt() + + selected = fzf.prompt(list(agents.keys())) + + if (len(selected) == 0): + print("No agent selected. Please try again.") + continue + + chosen_agent = agents[selected[0]] + + except ImportError: + print("pyfzf is not installed. Falling back to default reader.") + display_agents(list(agents.keys())) + chosen_agent, _ = "example/" + get_user_choice(agents) + + task = get_user_task() + + try: + agent_id = submitAgent( + agent_name=chosen_agent, + task_input=task + ) + + awaitAgentExecution(agent_id) + except Exception as e: + print(f"An error occurred: {str(e)}") + except KeyboardInterrupt: + stopScheduler() + clean_cache(root_directory="./") if __name__ == "__main__": main() diff --git a/docs/source/agent_developer/agent_database.rst b/docs/source/agent_developer/agent_database.rst index 48fa021e..e0faefcf 100644 --- a/docs/source/agent_developer/agent_database.rst +++ b/docs/source/agent_developer/agent_database.rst @@ -10,6 +10,8 @@ Interact with the database to Source https://github.com/agiresearch/AIOS/blob/main/pyopenagi/agents/interact.py. +If you are creating a PR with an example agent, please upload it as well. + You can download agents with the following command: .. code-block:: bash diff --git a/pyopenagi/agents/example/transcribe_agent/agent.py b/pyopenagi/agents/example/transcribe_agent/agent.py index c412d40a..ba168266 100755 --- a/pyopenagi/agents/example/transcribe_agent/agent.py +++ b/pyopenagi/agents/example/transcribe_agent/agent.py @@ -12,7 +12,7 @@ def manual_workflow(self): workflow = [ { "message": "figure out what to do with the audio", - "tool_use": [ "transcriber"], + "tool_use": [ "transcriber/transcriber"], }, { "message": "organize the information and respond to the user",