Skip to content

Commit a532f81

Browse files
committed
feat(pr-review): implement memory storage and retrieval in PR review workflows
Enhance PR review workflows by adding memory storage and retrieval capabilities. This includes storing findings and initial concerns during different phases and utilizing them in the synthesis phase to generate detailed reports. This change enables more comprehensive and iterative analysis across multiple review iterations.
1 parent ae30710 commit a532f81

6 files changed

Lines changed: 321 additions & 6 deletions

File tree

src/workflows_mcp/templates/agents/pr-review/agent-investigation-loop/investigation-sub-workflow/main.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,31 @@ blocks:
338338
description: "Confidence level in this analysis"
339339
required: [summary, issues, severity, suggestions, needs_further_investigation, confidence]
340340

341+
# ============================================================================
342+
# MEMORY: Store file findings for accumulation across iterations
343+
# ============================================================================
344+
- id: store_file_findings
345+
type: Workflow
346+
description: Store file analysis findings in memory for accumulation.
347+
condition: "{{ inputs.state | trim != '' }}"
348+
depends_on:
349+
- analyze_target
350+
- extract_target_path
351+
inputs:
352+
workflow: agent-state-management
353+
inputs:
354+
state: "{{ inputs.state }}"
355+
op: memory
356+
memory_op: append
357+
memory_key: "findings.by_file"
358+
memory_value: |
359+
{
360+
"path": "{{ (blocks.extract_target_path.outputs.stdout | fromjson).path }}",
361+
"analysis": {{ blocks.analyze_target.outputs.response | tojson }},
362+
"depth": {{ inputs.investigation_depth }}
363+
}
364+
caller: "pr-review:investigation-sub-workflow"
365+
341366
# ============================================================================
342367
# RECURSIVE INVESTIGATION: Process related files if needed
343368
# ============================================================================
@@ -382,7 +407,10 @@ blocks:
382407
condition: "{{ inputs.state and inputs.state != '' and blocks.track_file_start.succeeded }}"
383408
depends_on:
384409
- analyze_target
385-
- investigate_related_files
410+
- block: store_file_findings
411+
required: false
412+
- block: investigate_related_files
413+
required: false
386414
inputs:
387415
workflow: agent-state-management
388416
inputs:

src/workflows_mcp/templates/agents/pr-review/agent-investigation-loop/process-investigation-targets/main.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,31 @@ blocks:
179179
description: "New targets to investigate if continuation is needed"
180180
required: [confidence, needs_more_investigation, findings, conclusion]
181181

182+
# ============================================================================
183+
# MEMORY: Store iteration findings for accumulation
184+
# ============================================================================
185+
- id: store_iteration_findings
186+
type: Workflow
187+
description: Store this iteration's findings in memory for accumulation.
188+
condition: "{{ inputs.state | trim != '' }}"
189+
depends_on:
190+
- gather_results
191+
inputs:
192+
workflow: agent-state-management
193+
inputs:
194+
state: "{{ inputs.state }}"
195+
op: memory
196+
memory_op: append
197+
memory_key: "iterations.history"
198+
memory_value: |
199+
{
200+
"confidence": {{ blocks.gather_results.outputs.response.confidence | default(0) }},
201+
"findings": {{ blocks.gather_results.outputs.response.findings | default([]) | tojson }},
202+
"conclusion": "{{ blocks.gather_results.outputs.response.conclusion | default('') }}",
203+
"needs_more": {{ blocks.gather_results.outputs.response.needs_more_investigation | default(false) | tojson }}
204+
}
205+
caller: "pr-review:process-targets"
206+
182207
# ============================================================================
183208
# ITERATION: Advance iteration counter and check if capped
184209
# ============================================================================
@@ -187,6 +212,8 @@ blocks:
187212
description: Advance iteration counter and check if safety cap reached.
188213
depends_on:
189214
- gather_results
215+
- block: store_iteration_findings
216+
required: false
190217
condition: "{{ inputs.state | trim != '' and inputs.task_id | trim != '' }}"
191218
inputs:
192219
workflow: agent-state-management

src/workflows_mcp/templates/agents/pr-review/initial-assessment/main.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ blocks:
8585
description: |
8686
Consolidate PR analysis, risk assessment, and identification of
8787
investigation targets into a single structured response.
88+
depends_on:
89+
- block: track_start
90+
required: false
8891
inputs:
8992
profile: default
9093
prompt: |
@@ -215,6 +218,41 @@ blocks:
215218
description: "Brief summary of the change scope"
216219
required: [pr_intent, risk_level, risk_rationale, investigation_targets]
217220

