diff --git a/autogpt/app.py b/autogpt/app.py index 3166e70d0..eb5851349 100644 --- a/autogpt/app.py +++ b/autogpt/app.py @@ -276,9 +276,9 @@ def list_agents(): """List all agents Returns: - list: A list of all agents + str: A list of all agents """ - return AGENT_MANAGER.list_agents() + return "List of agents:\n" + "\n".join([str(x[0]) + ": " + x[1] for x in AGENT_MANAGER.list_agents()]) def delete_agent(key: str) -> str: diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py new file mode 100644 index 000000000..21982f7e6 --- /dev/null +++ b/tests/unit/test_commands.py @@ -0,0 +1,18 @@ +import autogpt.agent.agent_manager as agent_manager +from autogpt.app import start_agent, list_agents +import unittest +from unittest.mock import patch, MagicMock + + +class TestCommands(unittest.TestCase): + def test_make_agent(self): + with patch("openai.ChatCompletion.create") as mock: + obj = MagicMock() + obj.response.choices[0].messages[0].content = "Test message" + mock.return_value = obj + start_agent("Test Agent", "chat", "Hello, how are you?", "gpt2") + agents = list_agents() + self.assertEqual("List of agents:\n0: chat", agents) + start_agent("Test Agent 2", "write", "Hello, how are you?", "gpt2") + agents = list_agents() + self.assertEqual("List of agents:\n0: chat\n1: write", agents)