- Updated: July 17, 2026
- 7 min read
ProjAgent: Procedural Similarity Retrieval for Repository-Level Code Generation
Direct Answer
ProjAgent introduces a repository‑level code generation system that explicitly retrieves functions based on procedural similarity—the way code behaves step‑by‑step—rather than relying solely on lexical or semantic cues. By weaving procedural retrieval into a multi‑agent workflow and closing the loop with static‑analysis feedback, ProjAgent lifts the success rate of generating correct, compile‑ready functions across large codebases.
Background: Why This Problem Is Hard
Modern software projects span dozens of files, dozens of libraries, and a myriad of project‑specific conventions. When an AI model is asked to implement a new function, it must:
- Understand the surrounding API surface.
- Respect naming conventions, error‑handling patterns, and logging styles.
- Navigate cross‑file dependencies that are often implicit.
Existing retrieval‑augmented generation (RAG) pipelines typically surface candidate snippets using:
- Lexical similarity (shared identifiers or comments).
- Structural similarity (AST patterns).
- Semantic similarity (embedding proximity).
These signals excel at finding code that looks alike, but they miss a crucial dimension: two functions can solve the same algorithmic problem with completely different identifiers and even different domain vocabularies. For example, a “parse CSV” routine in a data‑processing repo and a “read TSV” routine in a bioinformatics repo share the same procedural steps—tokenization, type conversion, error handling—yet traditional similarity metrics rank them low.
Because repository‑level generation must synthesize code that fits the host project’s style, overlooking procedural similarity leads to:
- Higher rates of compilation errors.
- Generated code that feels “out of place” to human reviewers.
- Increased post‑generation debugging effort.
Addressing this gap is essential for AI‑assisted development tools that aim to be truly “plug‑and‑play” within existing codebases.
What the Researchers Propose
ProjAgent reframes retrieval as a two‑tiered process:
- Procedural similarity retrieval: The target function is broken down into a sequence of intermediate reasoning steps (e.g., “open file”, “iterate rows”, “validate schema”). For each step, an autonomous “retrieval agent” searches the repository for functions that exhibit the same procedural behavior, regardless of naming or domain.
- Semantic enrichment: The procedural candidates are merged with conventional semantic retrieval results, producing a richer context that combines “how” the code works with “what” it does.
Three core agents orchestrate the workflow:
- Decomposer Agent – parses the user‑provided specification and emits a stepwise plan.
- Procedural Retriever Agent – queries a specialized index built on execution‑trace signatures to locate procedurally similar snippets.
- Synthesizer Agent – feeds the combined context to a large language model (LLM) that generates the target function.
After synthesis, a static‑analysis feedback loop compiles the output, captures compiler errors, and prompts the Synthesizer Agent to iteratively repair the code until it passes a conservative set of checks.
How It Works in Practice
The end‑to‑end pipeline can be visualized as a series of coordinated stages:

