Feedback

Chat Icon

Building with GitHub Copilot

From Autocomplete to Autonomous Agents

Behind the Scenes of Chatting with Copilot
42%

The 10 Steps of a GitHub Copilot Request Flow

Based on information and insights from some blog posts from the official blog, the reverse-engineering work by Parth Thakkar, and my own analysis, the following steps outline the request flow from the moment you type in your editor to the moment a suggestion appears. These steps focus on the overall architecture and leave out some details for simplicity. Certain mechanisms have likely evolved since the original blog posts were published, but the broad flow and architecture remain largely the same.

The goal here is not to provide an exact, fully up-to-date flow, but to give a general picture of how such a system might work. Here is a high-level schematic of the flow:

What happens under the hood when you type in your editor and Copilot generates a suggestion? The following breakdown explains the 10 main steps involved in the process.

1. Inputs Captured Locally

The extension starts by reading the cursor position, file path, language, and current editor text. It treats your code as the "prompt seed".

2. Build The Base Prompt From The Active File

It takes the text before your cursor (the prefix) and the text after it (the suffix). If there's code on both sides, Copilot switches to a mode called Fill-In-the-Middle (FIM), where the AI learns to generate code that fits neatly between the two. This gives the model a clearer picture of what belongs in the gap.

For example, if your code looks like this:

def get_user(id):
    # Your cursor is here
    return user

def save_user(user):
    # Some code here

The prefix is everything before the cursor:

def get_user(id):

The suffix is everything after the cursor:

    return user
def save_user(user):
    # Some code here

Because the suffix includes return user, the model, after receiving the final prompt (which is currently being built), knows it needs to generate the code in the middle (e.g., user = db.find(id)), so the snippet connects smoothly to both sides. Code is not generated at this stage; we're just saying in the prompt, "Hey, this is the context around where I want help, and here is exactly where code should go."

3. Collect Context From Other Files (Same Workspace)

Copilot identifies other files in your workspace that might be relevant to your current coding task (e.g., recently edited files, files in the same directory, files with similar naming patterns, etc.).

4. Rank And Select Relevant Snippets

Copilot compares chunks of code from these other files against your active file to decide which ones are most relevant. In this step, it may use some techniques like Jaccard similarity, embeddings, and vector similarity to find the best matches.

To reduce noise and prevent duplicates, the system only picks the best-matching window from each file.

Here's a simple example with two files:

File 1: utils.py

def calculate_sum(a, b):
    return a + b

Building with GitHub Copilot

From Autocomplete to Autonomous Agents

Enroll now to unlock all content and receive all future updates for free.