Skip to content

Instantly share code, notes, and snippets.

View nerdimite's full-sized avatar

Bhavesh Laddagiri nerdimite

View GitHub Profile

Agentic System Prompt Design by Cursor

A deep-dive into how Cursor constructs the system prompt for its AI coding agent — using a real, live system prompt as the working example. Written for developers who want to understand the machinery so they can use it better.


Why This Matters

When you open a chat in Cursor and type a message, you're not just talking to a raw language model. Cursor assembles a carefully structured system prompt before your message ever reaches the model. That prompt is the difference between a generic chatbot and a context-aware coding agent that knows your repo, your rules, your tools, and your current editor state.

transcript1 = [
{"agent": "Thank you for calling ABC delivery. How may I assist you today?"},
{
"customer": "Hello, I'm calling about my delivery. It was supposed to arrive yesterday but it's still not here."
},
{"agent": "I'm sorry to hear that. Can I have your order number please?"},
{"customer": "Sure, it's 123456."},
{
"agent": "Thank you. Let me check on the status of your delivery. Please hold for a moment."
},
@nerdimite
nerdimite / loc_counter.py
Created June 29, 2021 15:00
Calculates the number of lines of code in a directory recursively
'''
Function: Calculates the number of lines of code in a directory recursively
Author: Bhavesh Laddagiri
'''
import os
import argparse
# append more extensions as per your project
code_extensions = ['py', 'js', 'css', 'html', 'graphql', 'sh', 'json']
def optimize_GA(pop_size, max_generations, crossover_prob, mutate_prob):
'''Returns the final solution by optimizing using genetic algorithm'''
# Initialize the Population
population = initialize_pop(pop_size)
global_best = {}
# Start Evolution
for g in range(max_generations):
def mutation(individual):
'''Mutates the DNA of a child/individual by swapping the values at two positions'''
# Selecting the index values to swap
pos_1 = rnd.randint(0, len(individual)-1)
pos_2 = rnd.randint(0, len(individual)-1)
# Init the mutant
mutant = individual.copy()
# Swap
mutant[pos_1] = individual[pos_2]
mutant[pos_2] = individual[pos_1]
def crossover(parent1, parent2, prnt=False):
'''Returns the child after crossover between the parents'''
# Select cut points
c1 = rnd.randint(0, len(parent1)-2)
c2 = rnd.randint(c1+1, len(parent2)-1)
# Create an Empty Child DNA
child = ["X"] * len(parent1)
# Set the values between the cut points from parent1 in the child DNA
def selection(population):
'''Selects an individual randomly based on its fitness value as weights'''
# Calculate the fitness values of every individual in the population
fitness_values = list(map(fitness, population))
# Calculate the relative inverse fitness as our goal is to minimize the total distance
inverse_fitness = [max(fitness_values) - x for x in fitness_values]
# Assign weights to each individual based on the inverse fitness
weights = [x / sum(inverse_fitness) for x in inverse_fitness]
# Select a individual as a parent with weighted randomness
selected_individual = rnd.choices(population, weights)[0]
def fitness(solution):
'''Returns the total travel distance for a given solution'''
total_distance = 0
# Calculate the acyclic distance from first city to last city
for i in range(len(solution)-1):
p1 = city_map[solution[i]]
p2 = city_map[solution[i+1]]
total_distance += euclidean(p1, p2)
cities = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
def initialize_pop(pop_size=10):
population = []
for i in range(pop_size):
individual = cities.copy()
rnd.shuffle(individual) # shuffle the cities
population.append(individual)
return population