Cursor AI 🤖: Giving AI a Keyboard, a Terminal, and a Brain

View on GitHub

🔍 What is Agentic AI?

Agentic AI refers to a class of artificial intelligence that doesn't just respond — it acts. Unlike traditional chatbots, which passively return answers, Agentic AIs plan, decide, and take action using tools provided by the developer. They mimic the way a human agent would think through a task:

“What’s the user asking? What steps should I take? What tools do I need? What did I observe? Now what should I do next?”

This makes Agentic AI the brain behind AI agents like AutoGPT, GPT Engineer, and DevGPT, and now — your very own Cursor-like AI Developer Assistant.

⚙️ Core Components of an Agentic AI (Its Arms & Legs 🦾🧠)

To behave agentically, the AI needs:

  • A System Prompt (Brain 🧠): This defines how the AI reasons, plans, and uses tools.

  • Tools (Arms 🤖): Functions that can do real-world things (file creation, API calls, etc.).

  • Planning + Observation Loop (Legs 🦿): The ability to:

    1. Plan the next step

    2. Call a tool

    3. Observe output

    4. Plan again

    5. Output results

This feedback loop enables autonomy.

🏗️ Tools I Built (The Arms)

Here are the core tools I built for the Agent:

1. create_file(filename, content)

A platform-independent file creation tool that works natively on Windows, Linux, or macOS using Python’s built-in functions (no shell commands). This replaced echo, touch, and powershell.

pythonCopyEditdef create_file(filename: str, content: str):
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    with open(filename, "w", encoding="utf-8") as f:
        f.write(content)
    return f"✅ File '{filename}' created successfully."

2. make_dir(path)

Creates directories recursively. The agent uses this when starting new projects.

pythonCopyEditdef make_dir(path: str):
    os.makedirs(path, exist_ok=True)
    return f"✅ Directory '{path}' created."

3. get_weather(city)

Fetches weather data using wttr.in for demo purposes and showing external API access.

4. run_command(cmd)

Executes terminal commands safely (used rarely, mostly for diagnostics or listing files).

🧠 How the Agent Thinks (Planning System Prompt)

The agent uses a carefully crafted system prompt that instructs it to:

  • Analyze the user query

  • Plan a step

  • Choose the right tool

  • Perform one action at a time

  • Observe the result

  • Continue reasoning

  • Produce a final answer

🧾 Output Format:

jsonCopyEdit{
  "step": "plan" | "action" | "observe" | "output",
  "content": "Explanation",
  "function": "Tool name (if action)",
  "input": "Tool input (string or object)"
}

This gives the agent a structure — like a reasoning chain.

💡 What is Natural Programmatic Language (NPL)?

Natural Programmatic Language (NPL) is how the AI speaks to your system — in structured JSON steps instead of plain text.

  • It’s halfway between natural language and code

  • Enables reasoning + execution + safety

  • Prevents hallucination or accidental file corruption

NPL turns GPT from a text bot ➝ into a developer assistant


💻 How the Agent Generated a TODO App from Scratch

Here’s how the agent built a complete HTML + CSS + JavaScript TODO app:

  1. 🧠 Plan: “User wants a TODO app in HTML/JS”

  2. 🔨 Create Directory: make_dirtodo-app/

  3. 🔨 Create index.html with form + list structure

  4. 🔨 Create style.css for basic styling

  5. 🔨 Create script.js with addTodo, removeTodo, localStorage logic

  6. 🔁 Observed each file success

  7. Output: “Your TODO app has been created with index.html, style.css, and script.js”

You didn’t write a line of code — the AI acted autonomously.


🖱️ How I Made It Act Like Cursor AI

Cursor AI is an AI IDE that can:

  • Write files

  • Modify code

  • Think step-by-step

  • Use tools like createFile() or runTests()

I mimicked that behavior by:

  • Writing native Python tools for file & directory creation

  • Using OpenAI's chat.completions.create() in a reasoning loop

  • Adding structured observations and state

  • Giving it memory (messages[]) just like how Cursor does

The result?

✅ A fully agentic system that builds code, modifies files, reasons, and waits for results — like a junior dev assistant!


🚀 Final Thoughts & Takeaways

This is more than just automation — this is an AI that thinks, acts, and builds.

🧰 Tech Stack:

  • Python

  • OpenAI GPT-4.1 (JSON mode)

  • Dotenv

  • Requests

  • Platform-aware design

0
Subscribe to my newsletter

Read articles from Vidya Sagar Mehar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vidya Sagar Mehar
Vidya Sagar Mehar