DEV Community

Cover image for Build Your Own Local AI Agent (Part 3): The Code Archaeologist 🔦
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on

Build Your Own Local AI Agent (Part 3): The Code Archaeologist 🔦

In Part 2, we queried data. Now, let's document code.

We all have that one file. legacy_math.py. No comments. Variables named x, y, z. You're afraid to touch it.

Meet the Private Code Archaeologist. An agent that reads your code, understands it, and comments it for you—locally.

The Goal

  1. Read a target file.
  2. Identify undocumented functions.
  3. Generate professional Google-style DocStrings.
  4. Edit the file in place.

The Architecture

The Architecture

The Power of Local

Why local? Because you don't want to paste your proprietary algorithms into ChatGPT. With Goose + Ollama, your IP stays on your SSD.

The Recipe

We instruct Goose to use the Developer Extension (which can read/write files).

title: Code Archaeologist
instructions: |
  1. Read the file.
  2. For every function, write a DocString explaining Args & Returns.
  3. Overwrite the file with the new content.
  4. Do NOT change the logic.
Enter fullscreen mode Exit fullscreen mode

Seeing it in Action

We used gpt-oss:20b for this. The model correctly identified a "Haversine formula" buried in math variables and added a perfect explanation.

# Before
def f2(lat1, lon1...): ...

# After (Agent Generated)
def f2(lat1, lon1, lat2, lon2):
    """
    Compute the great‑circle distance...
    Uses the haversine formula...
    """
    ...
Enter fullscreen mode Exit fullscreen mode

Output Example 1

Output Example 2

Next Up: The grand finale—[Part 4]: Handling Sensitive PII Data.

Top comments (0)