How to Build a General-Purpose AI Agent in 131 Lines of Python
The following article originally appeared on Hugo Bowne-Anderson’s newsletter, Vanishing Gradients, and is being republished here with the author’s permission. In this post, we’ll build two AI agents from scratch in Python. One will be a coding agent, the other a search agent. Why have I called this post “How to Build a General-Purpose AI […]

In this article, we will explore how to build a general-purpose AI agent in just 131 lines of Python. The concept of a general-purpose AI agent might seem complex, but by breaking it down into two distinct agents—a coding agent and a search agent—we can understand the underlying principles and patterns that make these agents so versatile.
First, let's consider the coding agent. This agent is designed to write code, but as we will see, its capabilities extend far beyond mere programming. The coding agent we will build will have four primary tools: read, write, edit, and bash. These tools enable it to perform a wide range of tasks, from organizing files and managing media to handling personal productivity and content creation.
To illustrate the coding agent's versatility, imagine using it to clean your desktop. The agent can scan your files, identify duplicates, and sort them into organized folders. It can also rename vacation photos with dates, making it easy to locate specific memories. For media management, the coding agent can rename TV episodes according to a standardized format or convert images to different file types. In terms of personal productivity, the agent can compile a packing list from past trips or search through all your notes for a specific piece of information.
The coding agent's ability to write code also extends to content creation. It can combine multiple documents into one, convert file formats, or perform find-and-replace operations across multiple files. By leveraging these capabilities, the coding agent becomes a powerful tool for handling various tasks that might not initially seem related to coding.
Now, let's shift our focus to the search agent. This agent is designed to find information efficiently, and it follows a similar pattern to the coding agent. The search agent can be applied to a wide range of scenarios, from locating specific files to discovering relevant data from large datasets. By understanding the underlying principles of both agents, we can appreciate how general-purpose AI agents can be built to tackle diverse problems.
The key takeaway from this exploration is that coding agents are not limited to writing code; they are computer-using agents that happen to excel at programming. This realization challenges the traditional view of what constitutes a general-purpose AI agent. By providing an LLM (Large Language Model) with shell access, we unlock a vast array of possibilities, enabling the agent to perform tasks that might not be immediately apparent.
In conclusion, building a general-purpose AI agent in 131 lines of Python is not only possible but also surprisingly effective. By understanding the underlying patterns and tools used in both the coding and search agents, we can appreciate the versatility and potential of these AI agents. Whether you're tackling file organization, media management, or content creation, a well-designed general-purpose AI agent can simplify complex tasks and enhance productivity. As we continue to develop and refine these agents, it's essential to recognize their broad applicability and the innovative ways they can be utilized.










