GitLab Duo · Developer Reference · Static Analysis


Improving Complexity Analysis with Radon

How to replace LLM-approximated scoring with precise, tool-based cyclomatic complexity measurement in your merge requests



When GitLab Duo runs static complexity analysis on your merge request, it measures cyclomatic complexity for every function you touched or added. This helps catch overly complex code before it gets merged.

There are two ways the analysis can run: tool-based, using radon directly on your source files for precise results, or LLM-approximated, where the AI reads your code and counts decision points manually, producing only an estimate.

If you saw an info box in the MR comment about improving accuracy, the sections below explain how to enable radon in your project.


If a Merge Request Was Linked

The analysis agent detected that your project can support radon but doesn't have it installed yet. It created a merge request that adds (or updates) your .gitlab/duo/agent-config.yml file to include pip install radon in the setup step.

Action — Review and merge that MR. The next time the complexity analysis runs, it will use radon for precise scores instead of LLM approximation.

The MR adds a configuration like this:

version: 1
base_image: python:3.12-slim
setup:
  - pip install radon

If your project already had an agent-config.yml, the MR modifies it to add radon to the existing setup steps.


If No Merge Request Was Linked

The analysis agent found an existing .gitlab/duo/agent-config.yml in your repository but could not safely modify it. This typically happens when:

Action — Add radon to your config manually. The exact steps depend on your base image.

Python Base Image

If your base_image is any Python variant (python:*, debian:*, ubuntu:*), add to your setup:

setup:
  - pip install radon    # Add this line
  - # ... your existing setup steps

Node.js Base Image

If your base image is Node-based, you'll need Python available:

setup:
  - apt-get update && apt-get install -y python3 python3-pip
  - pip3 install radon
  - # ... your existing setup steps

Other Base Images

For Alpine, Ruby, Go, or other images, ensure Python 3 and pip are available, then pip install radon.


The Configuration File

The file .gitlab/duo/agent-config.yml configures the execution environment for GitLab Duo agent workflows. It specifies:

When this file exists and includes radon, the complexity analysis agent can call radon cc directly on your source files for exact cyclomatic complexity scores. Without it, the agent falls back to LLM-based estimation, which is less precise.


What Is Cyclomatic Complexity?

Cyclomatic complexity (CC) measures the number of independent paths through a function. It counts decision points like if, for, while, case, catch, &&, ||, and ternary operators.

CC ScoreRankRisk Level
1–5ASimple, low risk
6–10BModerate, well-structured
11–15CMore complex, consider refactoring
16–20DComplex, should refactor
21–25EVery complex, high risk
26+FUntestable, must refactor

Functions with CC above 10 are harder to test and more likely to contain bugs. The analysis highlights these so you can address them during code review.