As I planned in my previous post , I recently built the deterministic prompt generator for cxgrd.
How I built it
Just two steps:
1) Get the blast radius results from the subgraph
export interface PromptSubgraph {
changeDescription: string;
seedFiles: string[];
affectedFiles: Array<Pick<ImpactedFile,
'path' | 'severity' | 'reason' | 'distance' | 'impactType' | 'changeRequired' | 'suggestedFix'
>>;
dependencies: Array<{ from: string; to: string; type: string }>;
symbols: Record<string, string[]>;
architectureLayers: Record<string, string[]>;
riskLevel: string;
recommendations: string[];
}
2) Embed these results in the prompt
for (const file of subgraph.affectedFiles) {
if (subgraph.seedFiles.includes(file.path)) continue;
const distance = file.distance === 1 ? 'direct dependent' : `transitive dependent, depth ${file.distance}`;
const required = file.changeRequired ? 'review and update if the change requires it' : 'review for compatibility';
const layers = layerByFile.get(file.path);
const layerNote = layers?.length ? `; architecture layer: ${layers.join(', ')}` : '';
lines.push(
`- \`${file.path}\` — ${file.severity} risk, ${distance}; ${file.reason}; ${required}${layerNote}.`,
);
if (file.suggestedFix) lines.push(` Suggested action: ${file.suggestedFix}`);
}
[truncated]
It can't interpret the intent as clearly as an AI model, but it can definitely guide your agent's focus on important modules, so it won't break your project.
And this custom generator will also cut API costs for me.
Try cxgrd here. I would love to hear what your think about this, any form of feedback/suggestion is welcomed.
Github : https://github.com/cxgrd/cli
Top comments (4)
Nice, I like that it's deterministic. Same change in, same prompt out, so when the agent does something weird you can actually tell whether it was the prompt or the model.
One suggestion: on a bigger repo the affected files list could get long fast, especially with transitive dependents. Sorting by severity and distance and capping it (say the top 15, then "plus N lower-risk files") would probably keep the agent focused and save even more on tokens. Direct dependents with changeRequired feel like the only ones it really needs every time.
Have you tried it on a change that touches a shared utils file? Curious how big the prompt gets there.
Thanks for your suggestion Matthew. I will try out sorting the files by severity.
If the request identifies a shared utility file, the generated prompt treats it as a direct change target and lists its detected dependents as files to review. For example, it might include:
The prompt also includes relevant dependency edges, symbols, analyzer recommendations, and steps to test affected modules.
Nice, that output looks clean. Listing the utils file as the direct target and then its dependents by risk is exactly what I'd want to see. Looking forward to the version with sorting.
Deterministic prompt generation là hướng đi rất đúng khi muốn reproducibility cho code review automation. Với cxgrd, việc tách biệt prompt logic ra generator riêng giúp:
Một điểm cần lưu ý: deterministic không có nghĩa là rigid. Cân nhắc thêm prompt parameterization (ví dụ: severity threshold, language-specific rules, team conventions) để generator adapt được cho nhiều repo/context khác nhau mà vẫn giữ reproducibility.
Có thử benchmark token usage so với approach dynamic prompt chưa? Việc fixed template có thể tốn token hơn ở chỗ include toàn bộ context, nhưng trade-off lại là predictable cost và easier caching PS: the tool I meant is on labagent .tech