medium.com 7 min read Original Source

Cyclops: Building a Fully Local AI Coding Agent, and the Three Bugs That Were Quietly Sabotaging It

A LangGraph pipeline that never sends code to the cloud, why file navigation turned out to be harder than code generation, and what broke when I ran it against real Django and Flask bugs.

Most AI coding tools assume your code goes to the cloud. Copilot sends it to Microsoft. Cursor sends it to Anthropic or OpenAI by default. Codeium sends it somewhere. For most developers that’s a non-issue. For proprietary systems, client codebases, regulated industries, or air-gapped environments, it’s a dealbreaker.

I wanted something that runs entirely on local hardware: no internet required after setup, no API costs, and a guarantee that code never leaves the machine. Six months later, that’s Cyclops. It scored 89/100 on a ten-task benchmark I built against a production Flask codebase. Against five real Django bugs pulled from SWE-bench Lite, one passed on the first try. The other four each failed for a different reason in the surrounding pipeline: a wrong file targeted, a correct patch rejected twice by an overzealous verifier, and an irrelevant file pulled into scope. Fixing those three issues brought all five to a pass. Here’s how it’s built, what actually went wrong, and what I changed.

The real problem is finding the right file

Most discussions about AI coding agents focus on generation quality: can the model write correct Python, can it handle edge cases. That matters, but it isn’t the hardest part. The hardest part is navigation.

A real codebase has hundreds or thousands of files. Tell an agent to “support callable path argument in FilePathField” and it has to find that class before it can touch it. FilePathField lives in django/db/models/fields/__init__.py, not fields.py, not models.py, not any file with “path” in the name. It’s in a sub-package’s __init__.py, indexed under the import path django.db.models.fields.FilePathField. A naive agent using keyword search or embedding similarity finds the wrong file roughly half the time on a codebase this size, and editing the wrong file does real damage. This is what I spent most of my six months on.

How Cyclops is built

Cyclops is a LangGraph state machine with seven specialized agents, each with a narrow responsibility, passing structured state to the next.

User Goal
    │
    ▼
Profiler         builds the repo graph (symbols, call graph, registries)
    │
    ▼
Planner          decomposes the goal into ordered tasks with file hints
    │
    ▼
Navigator        resolves each task to an exact file, symbol, and line range
    │
    ▼
Impact Analyzer  finds callers, tests, and side-effect files
    │
    ▼
Editor           generates a targeted unified diff
    │
    ▼
Verifier         applies the diff to an isolated sandbox and runs tests
    │
    ▼
Semantic Verifier  confirms the patch addresses the stated goal
    │
    ▼
Supervisor       approves, retries, or escalates
User Goal
    │
    ▼
Profiler         builds the repo graph (symbols, call graph, registries)
    │
    ▼
Planner          decomposes the goal into ordered tasks with file hints
    │
    ▼
Navigator        resolves each task to an exact file, symbol, and line range
    │
    ▼
Impact Analyzer  finds callers, tests, and side-effect files
    │
    ▼
Editor           generates a targeted unified diff
    │
    ▼
Verifier         applies the diff to an isolated sandbox and runs tests
    │
    ▼
Semantic Verifier  confirms the patch addresses the stated goal
    │
    ▼
Supervisor       approves, retries, or escalates

No file gets touched until the full chain passes. The verifier applies the diff to a temporary copy of the repo and runs the relevant tests there. Only if those tests pass does anything get written to the real files on disk.

The navigator: how file selection actually works

The navigator is the component that matters most, and it works in three steps.

Building the call graph. On the first run against a repo, Cyclops uses tree-sitter to parse every Python file and build a code graph. For Django, roughly 2,285 files, this produces about 7,400 symbols, 30,000 graph nodes, and 42,000 graph edges, including a full PageRank pass over the graph, in around twelve seconds.

Resolving symbols. When the planner says “edit FilePathField,” the navigator queries the graph for a node named FilePathField. That node carries the exact file path, line number, and type. No guessing involved.

Validating the planner’s file hints. The planner sometimes gets the file wrong. It might point at django/db/models/fields/files.py when FilePathField actually lives in django/db/models/fields/__init__.py, and both files are real, which makes the mistake easy to miss. The navigator checks whether the named symbols actually exist in the files the planner named. If they don’t, it falls through to the graph, which is the authority on where a symbol actually lives:

