{"id":253719,"date":"2025-07-31T05:00:42","date_gmt":"2025-07-31T12:00:42","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=253719"},"modified":"2025-07-28T13:58:02","modified_gmt":"2025-07-28T20:58:02","slug":"smarter-ai-edits-in-visual-studio-copilot","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/smarter-ai-edits-in-visual-studio-copilot\/","title":{"rendered":"Smarter AI Edits in Visual Studio Copilot"},"content":{"rendered":"<p><span data-contrast=\"auto\">When we first set out to get smarter AI edits in Visual Studio Copilot, we knew we were tackling a deeply complex problem. It wasn\u2019t just about generating great suggestions\u2014it was about figuring out how to seamlessly apply those suggestions to your code. While the idea seemed simple at first glance, the reality was anything but.\u00a0 <\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><div style=\"width: 992px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-253719-1\" width=\"992\" height=\"616\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2025\/07\/SideBySideNewMapper.mp4?_=1\" \/><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2025\/07\/SideBySideNewMapper.mp4\">https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2025\/07\/SideBySideNewMapper.mp4<\/a><\/video><\/div><\/p>\n<h2><b><span data-contrast=\"auto\">The Complexity of Implementing AI-Generated Edits<\/span><\/b><span data-ccp-props=\"{}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"auto\">Let\u2019s\u00a0rewind to our early attempts. Copilot might give you a fantastic suggestion\u2014a new method, a helpful refactor, or\u00a0maybe even\u00a0a corrected logic block. But the\u00a0real challenge\u00a0began when we tried to insert those changes into the existing file without breaking anything. Where does the edit go? What happens if the file has been updated since the suggestion was generated? What if the model\u2019s output inadvertently introduces conflicts, overlaps existing code, or even forgets a required bracket? These questions made the process tricky, and the resulting red squiggles made it difficult to trust AI suggestions.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">In the early days, we approached this problem in the most straightforward way possible: brute force. We used heuristics and rule-based techniques like string matching and pattern recognition to\u00a0identify\u00a0where edits might belong. It worked&#8230; kind of. The results were often inconsistent, especially for complex edits spanning multiple lines. And as Copilot\u2019s capabilities expanded to support more languages and scenarios,\u00a0maintaining\u00a0these rules became a moving target\u2014always shifting, always growing harder to manage. Success rates hovered around 50%, which was far from ideal. In hindsight, it became increasingly clear that we\u00a0couldn\u2019t\u00a0outpace the ever-evolving models with static rules.\u00a0\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h2><b><span data-contrast=\"auto\">Better Models Meet Smarter Techniques<\/span><\/b><span data-ccp-props=\"{}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"auto\">As AI technology advanced, we saw an opportunity to revisit this problem with a fresh perspective. Two major developments in AI made it possible to rethink how we could get smarter edits in Visual Studio Copilot: modern models with larger context windows and a groundbreaking technique called speculative decoding.\u00a0 <\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">Speculative decoding<\/span><\/b><span data-contrast=\"auto\">\u00a0became a game changer for speeding up AI-assisted edits. It works by pairing a fast model with a more sophisticated one. The fast model generates token predictions for the edit ahead of time, while the smarter model steps in only when needed to refine or verify those predictions. This collaboration\u00a0improved average token generation speed\u00a0by 2-3x\u00a0and\u00a0made\u00a0it\u00a0feasible\u00a0to implement the generated edits using the model, which\u00a0significantly enhanced accuracy when integrating changes into your files.\u00a0\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">By using speculative decoding,\u00a0we adopted\u00a0the\u00a0model-based approach to applying edits that\u00a0was able to fill in the gaps that the\u00a0previous\u00a0approach could not reach.\u00a0Instead of relying on rule sets, we employed an\u00a0AI model to simulate an \u201cideal\u201d version of your file with the chosen suggestions seamlessly integrated. A smart diff algorithm then compares this ideal version with your actual file to pinpoint and precisely map the edits. This allowed the entire process to handle edge cases\u2014like overlapping code or missing syntax\u2014more intelligently than ever before.\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h2><b><span data-contrast=\"auto\">Balancing Accuracy\u00a0and Speed<\/span><\/b><span data-ccp-props=\"{}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"auto\">While speculative decoding dramatically improved performance, applying AI edits still came with a natural trade-off: using models introduced latency. Previously, all string computation was done locally, meaning edits appeared\u00a0almost instantly. Now, every edit\u00a0involved\u00a0network calls and token generation\u2014a process that unfolds incrementally as a token stream, rather than as a single, instant response.\u00a0\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">To make this experience feel meaningful for users, we implemented a streaming animation in the editor. As edits are detected on the token stream, users see their document updating line by line in real time. This animation serves two purposes:\u00a0showcasing\u00a0progress and providing visibility into exactly how the changes are being applied. Although this approach trades the speed we had before for greater accuracy, feedback has shown that users value precision over raw speed\u2014especially when it comes to\u00a0maintaining\u00a0code quality and reducing disruption.\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h2><b><span data-contrast=\"auto\">Looking Ahead<\/span><\/b><\/h2>\n<p><span data-contrast=\"auto\">This work laid the foundation for\u202fAgent Mode\u202fin Visual Studio Copilot\u2014a feature that enables the AI to not only suggest improvements but actively\u00a0assist\u00a0in executing them. For Agent Mode to function effectively, the edits needed to be precise, seamless, and reliable enough for the agent to build, debug, and test the code. Speculative decoding has already made significant strides in balancing speed and accuracy, but\u00a0we&#8217;re\u00a0not stopping there.<\/span><\/p>\n<p><span data-contrast=\"auto\">A faster implementation of our speculative decoding technique is on the horizon. This updated version will\u00a0leverage\u00a0advancements in token generation and model pairing to further reduce latency while\u00a0maintaining\u00a0accuracy users have come to expect. Early tests show promise of a 2-4x speed boost compared to the original rollout, moving closer to the ideal experience where precision meets near-instant response times.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we first set out to get smarter AI edits in Visual Studio Copilot, we knew we were tackling a deeply complex problem. It wasn\u2019t just about generating great suggestions\u2014it was about figuring out how to seamlessly apply those suggestions to your code. While the idea seemed simple at first glance, the reality was anything [&hellip;]<\/p>\n","protected":false},"author":98326,"featured_media":252213,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[6888,6967,155],"tags":[6973,6969],"class_list":["post-253719","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-copilot","category-github-copilot","category-visual-studio","tag-ai-agents","tag-github-copilot-chat"],"acf":[],"blog_post_summary":"<p>When we first set out to get smarter AI edits in Visual Studio Copilot, we knew we were tackling a deeply complex problem. It wasn\u2019t just about generating great suggestions\u2014it was about figuring out how to seamlessly apply those suggestions to your code. While the idea seemed simple at first glance, the reality was anything [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/253719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/98326"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=253719"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/253719\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/252213"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=253719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=253719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=253719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}