Reinforcement Learning for Code Generation and Agent-Based Development Tools

cursor · Tech · 2024 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Reinforcement learning for coding agents and agentic developer tools

Cursor's team was reasoning through how to train coding agents with reinforcement learning when code work requires multi-step tool calls, sparse and imperfect rewards, long codebase context, model-specific tool behavior, and real-world user preferences that are harder to measure than test pass/fail.

Constraints:

Architecture

The discussion sketches a training and serving architecture for coding agents rather than a single shipped system. The agent operates over shells, edit tools, language servers, semantic search, PR history, memory/retrieval tools, and long-context mechanisms. RL training needs rewards from tests, ground-truth diffs, user choices, reward models, and possibly process rewards. Inference/training infrastructure must support many rollouts sharing large prompts and KV caches, while product feedback from Cursor users can supply real-world signals for retraining reward models or policies.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  A["Coding agent policy"] --> B["Tool set"]
  B --> C["Codebase context"]
  A --> D["Reward signals"]
  D --> E["Reward model"]
  A --> F["Rollout generator"]
  F --> D
  F --> I["Inference server"]
  A --> G["Long-context substrate"]
  G --> C
  G --> I
  H["User feedback stream"] --> D
  H --> E
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Coding agent policy Model being trained to reason, call tools, edit files, and solve user coding tasks. Tool set, Reward signals, Long-context substrate, User feedback stream
Tool set Shell, edit tools, language-server diagnostics, semantic search, PR search, and possible thinking/memory tools. Coding agent policy, Codebase context
Codebase context Repository files, PR history, previous chats, terminal behavior, linter output, and formatter behavior. Tool set, Long-context substrate
Reward signals Tests, ground-truth diffs, user edit acceptance, pairwise choices, and reward models. Coding agent policy, Rollout generator, Reward model
Rollout generator Samples multiple attempts from the same prompt for sparse rewards, pass@k, or reward-model selection. Coding agent policy, Reward signals, Inference server
Reward model Learns from user choices, ground-truth changes, and possibly process/outcome labels to select or train better outputs. Reward signals, Rollout generator, User feedback stream
User feedback stream Real-world acceptance, edits, pairwise choices, and product usage signals from Cursor users. Reward signals, Reward model
Long-context substrate Context-window, semantic retrieval, PR history, memory tools, attention mechanisms, and KV-cache storage. Coding agent policy, Codebase context, Inference server
Inference server Serves RL rollouts and reuses prompt/KV state across many samples. Rollout generator, Long-context substrate

Data flow

A coding task becomes an agent trajectory: the model emits tokens, calls tools, receives tool responses, edits files, and iterates. Training can score the trajectory through tests, diffs, user acceptance, or reward models, while multiple rollouts from the same prompt create comparative signals. Long codebase context, previous PRs, previous chats, semantic search, and possible memory tools feed the agent's context. In RL infrastructure, shared prompts and KV caches can be reused across rollouts to reduce inference cost.

3 supporting quotes
“It kind of looks like you generate some tokens, call some tools, get a response from those tools, and maybe you do this iteratively several times.”transcript, stated
“the RL the shape of the RL looks a little bit different because now you have to um like go through this multi-step tool calling process”transcript, stated
“The rollouts come back you already have the KVs. So you only have to forward through that the the the rollouts that have came came back.”transcript, stated

Why this architecture

The team argues that coding-agent RL cannot copy math-style RL directly. Coding needs tools, long context, partial decomposition, user/product feedback, and infrastructure that can afford many rollouts. Cursor's product position matters because it is the interface between coding models and real user tasks, so it can observe how model outputs are accepted, edited, or rejected.

3 supporting quotes
“for us RL is particularly interesting because we don't always have a way after receiving the completion from the model of determining whether it actually solved the user's problem”transcript, stated
“we are the interface between the model and the real world, at least to the extent that the model is used for coding.”transcript, stated
“the shorter you can make the loop between a new model uh being trained and it starting to interact with real with the real world, the better your results will be.”transcript, stated