bool:
sym_set = {s.lower() for s in symbols if s}
for fi in file_infos:
path = Path(fi.path)
if not path.exists():
continue
content = path.read_text(encoding="utf-8", errors="replace")
# Fast regex pass
for sym in sym_set:
if re.search(rf'b(class|def)s+{re.escape(sym)}b',
content, re.IGNORECASE):
return True
# AST pass for exact match
try:
tree = ast.parse(content)
for node in ast.walk(tree):
if isinstance(node, (ast.ClassDef, ast.FunctionDef)):
if node.name.lower() in sym_set:
return True
except SyntaxError:
pass
return False” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

def _symbols_present_in_files(self, symbols, file_infos) -> bool:
    sym_set = {s.lower() for s in symbols if s}
    for fi in file_infos:
        path = Path(fi.path)
        if not path.exists():
            continue
        content = path.read_text(encoding="utf-8", errors="replace")
        # Fast regex pass
        for sym in sym_set:
            if re.search(rf'b(class|def)s+{re.escape(sym)}b',
                         content, re.IGNORECASE):
                return True
        # AST pass for exact match
        try:
            tree = ast.parse(content)
            for node in ast.walk(tree):
                if isinstance(node, (ast.ClassDef, ast.FunctionDef)):
                    if node.name.lower() in sym_set:
                        return True
        except SyntaxError:
            pass
    return False
def _symbols_present_in_files(self, symbols, file_infos) -> bool:
    sym_set = {s.lower() for s in symbols if s}
    for fi in file_infos:
        path = Path(fi.path)
        if not path.exists():
            continue
        content = path.read_text(encoding="utf-8", errors="replace")
        # Fast regex pass
        for sym in sym_set:
            if re.search(rf'b(class|def)s+{re.escape(sym)}b',
                         content, re.IGNORECASE):
                return True
        # AST pass for exact match
        try:
            tree = ast.parse(content)
            for node in ast.walk(tree):
                if isinstance(node, (ast.ClassDef, ast.FunctionDef)):
                    if node.name.lower() in sym_set:
                        return True
        except SyntaxError:
            pass
    return False

This one function eliminated the bug class that caused one out of five Django runs to write to the wrong file entirely.

Testing it against real code

A custom harness: ten Flask tasks

I built a harness that runs Cyclops against a production Flask codebase across ten real-world tasks, scored on whether the correct files were modified, whether the tests pass, and whether the change actually matches the goal.

Task Score Notes Logging middleware 100/100 Clean two-file change User profile (multi-file) 100/100 Four files modified correctly Auth refactor (high risk) 100/100 Most complex task, handled cleanly Email notifications 55/100 Run cancelled mid-stream; valid code was still generating Audit logging 100/100 Four files, all correct Performance optimization 100/100 Client listing optimized Caching with constraints 100/100 Isolated, clean Chatbot with memory 98/100 Missing one signal Security audit scan 44/100 New test type, hit a timeout Self-directed bug fix 96/100 Found and fixed a real race condition

That’s 89/100 across the ten tasks. Both non-passes trace back to infrastructure rather than the agent itself: one run was manually cancelled while still generating valid code, and one hit a timeout on a test type I hadn’t tuned for yet.

The self-directed bug fix is the result I’m most pleased with. The agent got no information about what was wrong beyond “there’s a bug somewhere in the transaction handling.” It read the relevant files on its own, found a race condition in transfer_saga.py, and fixed it.

SWE-bench Lite: five real Django bugs

SWE-bench is the standard benchmark for coding agents: real GitHub issues from real open source projects, and the agent has to produce the fix. I ran five tasks from the Django subset.

Run 1, FILE_UPLOAD_PERMISSIONS default value. Cyclops resolved FileSystemStorage in storage.py exactly, patched the default value, updated the documentation, and passed the storage tests. Two files modified, both correct, no issues.

Run 2, FilePathField callable path. This is the run that exposed the navigator bug described above. Before the fix, Cyclops wrote to api.py and runner.py, both completely wrong. After adding _symbols_present_in_files() validation, it routed correctly to fields/__init__.py.

Run 3, multiline RawSQL in order_by. The fix itself was exactly right: a two-line change replacing newlines with spaces before compiling the column.

# Before
col = self.compile(col)
# After
col = self.compile(col).replace('n', ' ')
# Before
col = self.compile(col)
# After
col = self.compile(col).replace('n', ' ')

The semantic verifier rejected it anyway. It had pulled the literal string \nraw out of a code example inside the issue description and treated it as a required term the patch had to contain. No production fix reproduces test data from an issue description, and the verifier had no way to distinguish a symbol name from an example string.

The fix was to filter anything that looked like example code out of the required-terms set before matching against it:

_EXAMPLE_CHARS = re.compile(r'[()"'\s,=+]')
# Only accept bare identifiers, not example strings
if _EXAMPLE_CHARS.search(term):
    continue  # skip, this looks like example code, not a symbol
