Skip to content

Commit

Permalink
added getch and other helpful stuff in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
om-raheja committed Aug 31, 2024
1 parent c5bbefa commit a321938
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ __pycache__
.env
temp/
pyopenagi/environments/
deplogs.txt
web/deplogs.txt

# IPython
profile_default/
Expand Down
116 changes: 64 additions & 52 deletions agent_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
2 changes: 2 additions & 0 deletions docs/source/agent_developer/agent_database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyopenagi/agents/example/transcribe_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a321938

Please sign in to comment.