forked from Significant-Gravitas/AutoGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/challenge memory management (Significant-Gravitas#3425)
Co-authored-by: JS <[email protected]> Co-authored-by: Richard Beales <[email protected]>
- Loading branch information
1 parent
4f72ee7
commit cdd91f7
Showing
9 changed files
with
1,649 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--level", action="store", default=None, type=int, help="Specify test level" | ||
) | ||
|
||
|
||
def pytest_configure(config): | ||
config.option.level = config.getoption("--level") | ||
|
||
|
||
@pytest.fixture | ||
def user_selected_level(request) -> int: | ||
## used for challenges in the goal oriented tests | ||
return request.config.option.level |
Empty file.
1,454 changes: 1,454 additions & 0 deletions
1,454
...egration/challenges/memory/cassettes/test_memory_challenge_a/test_memory_challenge_a.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
tests/integration/challenges/memory/test_memory_challenge_a.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import pytest | ||
|
||
from autogpt.agent import Agent | ||
from autogpt.commands.file_operations import read_file, write_to_file | ||
from tests.integration.agent_utils import run_interaction_loop | ||
from tests.integration.challenges.utils import get_level_to_run | ||
from tests.utils import requires_api_key | ||
|
||
|
||
@pytest.mark.vcr | ||
@requires_api_key("OPENAI_API_KEY") | ||
def test_memory_challenge_a( | ||
memory_management_agent: Agent, user_selected_level: int | ||
) -> None: | ||
""" | ||
The agent reads a file containing a task_id. Then, it reads a series of other files. | ||
After reading 'n' files, the agent must write the task_id into a new file. | ||
Args: | ||
memory_management_agent (Agent) | ||
user_selected_level (int) | ||
""" | ||
|
||
level_currently_beaten = 3 | ||
max_level = 3 | ||
num_files = get_level_to_run(user_selected_level, level_currently_beaten, max_level) | ||
|
||
task_id = "2314" | ||
create_instructions_files(memory_management_agent, num_files, task_id) | ||
|
||
try: | ||
run_interaction_loop(memory_management_agent, 40) | ||
# catch system exit exceptions | ||
except SystemExit: | ||
file_path = str(memory_management_agent.workspace.get_path("output.txt")) | ||
content = read_file(file_path) | ||
assert task_id in content, f"Expected the file to contain {task_id}" | ||
|
||
|
||
def create_instructions_files( | ||
memory_management_agent: Agent, | ||
num_files: int, | ||
task_id: str, | ||
base_filename: str = "instructions_", | ||
) -> None: | ||
""" | ||
Creates a series of instructions files for the memory challenge. | ||
Args: | ||
memory_management_agent (Agent) | ||
num_files (int) | ||
task_id (str) | ||
base_filename (str, optional) | ||
""" | ||
for i in range(1, num_files + 1): | ||
content = generate_content(i, task_id, base_filename, num_files) | ||
file_name = f"{base_filename}{i}.txt" | ||
file_path = str(memory_management_agent.workspace.get_path(file_name)) | ||
write_to_file(file_path, content) | ||
|
||
|
||
def generate_content( | ||
index: int, task_id: str, base_filename: str, num_files: int | ||
) -> str: | ||
""" | ||
Args: | ||
index: int | ||
task_id: str | ||
base_filename: str | ||
num_files: int | ||
Returns: str | ||
""" | ||
if index == 1: | ||
return ( | ||
f"This task_id is {task_id}\nRead the file {base_filename}{index + 1}.txt" | ||
) | ||
if index != num_files: | ||
return f"Read the file {base_filename}{index + 1}.txt" | ||
return "Write the task_id into the file output.txt\nShutdown" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
|
||
def get_level_to_run( | ||
user_selected_level: Optional[int], | ||
level_currently_beaten: Optional[int], | ||
max_level: int, | ||
) -> int: | ||
""" | ||
Determines the appropriate level to run for a challenge, based on user-selected level, level currently beaten, and maximum level. | ||
Args: | ||
user_selected_level (int | None): The level selected by the user. If not provided, the level currently beaten is used. | ||
level_currently_beaten (int | None): The highest level beaten so far. If not provided, the test will be skipped. | ||
max_level (int): The maximum level allowed for the challenge. | ||
Returns: | ||
int: The level to run for the challenge. | ||
Raises: | ||
ValueError: If the user-selected level is greater than the maximum level allowed. | ||
""" | ||
if user_selected_level is None: | ||
if level_currently_beaten is None: | ||
pytest.skip( | ||
"No one has beaten any levels so we cannot run the test in our pipeline" | ||
) | ||
# by default we run the level currently beaten. | ||
return level_currently_beaten | ||
if user_selected_level > max_level: | ||
raise ValueError(f"This challenge was not designed to go beyond {max_level}") | ||
return user_selected_level |
Empty file.