221+
# ============================================================================
222+
# MEMORY: Store initial concerns for synthesis phase
223+
# ============================================================================
224+
- id: store_initial_concerns
225+
type: Workflow
226+
description: Store initial concerns in memory for synthesis phase access.
227+
condition: "{{ inputs.state | trim != '' }}"
228+
depends_on:
229+
- consolidated_pr_assessment
230+
inputs:
231+
workflow: agent-state-management
232+
inputs:
233+
state: "{{ inputs.state }}"
234+
op: memory
235+
memory_op: set
236+
memory_key: "synthesis.initial_concerns"
237+
memory_value: "{{ blocks.consolidated_pr_assessment.outputs.response.initial_concerns | default([]) | tojson }}"
238+
caller: "pr-review:initial-assessment"
239+
240+
- id: store_investigation_targets
241+
type: Workflow
242+
description: Store investigation targets in memory for reference.
243+
condition: "{{ inputs.state | trim != '' }}"
244+
depends_on:
245+
- consolidated_pr_assessment
246+
inputs:
247+
workflow: agent-state-management
248+
inputs:
249+
state: "{{ inputs.state }}"
250+
op: memory
251+
memory_op: set
252+
memory_key: "investigation.targets.initial"
253+
memory_value: "{{ blocks.consolidated_pr_assessment.outputs.response.investigation_targets | tojson }}"
254+
caller: "pr-review:initial-assessment"
255+
218256
# ============================================================================
219257
# STATE TRACKING: Mark phase complete with captured data
220258
# ============================================================================
@@ -224,6 +262,10 @@ blocks:
224262
condition: "{{ inputs.state | trim != '' and blocks.track_start.succeeded }}"
225263
depends_on:
226264
- consolidated_pr_assessment
265+
- block: store_initial_concerns
266+
required: false
267+
- block: store_investigation_targets
268+
required: false
227269
inputs:
228270
workflow: agent-state-management
229271
inputs:

src/workflows_mcp/templates/agents/pr-review/main.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,32 @@ blocks:
9090
ai: true
9191
audit: true
9292

93+
# ==========================================================================
94+
# MEMORY INITIALIZATION: Clear memory for fresh review
95+
# ==========================================================================
96+
- id: init_memory
97+
type: Workflow
98+
description: |
99+
Initialize/clear memory for this PR review execution.
100+
Creates fresh memory file to avoid cross-review contamination.
101+
depends_on:
102+
- state_management
103+
condition: "{{ blocks.state_management.outputs.state | trim != '' }}"
104+
inputs:
105+
workflow: agent-state-management
106+
inputs:
107+
state: "{{ blocks.state_management.outputs.state }}"
108+
op: memory
109+
memory_op: set
110+
memory_key: "_initialized"
111+
memory_value: |
112+
{
113+
"trace_id": "{{ blocks.state_management.outputs.trace_id }}",
114+
"started_at": "{{ now() }}",
115+
"version": 1
116+
}
117+
caller: "pr-review:main"
118+
93119
# ==========================================================================
94120
# PHASE 1: Context Gathering
95121
# Normalizes input (URL vs local path) and outputs consistent repo_path
@@ -101,6 +127,8 @@ blocks:
101127
Outputs normalized repo_path regardless of input source.
102128
depends_on:
103129
- state_management
130+
- block: init_memory
131+
required: false
104132
inputs:
105133
workflow: context-gathering
106134
inputs:

src/workflows_mcp/templates/agents/pr-review/synthesis/generate-report/main.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ inputs:
3333
required: false
3434
default: general
3535

36+
memory_summary:
37+
type: dict
38+
description: |
39+
Summary of accumulated memory data for report.
40+
Contains metrics from memory accumulation across phases.
41+
required: false
42+
default: {}
43+
3644
blocks:
3745
- id: generate_report_llm
3846
type: LLMCall
@@ -61,6 +69,17 @@ blocks:
6169
General comprehensive review.
6270
{% endif %}
6371
72+
## Investigation Summary
73+
{% if inputs.memory_summary and inputs.memory_summary != {} %}
74+
- **Initial Concerns Captured:** {{ inputs.memory_summary.initial_concerns_count | default(0) }}
75+
- **Files Analyzed:** {{ inputs.memory_summary.files_analyzed | default(0) }}
76+
- **Investigation Iterations:** {{ inputs.memory_summary.iterations_completed | default(0) }}
77+
- **Total Findings (before deduplication):** {{ inputs.memory_summary.total_findings_from_memory | default(0) }}
78+
- **Final Unique Findings:** {{ inputs.memory_summary.deduplicated_findings | default(0) }}
79+
{% else %}
80+
_No memory summary available_
81+
{% endif %}
82+
6483
## Findings ({{ inputs.filtered_findings | length }} total)
6584
```json
6685
{{ inputs.filtered_findings | tojson }}
@@ -84,11 +103,15 @@ blocks:
84103
- Highlight {{ inputs.focus }}-related issues prominently
85104
{% endif %}
86105
87-
3. **Recommendations**
106+
3. **Investigation Summary** (if memory_summary provided)
107+
- Include the metrics table from Investigation Summary above
108+
- Note if any findings came from initial concerns vs iterations
109+
110+
4. **Recommendations**
88111
- Actionable steps to address findings
89112
- Priority order
90113
91-
4. **Conclusion**
114+
5. **Conclusion**
92115
- Overall verdict
93116
- Whether PR is ready to merge
94117

0 commit comments

Comments
 (0)