Building a Simple Terminal-Based AI Coding Assistant
Building a terminal-based AI agent that can assist with coding tasks. The idea was to keep it simple, let everything run in the terminal, and allow the AI to perform basic dev-related actions — like running shell commands or helping set up project structure.
The overall focus is on creating something that could eventually evolve into a coding assistant — maybe even one that can help with full-stack projects.
🎯 Objective
The aim was to build an AI agent that:
Works entirely through the terminal
Supports basic dev workflows like:
Creating folders and files
Running shell commands like
pip install,npm init, etc.Iteratively modifying things based on follow-up instructions
Has some minimal awareness of what it’s already done
Can break down tasks and complete them step by step
There was no frontend or GUI — just Python, the terminal, and the OpenAI API.
🧱 How It’s Set Up
The agent works in a loop: it takes a user input, decides what to do, executes an action (like a command), observes the result, and then continues.
Here's a very basic version of the code structure that powers the agent:
def run_command(cmd: str):
result = os.system(cmd)
return result
def get_weather(city: str):
url = f"https://wttr.in/{city}?format=%C+%t"
response = requests.get(url)
if response.status_code == 200:
return f"The weather in {city} is {response.text}."
return "Something went wrong"
A dictionary maps available functions like this:
available_tools = {
"get_weather": get_weather,
"run_command": run_command
}
The AI is prompted with a special instruction format to follow a fixed process:
Plan
Action
Observe
Output
For example:
{ "step": "plan", "content": "The user wants to install dependencies" }
{ "step": "action", "function": "run_command", "input": "npm install" }
{ "step": "observe", "output": "installed successfully" }
{ "step": "output", "content": "All packages installed." }
💬 Sample Interaction
The interaction looks something like this in the terminal:
\>What's the weather in Bangalore?
🧠: The user wants to check the weather in Bangalore
🛠️: Calling Tool: get_weather with input bangalore
🤖: The weather in bangalore is Partly cloudy +30°C.
Or something more dev-focused:
\>Create a folder called backend
🧠: Planning to create a folder
🛠️: Calling Tool: run_command with input mkdir backend
🤖: Folder created successfully
🔧 Why This Flow?
The step-by-step format forces the agent to work like a simple loop: plan, act, wait, repeat. This avoids the AI jumping to conclusions and allows for better control in each phase.
Each tool is lightweight, and the agent just reacts based on the JSON-like output it receives from the OpenAI model. It’s not sophisticated, but it creates a nice base for more complex capabilities later.
🧠 Observations
Keeping the flow controlled (with explicit planning and observation steps) makes debugging easier.
Even with simple tools like
os.system(), the agent can already interact meaningfully with the terminal.Adding more tools like
read_file,write_file, or even a basic project scaffolding tool could make it more useful.Iterative development — where the user says something like “now add login functionality” — will need smarter file parsing and awareness of existing content.
📌 Summary
This project sets up a basic terminal-based AI agent that can respond to commands, plan actions step-by-step, and handle simple development-related tasks. The interaction format keeps things structured, and the tools are easy to extend. The setup could be a helpful base for building out more advanced capabilities for dev workflows in a terminal-driven environment.