1. Input Specification
The developer supplies a natural‑language description of the desired function, optionally accompanied by a signature or test harness.
2. Decomposition
The Decomposer Agent uses a fine‑tuned LLM to translate the description into a linear plan, e.g.:
1. Open the configuration file. 2. Parse each line into key/value pairs. 3. Validate required keys. 4. Return a dictionary of settings.
3. Procedural Retrieval
For each step, the Procedural Retriever Agent queries a procedure‑signature index. This index stores lightweight execution traces (e.g., sequence of API calls, control‑flow motifs) extracted from every function in the repository. Retrieval is performed via a nearest‑neighbor search on these signatures, yielding functions that share the same operational pattern.
4. Semantic Fusion
Simultaneously, a conventional semantic retriever pulls embeddings of functions whose textual description aligns with the overall task. The two result sets are merged, de‑duplicated, and ranked by a learned relevance model that balances procedural and semantic signals.
5. Synthesis
The Synthesizer Agent receives a prompt that includes:
- The original specification.
- The stepwise plan.
- Top‑k procedural snippets (with inline comments stripped).
- Top‑k semantic snippets.
Guided by this enriched context, the LLM generates candidate code that is already aligned with the repository’s idioms.
6. Static‑Analysis Feedback Loop
The generated file is compiled with the project’s build system. Any compiler or static‑analysis warnings are fed back to the Synthesizer Agent as corrective instructions (“add missing import”, “fix type mismatch”). The agent re‑generates only the problematic region, preserving the rest of the code. This loop repeats until the code passes a predefined “conservative” pass threshold (e.g., no type errors, no undefined symbols).
7. Final Delivery
When the loop terminates, the system returns a ready‑to‑commit function, optionally accompanied by a diff and a short rationale explaining the procedural choices.
What sets ProjAgent apart is the explicit modeling of procedural behavior as a first‑class retrieval signal, and the tight coupling of retrieval with an iterative, compiler‑aware repair cycle.
Evaluation & Results
Researchers benchmarked ProjAgent on REPOCOD, a newly curated dataset that contains real‑world function‑level tasks drawn from open‑source repositories of varying size and language diversity. The evaluation focused on the Pass@1 metric—whether the first generated snippet compiles and passes hidden unit tests.
Experimental Setup
- Baseline models: standard semantic‑retrieval‑augmented generation (SRAG) and a pure LLM without retrieval.
- Procedural index built from the same repository corpus used by the baselines.
- Static‑analysis loop limited to three repair iterations to simulate realistic developer patience.
Key Findings
- ProjAgent achieved 41.14% Pass@1, a 12‑point lift over the best semantic‑only baseline.
- When procedural retrieval was disabled, performance dropped to 30.2%, confirming the additive value of procedural signals.
- The static‑analysis loop reduced compilation failures by 68% compared to a single‑shot generation.
- Human evaluators rated ProjAgent’s output as more “in‑style” with the host repository than baseline outputs (average rating 4.3/5 vs. 3.6/5).
These results demonstrate that procedural similarity is not a niche curiosity but a robust lever for improving real‑world code generation across heterogeneous projects.
Why This Matters for AI Systems and Agents
For AI‑driven development platforms, the ability to generate code that compiles on the first try translates directly into productivity gains and lower friction for adoption. ProjAgent’s architecture offers several practical takeaways:
- Agent‑centric design: By delegating decomposition, retrieval, and synthesis to specialized agents, the system mirrors the modular pipelines used in enterprise AI orchestration tools.
- Procedural indexing as a reusable service: The procedure‑signature index can be exposed as a micro‑service, enabling other agents (e.g., test‑case generators, refactoring bots) to query for behaviorally similar code.
- Feedback‑driven synthesis: The static‑analysis loop exemplifies a closed‑feedback paradigm that can be generalized to security scanners, performance profilers, or style linters.
- Integration pathways: Platforms that already support semantic retrieval (e.g., Chroma DB integration) can augment their pipelines with procedural signatures without rebuilding the entire retrieval stack.
From a business perspective, teams building AI assistants for code review, automated onboarding, or low‑code platforms can leverage ProjAgent’s principles to reduce the “hand‑off” cost between AI output and human acceptance. The approach also aligns with emerging standards for AI‑augmented software development, where traceability and reproducibility are becoming compliance requirements.
What Comes Next
While ProjAgent marks a significant step forward, several open challenges remain:
- Cross‑language procedural retrieval: Current signatures are language‑specific; extending them to support polyglot repositories would broaden applicability.
- Dynamic behavior capture: Execution traces derived from static analysis miss runtime nuances (e.g., lazy loading, reflection). Incorporating lightweight instrumentation could enrich the procedural index.
- Scalability of the feedback loop: For massive monorepos, compiling after each iteration may become a bottleneck. Incremental compilation or type‑checking shortcuts are promising avenues.
- User‑controlled retrieval bias: Allowing developers to weight procedural vs. semantic signals on the fly could tailor the system to project‑specific priorities.
Future research may also explore how procedural similarity interacts with other retrieval dimensions such as security patterns or performance characteristics. In practice, teams can start experimenting by plugging ProjAgent’s components into existing AI development stacks. For example, the Workflow automation studio can orchestrate the agentic steps, while the Openclaw (Clawdbot, MoltBot) suite could serve as the procedural retriever backend.
As AI agents become more autonomous, the ability to reason about “how” code works—rather than just “what” it says—will be a decisive factor in building trustworthy, production‑grade assistants.
For a deeper dive into the original research, see the ProjAgent paper on arXiv.
Andrii Bidochko
CTO UBOS
Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.