Models used: o3 · Claude models · Cursor Composer · reasoning models · DeepSeek NSA

Scale

Alternatives considered (roads not taken)

Math-style RL with short answers and simple final rewards

Rejected because: Coding trajectories include large action spaces, code-as-reasoning, tool calls, edits, and rewards that may not be observable after completion.

“the action space for coding is much larger”transcript, stated
“while coding sort of like the reasoning is already in the answer, right?”transcript, stated

Use tests as the primary reward

Rejected because: Tests are close to ground truth when coverage is good, but they are sparse, expensive, incomplete, and can reward unrelated changes that pass tests.

“if there's, you know, good tests, then it's something close to a ground truth signal of like does this code work or not”transcript, stated
“the model could start doing things that are completely unrelated to the task and still pass the test”transcript, stated

Terminal-only minimal tooling

Rejected because: The terminal is simple, but richer tools like linter errors, semantic search, and PR history can provide faster or higher-quality signals.

“the reason why the terminal makes sense is it's so easy, right?”transcript, stated
“linder errors give you a ton of signal, but they're just hard to get because you need to run a language server”transcript, stated

Train model-managed long-term memory directly with RL

Rejected because: Writing memory creates delayed credit assignment: the reward depends on later unrelated trajectories that retrieve it.

“retrieving a memory is quite straightforward to teach to a model.”transcript, stated
“storing that memory is way more complicated because the reward is not dependent on the current trajectory is dependent on different trajectories.”transcript, stated

Patterns

fine-tuning-adaptation (model-adaptation)

The discussion centers on adapting coding models with RL, reward models, process/outcome rewards, and real-world feedback rather than relying only on pretraining.

“we've exper we're experimenting with many different kinds of rewards for uh for training the RL models.”transcript, stated
“I'm more bullish on using a reward model and just retraining that more frequently.”transcript, stated

tool-use-orchestration (architecture)

Coding RL is framed around multi-step tool-calling trajectories that include terminals, language servers, semantic search, edit tools, PR history, and memory tools.

“you have to call like multiple tools”transcript, stated
“Another like really interesting tool that we're thinking about is looking at PRs and what the people in the codebase have been doing.”transcript, stated

eval-driven-development (quality)

The team discusses tests, benchmarks, pass@k, user choices, reward-model evaluation, and memory benchmarks as ways to drive model improvement.

“if there's, you know, good tests, then it's something close to a ground truth signal”transcript, stated
“if you sample multiple you could take a majority vote or you could like have a reward model that selects the best one”transcript, stated

agent-memory (context)

Memory tools are discussed as stateful agent tools with separate store and retrieve operations, but with difficult training credit assignment.

“the memory tool is super interesting because there are actually really two tools.”transcript, stated
“I want to store a memory of like this particular interaction and the other one is I retrieve it”transcript, stated

context-engineering (context)

The team weighs long context, semantic retrieval, previous PRs/chats, KV caching, and document-level attention as ways to shape what coding agents can use.

“there's like a really large amount of relevant context to whatever you might want to be doing.”transcript, stated
“cache the keys and values of each of these documents independently and never have to repay the prefill cost”transcript, stated

Tradeoffs

Reward signal design

Chose a mix of tests, diffs, user feedback, and reward models over tests alone.

Rationale: Tests are close to ground truth when good, but incomplete for code quality, user intent, and many real coding tasks.

“not everything can be captured by tests.”transcript, stated
“what you will need to do is like get some real signal from real humans in the environment.”transcript, stated

Tool design

Chose higher-quality coding tools where useful over minimal terminal-only interaction.

Rationale: Terminal access is simple, but language-server errors, semantic search, and PR history can give signal or find relevant context faster.

“the reason why the terminal makes sense is it's so easy, right?”transcript, stated
“semantic search can get you things like over just static code files will get you things that like GP with sufficiently many uh hops could get you um but it'll get you there faster”transcript, stated

Long-context strategy

Chose hybrid long-context plus retrieval/cache mechanisms over only making the raw context window larger.

