There are two scenarios:
- The PR is small enough to fit in a single prompt (including system and user prompt)
- The PR is too large to fit in a single prompt (including system and user prompt)
For both scenarios, we first use the following strategy
We prioritize the languages of the repo based on the following criteria:
- Exclude binary files and non code files (e.g. images, pdfs, etc)
- Given the main languages used in the repo
- We sort the PR files by the most common languages in the repo (in descending order):
[[file.py, file2.py],[file3.js, file4.jsx],[readme.md]]
In this case, we can fit the entire PR in a single prompt:
- Exclude binary files and non code files (e.g. images, pdfs, etc)
- We Expand the surrounding context of each patch to 6 lines above and below the patch
Pull Requests can be very long and contain a lot of information with varying degree of relevance to the pr-agent. We want to be able to pack as much information as possible in a single LMM prompt, while keeping the information relevant to the pr-agent.
We prioritize additions over deletions:
- Combine all deleted files into a single list (
deleted files
) - File patches are a list of hunks, remove all hunks of type deletion-only from the hunks in the file patch
We use tiktoken to tokenize the patches after the modifications described above, and we use the following strategy to fit the patches into the prompt:
- Within each language we sort the files by the number of tokens in the file (in descending order):
[[file2.py, file.py],[file4.jsx, file3.js],[readme.md]]
- Iterate through the patches in the order described above
- Add the patches to the prompt until the prompt reaches a certain buffer from the max token length
- If there are still patches left, add the remaining patches as a list called
other modified files
to the prompt until the prompt reaches the max token length (hard stop), skip the rest of the patches. - If we haven't reached the max token length, add the
deleted files
to the prompt until the prompt reaches the max token length (hard stop), skip the rest of the patches.