Skip to content

amitb-dev/ai-code-assistant

Repository files navigation

Python AI Code Assistant (Gemini Agent)

This is a Python-based CLI agent built to automate coding tasks by autonomously reading, writing, and executing code within a sandboxed project. It uses Google's Gemini API for its core reasoning and function-calling capabilities.

Project Status & Disclaimer

This is a guided project I completed as part of the Boot.dev backend curriculum. The primary goal was not to build a production-ready tool, but to gain a deep, practical understanding of the fundamentals behind agentic AI.

This is an educational tool and is NOT secure. It uses subprocess.run to execute code, and its security guardrails are basic. Do not run this in a sensitive environment.


Core Features

  • Multi-Step Agentic Loop: The agent can perform complex, multi-step tasks by maintaining a conversation history and feeding the results of its actions (the "feedback loop") back into its own context.
  • Gemini Function Calling: Uses Google's Gemini API to parse natural language prompts (e.g., "fix this bug") into structured function calls.
  • Toolbelt: The agent is equipped with a "toolbelt" of Python functions to interact with the filesystem, including:
    • get_files_info (List files)
    • get_file_content (Read files)
    • write_file (Write/overwrite files)
    • run_python_file (Execute Python scripts)
  • Security Sandboxing: All file operations are sandboxed to a specific working_directory (./calculator). Any attempt by the AI to "escape" this directory (e.g., using ../ or /bin) is blocked.
  • Prompt Engineering: The agent is guided by a robust system prompt that acts as a "playbook" for complex tasks, forcing it to follow a specific strategy (Reproduce, Investigate, Fix, Verify).

See it in Action! (How to Run)

This repository is in the broken state by design. You can run the agent to watch it fix the bug.

1. Setup

# Clone the repo
git clone https://github.com/amitb-dev/ai-code-assistant
cd ai-code-assistant

# Create and activate virtual environment
uv venv
uv add google-genai python-dotenv

# Create your .env file
cp .env.example .env

Now, open .env and paste in your GEMINI_API_KEY.

2. Verify the Bug

Run the broken calculator. The precedence for + is wrong, so 3 + 7 * 2 will equal 20 instead of 17.

uv run calculator/main.py "3 + 7 * 2"

Output:

{
  "expression": "3 + 7 * 2",
  "result": 20
}

3. Run the Agent

Tell the agent to fix the bug. Use --verbose to watch its thought process.

uv run python main.py "fix the bug: 3 + 7 * 2 shouldn't be 20" --verbose

You will see the agent's multi-step loop as it:

  1. Runs the code and sees the "result": 20.
  2. Reads pkg/calculator.py and finds the "+": 3 bug.
  3. Writes a new pkg/calculator.py file with "+": 1.
  4. Runs the code again and sees the "result": 17.
  5. Gives a final report: "The bug is fixed."

4. Verify the Fix

Run the calculator one last time.

uv run calculator/main.py "3 + 7 * 2"

Output:

{
  "expression": "3 + 7 * 2",
  "result": 17
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages