Build an AI-Agent: Mini-Cursor in Your Terminal


What if your terminal could think like a developer?
Meet Mini-Cursor, an AI-powered coding assistant that doesn't just generate code — it plans, acts, and learns like a real developer. It asks questions, makes decisions, runs terminal commands, and observes the output to guide the next step — all inside your terminal.
What is AI Agent?
Think of AI agents as computers with a brain, hands, and legs.
AI is just a brain — it thinks, responds, and tells you how to do things. For example, it can tell you the command to create a folder, but it won’t actually run that command for you.
But an AI Agent goes a step further. It doesn’t just tell you what to do — it actually does it.
It’s like giving AI a pair of hands and feet — the ability to act in the real world using tools you provide.
Analogy:
AI = Brain
Tools = Hands and Legs
When you connect the brain with real tools, you get an agent that can think and do.
How Can AI Agents Handle the Latest Tasks If They’re Pre-Trained?
It's true — traditional AI models are pre-trained on data that may be weeks or months old. They don’t automatically know the latest tools, APIs, or commands introduced yesterday.
So how do AI agents keep up?
Answer: By using tools that connect to the real world.
Instead of retraining the whole model (which takes time and resources), we let the AI call a tool — like hitting an API, running a script, or fetching real-time data. This allows it to stay current and execute live tasks, even if it was trained on older data.
The AI doesn’t need to “know everything” — it just needs to know how to find or run the thing that knows.
Here comes the real magic — prompting.
Even though AI models are pre-trained, you can still teach them new things at runtime by providing the right context through prompts.
So, if you’ve built a tool like run_command
, you simply describe how it works in the system prompt:
“
run_command
takes a list of command arguments, executes them in the terminal, and returns the result.”
Now, the AI understands it can use that tool — just like giving instructions to a junior developer.
By describing the tools clearly, you unlock the agent’s ability to:
Choose which tool is best for the task
Pass the correct input
React based on the result
Prompting acts like a bridge between the AI’s static brain and your dynamic environment.
In short, you don’t need to retrain the AI — you just need to give it a good prompt and the right tools.
What Is Mini-Cursor?
Mini-Cursor is an AI agent framework that mimics the problem-solving workflow of a software engineer.
The core technique behind Mini-Cursor is called Chain of Thought Prompting. Instead of jumping directly to the answer, the AI is encouraged to reason through each step — planning, acting, and evaluating along the way.
For example:
User Query: "Build a Todo app using React"
The AI doesn’t just respond with a full project at once.
Instead, it says:🧠: "I will scaffold a Vite React project using TypeScript."
🛠️:npm create vite@latest client -- --template react-ts
🧠 "React app scaffolded successfully."
❓: "What should we name the project?"
You can see the system prompt I used to enable this kind of structured thinking.
It plans, acts, observes, asks, and gives real results — just like a real assistant.
Mini-Cursor follows a reasoning and execution loop:
ask → plan → act → observe → output
This loop allows the agent to interact with the environment (like the terminal), clarify intent, and adapt based on real-time feedback — making it feel like a real developer assistant.
How I Built the AI Agent: Mini-Cursor
Now that we understand what AI agents are and how they work — let me walk you through how I built Mini-Cursor, a terminal-based AI agent that thinks like a developer and executes real commands step-by-step.
Import Libraries and Setup
Let’s walk through the main logic behind Mini-Cursor — how it uses OpenAI's model, processes each step, and connects to system-level tools.
import subprocess
from openai import OpenAI
from dotenv import load_dotenv
from openai.types.chat import ChatCompletionMessageParam
import json
from prompt import system_prompt
Load Environment and Initialize OpenAI Client
load_dotenv()
client = OpenAI()
Tools
This tool allows the agent to securely execute terminal commands.
def run_command(cmd: list[str]) -> str:
try:
result = subprocess.run(
cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
return result.stdout.strip()
except Exception as e:
return f"Command failed with error: {str(e)}"
Tool Registry
available_tool = {
"run_command": run_command,
}
Message Setup and Interaction Loop
messages: list[ChatCompletionMessageParam] = [
{"role": "system", "content": system_prompt}
]
Main Loop
This is where the magic happens — handling plan/act/ask/output steps dynamically.
while True:
query = input("> ")
messages.append({"role": "user", "content": query})
while True:
response = client.chat.completions.create(
model="gpt-4.1",
messages=messages,
response_format={"type": "json_object"},
)
messages.append(
{"role": "assistant", "content": response.choices[0].message.content}
)
parsed_json = json.loads(response.choices[0].message.content)
if parsed_json.get("step") == "plan":
print(f"🧠: {parsed_json.get('content')}")
continue
Handle “act” Step
The act
step is where the AI can actually perform tasks or respond to real-world changes. This is the stage where we allow it to interact with the environment — whether that's executing terminal commands, running scripts, or checking for the latest events using the tools we provide.
Unlike traditional AI, which can only suggest actions, the act
step bridges thought and execution.
This is the power of Chain of Thought Prompting.
if parsed_json.get("step") == "act":
tool_name = parsed_json.get("function")
tool_input = parsed_json.get("input")
print(f"🛠️: {tool_name} with input {tool_input}")
if available_tool[tool_name]:
output = ""
if tool_input:
output = available_tool[tool_name](tool_input)
else:
output = available_tool[tool_name]()
messages.append(
{
"role": "user",
"content": json.dumps({"step": "observe", "content": output}),
}
)
continue
Handle “ask” Step
if parsed_json.get("step") == "ask":
print(f"❓: {parsed_json.get('content')}")
askedQuery = input("> ")
messages.append(
{
"role": "user",
"content": json.dumps({"step": "observe", "content": askedQuery}),
}
)
continue
Final Output
if parsed_json.get("step") == "output":
print(f"Result: {parsed_json.get('content')}")
break
Links
Subscribe to my newsletter
Read articles from Karan Shaw directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Karan Shaw
Karan Shaw
I am Karan Shaw. I am MERN Stack developer exprienced in building responsive user interfaces using ReactJs and NextJs and developing backend services using MongoDB and ExpressJs