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

Fix execute_command coming from plugins #4729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,8 @@ def signal_handler(signum, frame):
command_name, arguments
)
command_result = execute_command(
self.command_registry,
command_name,
arguments,
command_name=command_name,
arguments=arguments,
agent=self,
)
result = f"Command {command_name} returned: " f"{command_result}"
Expand Down
7 changes: 3 additions & 4 deletions autogpt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Dict

from autogpt.agent.agent import Agent
from autogpt.models.command_registry import CommandRegistry


def is_valid_int(value: str) -> bool:
Expand Down Expand Up @@ -79,7 +78,6 @@ def map_command_synonyms(command_name: str):


def execute_command(
command_registry: CommandRegistry,
command_name: str,
arguments: dict[str, str],
agent: Agent,
Expand All @@ -89,12 +87,13 @@ def execute_command(
Args:
command_name (str): The name of the command to execute
arguments (dict): The arguments for the command
agent (Agent): The agent that is executing the command

Returns:
str: The result of the command
"""
try:
cmd = command_registry.commands.get(command_name)
cmd = agent.command_registry.commands.get(command_name)

# If the command is found, call it with the provided arguments
if cmd:
Expand All @@ -106,7 +105,7 @@ def execute_command(
# TODO: Change these to take in a file rather than pasted code, if
# non-file is given, return instructions "Input should be a python
# filepath, write your code to file and try again
for command in agent.prompt.commands:
for command in agent.ai_config.prompt_generator.commands:
if (
command_name == command["label"].lower()
or command_name == command["name"].lower()
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_execute_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from autogpt.agent import Agent
from autogpt.app import execute_command


def check_plan():
return "hi"


def test_execute_command_plugin(agent: Agent):
"""Test that executing a command that came from a plugin works as expected"""
agent.ai_config.prompt_generator.add_command(
"check_plan",
"Read the plan.md with the next goals to achieve",
{},
check_plan,
)
command_name = "check_plan"
arguments = {}
command_result = execute_command(
command_name=command_name,
arguments=arguments,
agent=agent,
)
assert command_result == "hi"
Loading