PythonGoogle Gemini APIFunction Calling

PCA — Personal Coding Assistant

An AI agent powered by Google's Gemini API that takes a natural-language prompt and autonomously reads files, writes code, and executes Python scripts — iterating up to 20 times until the task is complete.

Features

  • Function calling: the model decides which tools to invoke based on the task
  • File operations: read files, list directories, write or modify code
  • Code execution: run Python scripts and feed the output back to the model
  • Multi-turn loop: continues iterating until it reaches a final answer or the step limit
  • Verbose mode: log each function call and response for debugging

How It Works

PCA sends a user prompt to Gemini with a set of available function declarations. When the model decides to call a function, PCA executes it and sends the result back as the next input. This continues until the model returns a final text response with no pending function calls.

The function registry includes:

  • get_file_content — read any file in the working directory
  • get_files_info — list files and metadata in a directory
  • write_file — write or overwrite a file with new content
  • run_python_file — execute a Python script and capture stdout/stderr

Each function is a plain Python function registered by name. Adding new capabilities is a matter of adding a new file to functions/ and registering it.

Usage

python3 main.py "refactor main.py to use type hints throughout"
python3 main.py "write unit tests for stats.py" --verbose

Tech Stack

  • Language: Python 3.13+
  • AI API: Google Gemini (google-genai SDK)
  • Config: python-dotenv for API key management
  • Architecture: Function-calling agent loop (up to 20 iterations)