_EXAMPLE_CHARS = re.compile(r'[()"'\s,=+]')
# Only accept bare identifiers, not example strings
if _EXAMPLE_CHARS.search(term):
    continue  # skip, this looks like example code, not a symbol

Run 4, MediaOrderConflictWarnings. The same false-positive pattern showed up here: the verifier required the literal string text-editor.js, an example filename from the issue description, to appear in widgets.py. It didn’t, because the real fix was a nine-line deduplication change in Media.__add__. The same term-filtering fix resolved it.

Run 5, sqlmigrate BEGIN/COMMIT. The planner correctly identified the management command that needed changing, but integration closure also pulled in global_settings.py as a required change, which had nothing to do with the fix. A generic setting name in the management command had matched an unrelated registry entry in global_settings.py at 0.72 confidence, just above the 0.70 threshold the integration closure was using. Raising MIN_CONFIDENCE_FOR_TASK to 0.82 fixed it: real integration sites consistently score above 0.85, and spurious matches land in the 0.70 to 0.80 range.

Three real bugs, three small fixes, and all three came from the same root cause: the agent trusted its own intermediate outputs more than it should have.

Hardware reality

I ran the benchmarks on an RTX 4080 with 16GB VRAM, and it’s worth being honest about what that requires. qwen2.5-coder:32b at 16GB runs in CPU and GPU hybrid mode at roughly 3 tokens per second, which is slow enough that a task needing fifteen LLM calls can take twenty to forty minutes. qwen2.5-coder:14b fits entirely in VRAM and runs at 15 to 20 tokens per second, which is the right choice for most people day to day. qwen2.5-coder:7b is fastest but noticeably weaker at multi-step planning. I used the 32b model for the benchmark results above because I wanted the strongest results the hardware could produce; for daily use, 14b is the better trade-off.

The VS Code extension

The Python backend runs a FastAPI server, and the VS Code extension talks to it directly. It has a run panel that streams each step as the agent works, a chat panel that routes between code changes, web search, and repo questions depending on intent, a review panel that shows every diff with a risk score before anything gets written, a history panel that logs and can rerun any past run, and a code graph view built with D3.js.

The chat panel classifies intent with a quick LLM call before responding. “What’s the latest version of FastAPI?” routes to a web search. “How does auth work in this codebase?” routes to a repo explanation. “Add rate limiting to the login endpoint” routes to the full planning pipeline.

What’s next

Two SWE-bench tasks still need reruns with the fixes applied. Beyond that: tree-sitter already parses more than 40 languages, but AST repair and deep validation are Python-only for now, so multi-language support is next. A tuned qwen2.5-coder:7b that still plans correctly would make this workable on 8GB VRAM machines. GitHub Actions integration would let Cyclops run directly on pull requests.

Try it

The full codebase is on GitHub: https://github.com/shan305/cyclops-ai

Setup takes about ten minutes if Ollama is already installed:

git clone https://github.com/shan305/cyclops-ai.git
cd cyclops-ai/Cyclopse
pip install -r requirements.txt
cp .env.example .env
# edit .env, set TARGET_REPO to your project
ollama pull qwen2.5-coder:14b
python start_server.py
git clone https://github.com/shan305/cyclops-ai.git
cd cyclops-ai/Cyclopse
pip install -r requirements.txt
cp .env.example .env
# edit .env, set TARGET_REPO to your project
ollama pull qwen2.5-coder:14b
python start_server.py

Built with LangGraph, FastAPI, ChromaDB, tree-sitter, Ollama, and the VS Code Extension API.

What six months of this actually taught me

The hardest part of an AI coding agent isn’t generation quality. Every decent model can write reasonable Python. The hard part is navigation: knowing which file to touch before touching it, and knowing when the planner is wrong about that. The three bugs above were all the same failure wearing different clothes. The agent trusted its own intermediate outputs when it shouldn’t have.

None of the fixes were glamorous. Raise a confidence threshold. Filter out terms that look like example code. Check that a symbol actually exists in the file the planner says it’s in. Each one took an afternoon. Together, they took the SWE-bench score from one correct run out of five to five out of five.

If you are building local AI agents or running inference on your own hardware, the follow-up piece covers the three failure modes in more detail, including the compiler near-miss that almost replaced 1,500 lines of Django’s SQL compiler with a 38-line stub

I spent many months writing about Rust and turned it into a 23-chapter field guide with a full Redis clone as the capstone. If you are working through this language seriously, it covers everything from ownership to production-level concurrency.

$7 — Zero to Rust: A Systems Programmer’s Field Guide
You can read the free sample here — Free 20-page sample