Rationale: Longer context helps but costs rise; retrieval, KV caching, and document-level attention can reuse context more efficiently.

“the trend has been for the context to get longer and longer and attention is is pretty great at using a long context but you know the the price also gets higher and higher”transcript, stated
“reuse uh cacheed context across many uh prompts”transcript, stated

Online versus offline optimization

Chose short feedback loops and frequently retrained reward models over slow offline-only training disconnected from user behavior.

Rationale: Real user interaction gives the closest signal, but samples are costly, so reward models can be updated frequently from that stream.

“if you can take infinite samples against the real world, you can just optimize that and it'll be great.”transcript, stated
“I'm more bullish on using a reward model and just retraining that more frequently.”transcript, stated

Gotchas (what bit them)

Sparse test rewards make full-PR RL expensive.

Root cause: Few sampled rollouts may pass all tests on large tasks, so the model sees little useful advantage signal.

Resolution: Break tasks into smaller parts when possible, use multiple rollouts, and supplement tests with other reward signals.

“if the task is like so hard the model will only get it right like one in a thousand times if you just sample then the sparse reward becomes like a real issue.”transcript, stated
“you may need to reduce the amount of sparity by breaking it up into component parts”transcript, stated

Tests can reward wrong or unrelated code.

Root cause: Passing tests depends on test coverage and may not capture whether the change actually solves the intended task cleanly.

Resolution: Use tests as one signal while adding ground-truth diffs, user feedback, code-quality preferences, and reward models.

“pass the test doesn't also capture the case of what the model actually did to make it pass the test.”transcript, stated
“not everything can be captured by tests. So like we might need to sort of relax sort of the conditions and maybe think about other ways to get rewards.”transcript, stated

Reward models can improve reported reward while real quality stops improving.

Root cause: Optimizing against a learned reward can saturate or diverge from the true reward humans care about.

Resolution: Ground reward models in real user decisions and retrain them frequently rather than trusting a static proxy.

“The reward keeps going up, but the model actually doesn't improve.”transcript, stated
“the reward will go up forever, but like the real reward you care about will go up down”transcript, stated

Memory storage is harder to train than memory retrieval.

Root cause: The benefit of storing a memory appears in later unrelated trajectories, causing a delayed credit-assignment problem.

Resolution: Use benchmarks and heuristic/prompt search for memory policies rather than immediate end-to-end backpropagation into memory storage.

“to get good signal from storing this memory, I have to do many rollouts in a bunch of random other trajectories”transcript, stated
“because of the credit assignment problems Federico mentioned it is really hard to like actually back propagate into the memory storage mechanism.”transcript, stated

Evaluation

The discussion proposes and critiques possible evaluation signals rather than reporting one completed experiment: unit tests, pass@k rollouts, ground-truth diffs, user acceptance/edit traces, pairwise choices, reward models, process rewards, and memory-policy benchmarks.

Metrics: pass@k versus pass@1 · test pass/fail · ground-truth diff similarity · user acceptance or edited-change similarity · pairwise rollout choices · memory benchmark performance over about 500 examples · rollout throughput and KV reuse in RL inference

3 supporting quotes
“pass k which is like the the uh proportion of times the model got it correct out of k tries is so much higher than the pass at one”transcript, stated
“maybe there's multiple ways to make that same change. Um so it's not a perfect you know signal but like you could potentially use this as information”transcript, stated
“Did the user like the changes the agent made or maybe some proxy for that based on like whether they accepted the edit”transcript, stated

Outcomes

This is a technical discussion, not a published production launch. Quantitative references are illustrative infrastructure/evaluation magnitudes rather than outcome claims.

3 supporting quotes
“for us RL is particularly interesting because we don't always have a way after receiving the completion from the model of determining whether it actually solved the user's problem”transcript, stated
“we are the interface between the model and the real world”transcript, stated
“We're looking at this for tab because we just get so much data per unit of time um because we get feedback whenever someone is shown a tab suggestion”transcript, stated