IP Library Granted Patent US 12693834
Granted Patent B1
US 12693834 · App. 19/413,868 · Granted Jul 28, 2026

Context-aware code generation using syntax tree modification and level-of-detail processing

Inventors: Jens Faenger (Lakewood Ranch, FL); Thorsten Kuehnemund (Scotts Valley, CA); Redi Kurti (Santa Clara, CA); Bradley Michael Eckert (San Francisco, CA); Benjamin Taylor Collins (San Francisco, CA)
Assignee: With Woz, Inc.
G06F8/30
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12693834
App. No.
19/413,868
Granted
Jul 28, 2026
Kind
B1
Abstract

A method comprises generating a map of relationships between functions, statements and data structures in identified code by traversing a syntax tree for the identified code, the syntax tree for the identified code includes a hierarchy of nodes, each node comprising at least one identifying name; modifying nodes of the syntax tree of the identified node by truncating code unrelated to the code generation task to generate a modified syntax tree for the identified code; adding to the modified syntax tree, for each modified node, a new node indicating that the modified node is truncated, and traversing the at least one modified syntax tree to generate a second code that is shorter than at least one identified code. The method also includes providing the generated second code, the at least one modified syntax tree, and the code generation task as input to a language model to generate output code.

Claims (56)

1 . A method comprising:

receiving a code generation task;

identifying at least one code from a plurality of codes relevant to the code generation task;

generating at least one snippet for each of the at least one identified code, wherein each of the at least one snippet is shorter than the at least one corresponding identified code that each at least one snippet is generated for;

providing the at least one snippet of the at least one identified code and the code generation task as input context to a language model to generate output code;

validating the output code on a computing device; and

responsive to an error during the validating, rebuilding the input context by generating new snippets from the at least one identified code and from additional code of the plurality of codes identified based on the error, and providing the rebuilt input context to the language model to generate new output code.

2 . The method of claim 1 , further comprising validating the output code and executing the validated output code.

3 . The method of claim 1 , wherein the plurality of codes comprises previously written code from a codebase.

4 . The method of claim 1 , wherein generating at least one snippet comprises replacing one or more functions with a comment that summarizes the one or more functions that were replaced.

5 . The method of claim 1 , wherein identifying at least one code comprises using Large Language Model-assisted classification to determine which source code files are relevant to the code generation task.

6 . The method of claim 1 , further comprising:

rebuilding the input context by purging previous failed code generation attempts; and

maintaining only current relevant code versions to prevent degradation of language model output quality.

7 . The method of claim 1 , wherein generating the at least one snippet comprises:

creating an abridged version of the at least one identified code by truncating the at least one identified code; and

inserting explanatory text indicating where code has been truncated.

8 . The method of claim 1 , wherein identifying at least one code relevant to the code generation task comprises:

performing a keyword-based search on the plurality of codes; and

using a re-ranking language model to select at least one code based on the keyword-based search.

9 . The method of claim 8 , wherein identifying at least one code further comprises performing a semantic search using vector embeddings on the plurality of codes.

10 . A non-transitory computer readable medium having stored thereon instructions to configure at least one processor to:

receive a code generation task;

identify at least one code from a plurality of codes relevant to the code generation task;

generate at least one snippet for each of the at least one identified code, wherein each of the at least one snippet is shorter than the at least one corresponding identified code that each at least one snippet is generated for;

provide the at least one snippet of the at least one identified code and the code generation task as input context to a language model to generate output code;

validate the output code on a computing device; and

responsive to an error during the validating, rebuild the input context by generating new snippets from the at least one identified code and from additional code of the plurality of codes identified based on the error, and provide the rebuilt input context to the language model to generate new output code.

11 . A computing apparatus comprising:

at least one processor; and

a memory storing instructions that, when executed by the at least one processor, configure the apparatus to:

receive a code generation task;

identify at least one code from a plurality of codes relevant to the code generation task;

generate at least one snippet for each of the at least one identified code, wherein each of the at least one snippet is shorter than the at least one corresponding identified code that each at least one snippet is generated for;

provide the at least one snippet of the at least one identified code and the code generation task as input context to a language model to generate output code;

validate the output code on a computing device; and

responsive to an error during the validating, rebuild the input context by generating new snippets from the at least one identified code and from additional code of the plurality of codes identified based on the error, and provide the rebuilt input context to the language model to generate new output code.

12 . The computing apparatus of claim 11 , wherein the instructions further configure the apparatus to validate the output code and executing the validated output code.

13 . The computing apparatus of claim 11 , wherein the plurality of codes comprises previously written code from a codebase.

14 . The computing apparatus of claim 11 , wherein generating at least one snippet comprises replacing one or more source code statements or instructions with a comment that summarizes the one or more source code statements or instructions that were replaced.

15 . The computing apparatus of claim 11 , wherein identifying at least one code comprises using Large Language Model-assisted classification to determine source code files are relevant to the code generation task.

16 . The computing apparatus of claim 11 , wherein the instructions further configure the apparatus to:

rebuild the input context by purging previous failed code generation attempts; and

maintain only current relevant code versions to prevent degradation of language model output quality.

17 . The computing apparatus of claim 11 , wherein generating the at least one snippet comprises:

creating an abridged version of the identified code by truncating the at least one identified code; and

inserting explanatory text indicating where code has been truncated.

18 . The computing apparatus of claim 11 , wherein identifying at least one code relevant to the code generation task comprises:

performing a keyword-based search on the plurality of codes; and

using a re-ranking language model to select at least on code based on the keyword-based search.

19 . The computing apparatus of claim 18 , wherein identifying at least one code further comprises performing a semantic search using vector embeddings on the plurality of codes.

20 . The computing apparatus of claim 11 , wherein generating at least one snippet comprises dynamically adjusting an amount of detail based on at least one of:

available context window size of the language model;

desired processing speed;

desired output quality; or

processing cost.