Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent and agent manager tests #3116

Merged
merged 44 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c83667e
Update Python version and benchmark file in benchmark.yml
waynehamadi Apr 18, 2023
f4db77a
Refactor main function and imports in cli.py
waynehamadi Apr 18, 2023
81d6ae4
Update import statement in ai_config.py
waynehamadi Apr 18, 2023
59c28fb
Add set_temperature and set_memory_backend methods in config.py
waynehamadi Apr 18, 2023
296fab3
Remove unused import in prompt.py
waynehamadi Apr 18, 2023
ca3a441
Add goal oriented tasks workflow
waynehamadi Apr 18, 2023
5653b52
Added agent_utils to create agent
waynehamadi Apr 18, 2023
3327e1f
added pytest and vcrpy
waynehamadi Apr 18, 2023
4a339e1
added write file cassette
waynehamadi Apr 18, 2023
9cc126c
created goal oriented task write file with cassettes to not pay opena…
waynehamadi Apr 18, 2023
35e91a0
solve conflicts
waynehamadi Apr 18, 2023
712a449
add ability set azure because github workflow needs it off
waynehamadi Apr 19, 2023
af0fef1
solve conflicts in cli.py
waynehamadi Apr 19, 2023
11234de
black because linter fails
waynehamadi Apr 19, 2023
baaf4d1
solve conflict
waynehamadi Apr 19, 2023
fb5e916
setup github action to v3
Apr 19, 2023
fdbfa7a
fix conflicts
Apr 22, 2023
8793f67
Merge pull request #2461 from merwanehamadi/feature/create-smoke-test
richbeales Apr 22, 2023
61600b7
Merge pull request #2931 from riensen/fix/multiple-plugins
ntindle Apr 22, 2023
5b06290
Plugins: debug line always printed in plugin load
richbeales Apr 22, 2023
11dd1ef
Merge pull request #2936 from Significant-Gravitas/richbeales-patch-1
BillSchumacher Apr 22, 2023
125abad
add decorator to tests
Apr 22, 2023
48dd9e7
move decorator higher up
Apr 22, 2023
672d38f
init
rihp Apr 22, 2023
b22f47d
more tests
rihp Apr 22, 2023
afdacf8
Merge pull request #2946 from merwanehamadi/feature/add-decorator-to-…
ntindle Apr 22, 2023
d4124c7
passing tests
rihp Apr 22, 2023
dc6afa7
skip gitbranch decorator on ci
rihp Apr 22, 2023
7724bc2
Merge branch 'master' into tests-utils
rihp Apr 22, 2023
39434e9
decorator skiponci
rihp Apr 22, 2023
cc6a77f
black
rihp Apr 22, 2023
485aff3
Update tests/utils.py decorator of skipping ci
rihp Apr 22, 2023
042ff3c
black
rihp Apr 22, 2023
631307b
I oopsed the name
ntindle Apr 22, 2023
9d4219a
black
rihp Apr 22, 2023
6c0e467
finally
rihp Apr 22, 2023
f3b2afe
Merge pull request #2950 from rihp/tests-utils
ntindle Apr 22, 2023
22d6782
Merge branch 'Significant-Gravitas:master' into master
rihp Apr 23, 2023
142de88
Merge branch 'Significant-Gravitas:master' into master
rihp Apr 23, 2023
6ec960a
Merge branch 'Significant-Gravitas:master' into master
rihp Apr 23, 2023
ba30bf2
simple tests for agent and manager
rihp Apr 24, 2023
2a4062c
ísort
rihp Apr 24, 2023
5801247
Merge branch 'master' into agent_tests
ntindle Apr 24, 2023
7f44585
Merge branch 'master' into agent_tests
ntindle Apr 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from unittest.mock import MagicMock

import pytest

from autogpt.agent import Agent
from autogpt.chat import chat_with_ai
from autogpt.config import Config
from autogpt.speech import say_text
from autogpt.utils import clean_input


@pytest.fixture
def agent():
ai_name = "Test AI"
memory = MagicMock()
full_message_history = []
next_action_count = 0
command_registry = MagicMock()
config = Config()
system_prompt = "System prompt"
triggering_prompt = "Triggering prompt"
workspace_directory = "workspace_directory"

agent = Agent(
ai_name,
memory,
full_message_history,
next_action_count,
command_registry,
config,
system_prompt,
triggering_prompt,
workspace_directory,
)
return agent


def test_agent_initialization(agent):
assert agent.ai_name == "Test AI"
assert agent.memory == agent.memory
assert agent.full_message_history == []
assert agent.next_action_count == 0
assert agent.command_registry == agent.command_registry
assert agent.config == agent.config
assert agent.system_prompt == "System prompt"
assert agent.triggering_prompt == "Triggering prompt"


# More test methods can be added for specific agent interactions
# For example, mocking chat_with_ai and testing the agent's interaction loop
58 changes: 58 additions & 0 deletions tests/test_agent_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from typing import List

import pytest

from autogpt.agent.agent_manager import AgentManager
from tests.utils import requires_api_key


@pytest.fixture
def agent_manager():
return AgentManager()


@pytest.fixture
def task():
return "translate English to French"


@pytest.fixture
def prompt():
return "Translate the following English text to French: 'Hello, how are you?'"


@pytest.fixture
def model():
return "gpt-4"


@requires_api_key("OPENAI_API_KEY")
def test_create_agent(agent_manager, task, prompt, model):
key, agent_reply = agent_manager.create_agent(task, prompt, model)
assert isinstance(key, int)
assert isinstance(agent_reply, str)
assert key in agent_manager.agents


@requires_api_key("OPENAI_API_KEY")
def test_message_agent(agent_manager, task, prompt, model):
key, _ = agent_manager.create_agent(task, prompt, model)
user_message = "Please translate 'Good morning' to French."
agent_reply = agent_manager.message_agent(key, user_message)
assert isinstance(agent_reply, str)


@requires_api_key("OPENAI_API_KEY")
def test_list_agents(agent_manager, task, prompt, model):
key, _ = agent_manager.create_agent(task, prompt, model)
agents_list = agent_manager.list_agents()
assert isinstance(agents_list, list)
assert (key, task) in agents_list


@requires_api_key("OPENAI_API_KEY")
def test_delete_agent(agent_manager, task, prompt, model):
key, _ = agent_manager.create_agent(task, prompt, model)
success = agent_manager.delete_agent(key)
assert success
assert key not in agent_manager.agents