Building a TypeScript Version of Auto-GPT: Implementation and Insights
In this blog post, we will discuss the implementation of a TypeScript version of Auto-GPT. We will cover the architecture used, our observations on the system, hacks that significantly improved performance, and potential improvements and further ideas. If you have some knowledge of AutoGPT, you will find this journey and technical insights interesting and useful.
Architecture
We took an Object-Oriented Programming approach and added concepts from Domain Driven Design, specifically for commands or tools. This approach made the code base more maintainable and allowed for more abstraction and modularity.
The main control loop consisted of an Agent and a Memory class that handled coming up with a plan of action, which were stored in memory to be used later as part of the prompt. The acting system uses a commandBus where commands can be registered and then invoked by the Agent.
The memory module saved all the thoughts generated by the agent and then re-structured them when injected as part of the prompt. We spent a lot of time trying to come up with different ways of constructing the memory but found it relatively easy to do given that prompts were derived from a get method in the memory class.
Type Validation
We found that if a return value from GPT-3.5 didn’t match the required JSON format, re-querying the LLM would often result in the correct format. Our implementation has a wrapper for this in an OpenAiManager class that continually queries (with max retries) until the expected type is returned.
Docker Container to Execute Code
All interactions done on a code and command level are run within a docker container to avoid any arbitrary running of code and commands on the device.
Command Bus Design
The commandBus in this architecture allows for the modular addition of commands through registering to command handlers. This allows for easy extensibility of the system by adding new commands as required without affecting the existing codebase.
Modularity
The command system's encapsulation enabled GPT-4 to generate fully functional commands and tests for it. The whole searchGoogle and queryWolframAlpha section in the command handler was written by GPT-4.
Improvements
Adding too many commands can confuse the agent and negatively impact its performance. In the future, versions of the architecture will have the ability to choose specific commands. Also, the planning aspect of the agent’s behavior was often poor, resulting in inefficient command execution. The implementation of a meta-cognition agent would likely help improve this aspect of the architecture.
An improvement for the architecture would be to allow the spawning of agents with specific abilities, rather than relying on a single agent to perform all tasks. This could potentially improve the overall performance of the system and allow for better task distribution.
The implementation of a good interface and logging system would be helpful for future development.
Finally, while the GPT-3.5 architecture was used in the current implementation, it may not be sufficient for more complex tasks. Further research and experimentation with different architectures may be necessary for more advanced applications.
Closing Thoughts
Our implementation of Auto-GPT in TypeScript was successful. We created a calculator app in Python, tested the code, wrote tests, ran the tests, and then ran the calculator app. Based on our observations and interactions with the agent, the main improvements we will be making are to the planning element of the agent and how memory is retrieved.
The command architecture is flexible and can accommodate a wide variety of command implementations, making the system adaptable to various use cases. The use of the optional correctional callback function adds an extra layer of versatility to the system, allowing for more complex queries to be made while ensuring the validity of the commands.