AutoGPT
AutoGPT copied to clipboard
Use `@command()` function decorator
Background
See #1272 @rhernaus
Optimize the
execute_command
function. The original function used a series ofif-elif
statements to determine the appropriate action based on the given command name. This structure made the code lengthy, harder to read, and difficult to maintain. By refactoring the function to use a dictionary that maps command names to their respective functions, we can improve readability, conciseness, and maintainability.
Changes
See https://github.com/Significant-Gravitas/Auto-GPT/pull/1272#issuecomment-1510688932
Commands are now registered like this:
@command()
def start_agent(name: str, task: str, prompt: str) -> str:
...
Or alternatively:
@command(name="start_agent", aliases=["start_new_agent"])
def do_start_agent(name: str, task: str, prompt: str) -> str:
...
They're later called with command(**arguments)
syntax, meaning arguments are assigned by name.
Documentation
Test Plan
PR Quality Checklist
- [x] My pull request is atomic and focuses on a single change.
- [x] I have thoroughly tested my changes with multiple different prompts.
- [x] I have considered potential risks and mitigations for my changes.
- [x] I have documented my changes clearly and comprehensively.
- [X] I have not snuck in any "extra" small tweaks changes
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
This is a duplicate of the command registry that is included in #757 but less advanced. Sorry but this is going to make it.