mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-04 23:04:28 +01:00
Fix execute_command coming from plugins (#4730)
This commit is contained in:
@@ -291,9 +291,8 @@ class Agent:
|
||||
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}"
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Dict, List, Union
|
||||
|
||||
from autogpt.agent.agent import Agent
|
||||
from autogpt.agent.agent_manager import AgentManager
|
||||
from autogpt.commands.command import CommandRegistry, command
|
||||
from autogpt.commands.command import command
|
||||
from autogpt.commands.web_requests import scrape_links, scrape_text
|
||||
from autogpt.processing.text import summarize_text
|
||||
from autogpt.speech import say_text
|
||||
@@ -84,7 +84,6 @@ def map_command_synonyms(command_name: str):
|
||||
|
||||
|
||||
def execute_command(
|
||||
command_registry: CommandRegistry,
|
||||
command_name: str,
|
||||
arguments: dict[str, str],
|
||||
agent: Agent,
|
||||
@@ -94,12 +93,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:
|
||||
@@ -111,7 +111,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()
|
||||
|
||||
24
tests/unit/test_execute_command.py
Normal file
24
tests/unit/test_execute_command.py
Normal file
@@ -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"
|
||||
Reference in New Issue
Block a user