ace-handbook 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ace-defaults/handbook/config.yml +4 -0
- data/.ace-defaults/nav/protocols/guide-sources/ace-handbook.yml +19 -0
- data/.ace-defaults/nav/protocols/tmpl-sources/ace-handbook.yml +10 -0
- data/.ace-defaults/nav/protocols/wfi-sources/ace-handbook.yml +19 -0
- data/CHANGELOG.md +362 -0
- data/LICENSE +21 -0
- data/README.md +42 -0
- data/Rakefile +12 -0
- data/exe/ace-handbook +6 -0
- data/handbook/guides/ai-agent-integration.g.md +625 -0
- data/handbook/guides/atom-pattern.g.md +371 -0
- data/handbook/guides/changelog.g.md +333 -0
- data/handbook/guides/cli-dry-cli.g.md +276 -0
- data/handbook/guides/cli-support-cli.g.md +277 -0
- data/handbook/guides/coding-standards/ruby.md +41 -0
- data/handbook/guides/coding-standards/rust.md +19 -0
- data/handbook/guides/coding-standards/typescript.md +20 -0
- data/handbook/guides/coding-standards.g.md +134 -0
- data/handbook/guides/debug-troubleshooting.g.md +62 -0
- data/handbook/guides/error-handling/ruby.md +29 -0
- data/handbook/guides/error-handling/rust.md +59 -0
- data/handbook/guides/error-handling/typescript.md +38 -0
- data/handbook/guides/error-handling.g.md +207 -0
- data/handbook/guides/meta/agents-definition.g.md +823 -0
- data/handbook/guides/meta/guides-definition.g.md +322 -0
- data/handbook/guides/meta/markdown-definition.g.md +210 -0
- data/handbook/guides/meta/tools-definition.g.md +159 -0
- data/handbook/guides/meta/workflow-instructions-definition.g.md +367 -0
- data/handbook/guides/mono-repo-patterns.g.md +92 -0
- data/handbook/guides/multi-agent-research.g.md +251 -0
- data/handbook/guides/performance/ruby.md +25 -0
- data/handbook/guides/performance/rust.md +48 -0
- data/handbook/guides/performance/typescript.md +32 -0
- data/handbook/guides/performance.g.md +211 -0
- data/handbook/guides/prompt-caching.g.md +83 -0
- data/handbook/guides/quality-assurance/ruby.md +33 -0
- data/handbook/guides/quality-assurance/rust.md +41 -0
- data/handbook/guides/quality-assurance/typescript.md +49 -0
- data/handbook/guides/quality-assurance.g.md +222 -0
- data/handbook/guides/strategic-planning.g.md +69 -0
- data/handbook/guides/troubleshooting/ruby.md +21 -0
- data/handbook/guides/troubleshooting/rust.md +20 -0
- data/handbook/guides/troubleshooting/typescript.md +36 -0
- data/handbook/guides/workflow-context-embedding.g.md +286 -0
- data/handbook/skills/as-handbook-init-project/SKILL.md +34 -0
- data/handbook/skills/as-handbook-manage-agents/SKILL.md +35 -0
- data/handbook/skills/as-handbook-manage-guides/SKILL.md +35 -0
- data/handbook/skills/as-handbook-manage-workflows/SKILL.md +35 -0
- data/handbook/skills/as-handbook-parallel-research/SKILL.md +29 -0
- data/handbook/skills/as-handbook-perform-delivery/SKILL.md +35 -0
- data/handbook/skills/as-handbook-review-guides/SKILL.md +32 -0
- data/handbook/skills/as-handbook-review-workflows/SKILL.md +32 -0
- data/handbook/skills/as-handbook-synthesize-research/SKILL.md +29 -0
- data/handbook/skills/as-handbook-update-docs/SKILL.md +35 -0
- data/handbook/skills/as-release/SKILL.md +50 -0
- data/handbook/skills/as-release-bump-version/SKILL.md +28 -0
- data/handbook/skills/as-release-rubygems-publish/SKILL.md +58 -0
- data/handbook/skills/as-release-update-changelog/SKILL.md +28 -0
- data/handbook/templates/completed-work-documentation.md +59 -0
- data/handbook/templates/cookbooks/cookbook.template.md +237 -0
- data/handbook/templates/research-comparison.template.md +175 -0
- data/handbook/workflow-instructions/handbook/init-project.wf.md +629 -0
- data/handbook/workflow-instructions/handbook/manage-agents.wf.md +379 -0
- data/handbook/workflow-instructions/handbook/manage-guides.wf.md +294 -0
- data/handbook/workflow-instructions/handbook/manage-workflows.wf.md +292 -0
- data/handbook/workflow-instructions/handbook/parallel-research.wf.md +328 -0
- data/handbook/workflow-instructions/handbook/perform-delivery.wf.md +267 -0
- data/handbook/workflow-instructions/handbook/research.wf.md +247 -0
- data/handbook/workflow-instructions/handbook/review-guides.wf.md +348 -0
- data/handbook/workflow-instructions/handbook/review-workflows.wf.md +299 -0
- data/handbook/workflow-instructions/handbook/synthesize-research.wf.md +429 -0
- data/handbook/workflow-instructions/handbook/update-docs.wf.md +338 -0
- data/lib/ace/handbook/atoms/provider_registry.rb +70 -0
- data/lib/ace/handbook/cli/commands/status.rb +36 -0
- data/lib/ace/handbook/cli/commands/sync.rb +36 -0
- data/lib/ace/handbook/cli.rb +51 -0
- data/lib/ace/handbook/models/skill_document.rb +25 -0
- data/lib/ace/handbook/molecules/skill_projection.rb +54 -0
- data/lib/ace/handbook/organisms/provider_syncer.rb +106 -0
- data/lib/ace/handbook/organisms/skill_inventory.rb +54 -0
- data/lib/ace/handbook/organisms/status_collector.rb +181 -0
- data/lib/ace/handbook/version.rb +7 -0
- data/lib/ace/handbook.rb +28 -0
- metadata +227 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: guide
|
|
3
|
+
title: Multi-Agent Research Guide
|
|
4
|
+
purpose: Documentation for ace-handbook/handbook/guides/multi-agent-research.g.md
|
|
5
|
+
ace-docs:
|
|
6
|
+
last-updated: 2026-02-22
|
|
7
|
+
last-checked: 2026-03-21
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Multi-Agent Research Guide
|
|
11
|
+
|
|
12
|
+
This guide explains when and how to leverage multiple AI agents for research tasks, combining their diverse capabilities to produce higher-quality, more comprehensive results.
|
|
13
|
+
|
|
14
|
+
## Purpose
|
|
15
|
+
|
|
16
|
+
Multi-agent research uses parallel execution across different AI models followed by structured synthesis to:
|
|
17
|
+
- Reduce individual model blind spots through cross-validation
|
|
18
|
+
- Surface diverse perspectives and approaches
|
|
19
|
+
- Increase confidence in findings through consensus
|
|
20
|
+
- Extend effective context through task division
|
|
21
|
+
|
|
22
|
+
## When to Use Multi-Agent Research
|
|
23
|
+
|
|
24
|
+
### Good Use Cases
|
|
25
|
+
|
|
26
|
+
| Scenario | Why Multi-Agent Helps |
|
|
27
|
+
|----------|----------------------|
|
|
28
|
+
| Complex research topics | Different models have different knowledge and reasoning styles |
|
|
29
|
+
| High-stakes decisions | Cross-validation reduces hallucinations and errors |
|
|
30
|
+
| Novel domains | Diverse perspectives surface more options |
|
|
31
|
+
| Standard-setting | Consensus building across multiple viewpoints |
|
|
32
|
+
| Exploratory research | Broader coverage of solution space |
|
|
33
|
+
|
|
34
|
+
### When NOT to Use
|
|
35
|
+
|
|
36
|
+
| Scenario | Why Single Agent is Better |
|
|
37
|
+
|----------|---------------------------|
|
|
38
|
+
| Simple, well-defined tasks | Overhead not justified |
|
|
39
|
+
| Time-critical work | Parallel + synthesis adds latency |
|
|
40
|
+
| Cost-sensitive projects | 3x+ token usage |
|
|
41
|
+
| Clear single source of truth | No benefit from diversity |
|
|
42
|
+
| Implementation tasks | Execution benefits from consistency |
|
|
43
|
+
|
|
44
|
+
### Decision Criteria
|
|
45
|
+
|
|
46
|
+
Ask yourself:
|
|
47
|
+
1. **Is the task primarily research or implementation?** Multi-agent works best for research.
|
|
48
|
+
2. **Would multiple perspectives add value?** If one answer is clearly correct, single agent suffices.
|
|
49
|
+
3. **Is the cost justified?** Multi-agent typically costs 3-5x a single-agent approach.
|
|
50
|
+
4. **Do you have time for synthesis?** Plan for 20-30% additional effort for combination.
|
|
51
|
+
|
|
52
|
+
## Agent Selection Criteria
|
|
53
|
+
|
|
54
|
+
### Quality Over Diversity
|
|
55
|
+
|
|
56
|
+
Research shows that mixing high-quality agents produces better results than adding lower-quality agents for diversity. The key finding:
|
|
57
|
+
|
|
58
|
+
> "Diversity in MoA proposers might have an adverse effect... MoA performance is sensitive to the quality of the models being mixed."
|
|
59
|
+
> — Princeton Research on Mixture-of-Agents
|
|
60
|
+
|
|
61
|
+
### Selection Principles
|
|
62
|
+
|
|
63
|
+
1. **Choose capable models**: Each agent should be able to complete the task solo
|
|
64
|
+
2. **Prefer complementary strengths**: Agents with different training data or specializations
|
|
65
|
+
3. **Avoid weak links**: One poor agent can degrade overall synthesis quality
|
|
66
|
+
4. **Consider context limits**: Match agent capabilities to task requirements
|
|
67
|
+
|
|
68
|
+
### Recommended Configurations
|
|
69
|
+
|
|
70
|
+
| Research Type | Suggested Agents | Rationale |
|
|
71
|
+
|---------------|------------------|-----------|
|
|
72
|
+
| Code analysis | Claude, Codex, Gemini | Strong code understanding |
|
|
73
|
+
| Technical docs | Claude, Gemini | Strong reasoning and knowledge |
|
|
74
|
+
| Architecture | Claude, Gemini, GPT-4 | Diverse design perspectives |
|
|
75
|
+
| Security review | Multiple specialized models | Defense in depth |
|
|
76
|
+
|
|
77
|
+
## Task Formulation for Parallel Work
|
|
78
|
+
|
|
79
|
+
### Consistent Prompting
|
|
80
|
+
|
|
81
|
+
All agents should receive the same core prompt to enable meaningful comparison:
|
|
82
|
+
|
|
83
|
+
```markdown
|
|
84
|
+
## Research Task
|
|
85
|
+
|
|
86
|
+
**Topic**: [Clear description of what to research]
|
|
87
|
+
**Scope**: [Boundaries of the investigation]
|
|
88
|
+
**Expected Outputs**:
|
|
89
|
+
- Main report with findings
|
|
90
|
+
- Supplementary artifacts (guides, templates, etc.)
|
|
91
|
+
- Recommendations with rationale
|
|
92
|
+
|
|
93
|
+
## Context
|
|
94
|
+
[Shared context all agents need]
|
|
95
|
+
|
|
96
|
+
## Deliverables Format
|
|
97
|
+
[Consistent structure for outputs]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Avoid These Pitfalls
|
|
101
|
+
|
|
102
|
+
- **Vague prompts**: Lead to incomparable outputs
|
|
103
|
+
- **Different scopes**: Make synthesis difficult
|
|
104
|
+
- **Inconsistent output formats**: Complicate comparison
|
|
105
|
+
- **Missing context**: Results in agents making different assumptions
|
|
106
|
+
|
|
107
|
+
## Cross-Review Protocol
|
|
108
|
+
|
|
109
|
+
The cross-review phase is critical for surfacing blind spots and building toward consensus.
|
|
110
|
+
|
|
111
|
+
### Process
|
|
112
|
+
|
|
113
|
+
1. **Distribution**: Each agent receives all other agents' reports
|
|
114
|
+
2. **Analysis**: Each agent identifies:
|
|
115
|
+
- Points of agreement (reinforces confidence)
|
|
116
|
+
- Points of disagreement (requires resolution)
|
|
117
|
+
- Gaps in other reports (opportunities for contribution)
|
|
118
|
+
- Improvements to incorporate
|
|
119
|
+
3. **Self-Enhancement**: Each agent improves own report with peer insights
|
|
120
|
+
4. **Attribution**: Credit sources when incorporating ideas
|
|
121
|
+
|
|
122
|
+
### Cross-Review Prompt Template
|
|
123
|
+
|
|
124
|
+
```markdown
|
|
125
|
+
## Cross-Review Task
|
|
126
|
+
|
|
127
|
+
You have completed initial research on [topic]. Below are reports from peer agents.
|
|
128
|
+
|
|
129
|
+
### Peer Reports
|
|
130
|
+
[Include all peer reports]
|
|
131
|
+
|
|
132
|
+
### Your Task
|
|
133
|
+
1. Identify agreements across reports
|
|
134
|
+
2. Note disagreements and evaluate which position is stronger
|
|
135
|
+
3. Find gaps in your report that peers covered
|
|
136
|
+
4. Enhance your report by incorporating valuable insights (with attribution)
|
|
137
|
+
5. Document your reasoning for key decisions
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Synthesis Process Overview
|
|
141
|
+
|
|
142
|
+
Synthesis combines multiple agent outputs into a unified result. See [Synthesize Research Workflow](wfi://handbook/synthesize-research) for detailed execution steps.
|
|
143
|
+
|
|
144
|
+
### Key Phases
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
148
|
+
│ PHASE 1: INVENTORY │
|
|
149
|
+
│ - List all reports and supplementary artifacts │
|
|
150
|
+
│ - Create comparison matrix (artifacts × agents) │
|
|
151
|
+
│ - Rate quality and completeness │
|
|
152
|
+
└─────────────────────────────────────────────────────────────┘
|
|
153
|
+
↓
|
|
154
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
155
|
+
│ PHASE 2: COMPARE │
|
|
156
|
+
│ - Side-by-side analysis by artifact type │
|
|
157
|
+
│ - Note conflicts and disagreements │
|
|
158
|
+
│ - Rate depth, accuracy, actionability │
|
|
159
|
+
└─────────────────────────────────────────────────────────────┘
|
|
160
|
+
↓
|
|
161
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
162
|
+
│ PHASE 3: RESOLVE │
|
|
163
|
+
│ - Document conflicts with both positions │
|
|
164
|
+
│ - Research/verify factual disagreements │
|
|
165
|
+
│ - Make reasoned decisions with rationale │
|
|
166
|
+
└─────────────────────────────────────────────────────────────┘
|
|
167
|
+
↓
|
|
168
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
169
|
+
│ PHASE 4: SYNTHESIZE │
|
|
170
|
+
│ - Select base (usually most comprehensive report) │
|
|
171
|
+
│ - Merge unique contributions from others │
|
|
172
|
+
│ - Ensure consistent terminology │
|
|
173
|
+
│ - Credit source reports │
|
|
174
|
+
└─────────────────────────────────────────────────────────────┘
|
|
175
|
+
↓
|
|
176
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
177
|
+
│ PHASE 5: VALIDATE │
|
|
178
|
+
│ - Completeness check (nothing valuable lost) │
|
|
179
|
+
│ - Consistency check (no contradictions) │
|
|
180
|
+
│ - Gap identification (for future work) │
|
|
181
|
+
└─────────────────────────────────────────────────────────────┘
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Aggregator Role
|
|
185
|
+
|
|
186
|
+
The synthesis should be performed by a dedicated aggregator (human or agent) who:
|
|
187
|
+
- Has access to all agent outputs
|
|
188
|
+
- Can make objective comparisons
|
|
189
|
+
- Documents all decisions with rationale
|
|
190
|
+
- Produces unified, consistent output
|
|
191
|
+
|
|
192
|
+
## Quality Validation Checklist
|
|
193
|
+
|
|
194
|
+
### Before Parallel Research
|
|
195
|
+
|
|
196
|
+
- [ ] Research question is clearly defined
|
|
197
|
+
- [ ] All agents receive identical prompts
|
|
198
|
+
- [ ] Output format is specified consistently
|
|
199
|
+
- [ ] Shared context is complete and accurate
|
|
200
|
+
- [ ] Success criteria are defined
|
|
201
|
+
|
|
202
|
+
### After Cross-Review
|
|
203
|
+
|
|
204
|
+
- [ ] Each agent produced enhanced report
|
|
205
|
+
- [ ] Agreements are documented
|
|
206
|
+
- [ ] Disagreements are identified
|
|
207
|
+
- [ ] Sources are properly attributed
|
|
208
|
+
|
|
209
|
+
### After Synthesis
|
|
210
|
+
|
|
211
|
+
- [ ] Comparison matrix is complete
|
|
212
|
+
- [ ] All conflicts have documented resolutions
|
|
213
|
+
- [ ] Unified report covers all key findings
|
|
214
|
+
- [ ] No contradictions in final output
|
|
215
|
+
- [ ] Gaps are identified for future work
|
|
216
|
+
- [ ] All sources are credited
|
|
217
|
+
|
|
218
|
+
## Key Insights from Research
|
|
219
|
+
|
|
220
|
+
### Industry Patterns
|
|
221
|
+
|
|
222
|
+
| Pattern | Description | Benefit |
|
|
223
|
+
|---------|-------------|---------|
|
|
224
|
+
| Mixture-of-Agents (MoA) | Proposers generate, aggregator synthesizes | Outperforms single agents |
|
|
225
|
+
| Iterative Consensus (ICE) | 2-3 rounds of critique until consensus | +7-15% accuracy |
|
|
226
|
+
| LLM-BLENDER | Rank responses, blend best ones | Selects highest quality |
|
|
227
|
+
|
|
228
|
+
### Best Practices
|
|
229
|
+
|
|
230
|
+
1. **Quality > Quantity**: 3 quality agents outperform 5 mediocre ones
|
|
231
|
+
2. **Document decisions**: Synthesis rationale is valuable for future reference
|
|
232
|
+
3. **Human validation**: Final quality check remains important
|
|
233
|
+
4. **Iterate if needed**: 2-3 review rounds typically sufficient
|
|
234
|
+
|
|
235
|
+
## Related Resources
|
|
236
|
+
|
|
237
|
+
- [Research Comparison Template](tmpl://research-comparison) - Structured comparison matrix
|
|
238
|
+
- [Synthesize Research Workflow](wfi://handbook/synthesize-research) - Detailed synthesis process
|
|
239
|
+
- [Parallel Research Workflow](wfi://handbook/parallel-research) - Setting up parallel execution
|
|
240
|
+
|
|
241
|
+
## References
|
|
242
|
+
|
|
243
|
+
### Academic Sources
|
|
244
|
+
- [Mixture-of-Agents (arXiv 2406.04692)](https://arxiv.org/abs/2406.04692)
|
|
245
|
+
- [Multi-Agent Collaboration Mechanisms Survey (arXiv 2501.06322)](https://arxiv.org/abs/2501.06322)
|
|
246
|
+
- [Iterative Consensus Ensemble (ScienceDirect)](https://www.sciencedirect.com/science/article/abs/pii/S0010482525010820)
|
|
247
|
+
|
|
248
|
+
### Industry Sources
|
|
249
|
+
- [LLM Orchestration Best Practices (orq.ai)](https://orq.ai/blog/llm-orchestration)
|
|
250
|
+
- [Multi-Agent LLMs in 2025 (SuperAnnotate)](https://www.superannotate.com/blog/multi-agent-llms)
|
|
251
|
+
- [Awesome-LLM-Ensemble (GitHub)](https://github.com/junchenzhi/Awesome-LLM-Ensemble)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Ruby Performance Examples
|
|
2
|
+
|
|
3
|
+
This file provides Ruby-specific examples related to the main [Performance Guide](../performance.g.md).
|
|
4
|
+
|
|
5
|
+
* **Benchmarking:** `Benchmark` standard library module.
|
|
6
|
+
* **Profiling:** `stackprof`, `ruby-prof` gems.
|
|
7
|
+
* **Memory Analysis:** `memory_profiler` gem.
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
require 'benchmark'
|
|
11
|
+
|
|
12
|
+
iterations = 100_000
|
|
13
|
+
|
|
14
|
+
Benchmark.bm(7) do |x|
|
|
15
|
+
x.report("String Interpolation:") { iterations.times do; "User ID: #{123}"; end }
|
|
16
|
+
x.report("String Concat:") { iterations.times do; 'User ID: ' + 123.to_s; end }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Example using stackprof (conceptual)
|
|
20
|
+
# require 'stackprof'
|
|
21
|
+
# StackProf.run(mode: :cpu, out: 'tmp/stackprof-cpu.dump') do
|
|
22
|
+
# # Code to profile
|
|
23
|
+
# 1000.times { perform_complex_operation }
|
|
24
|
+
# end
|
|
25
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Rust Performance Examples
|
|
2
|
+
|
|
3
|
+
This file provides Rust-specific examples related to the main [Performance Guide](../performance.g.md).
|
|
4
|
+
|
|
5
|
+
* **Benchmarking:** `cargo bench` (requires nightly toolchain or stable with `criterion` crate), `std::time::Instant`.
|
|
6
|
+
* **Profiling:** `perf` (Linux), Instruments (macOS), `cargo flamegraph`, `pprof` crate.
|
|
7
|
+
* **Memory Analysis:** Valgrind (with caution), `dhat` crate, platform-specific tools.
|
|
8
|
+
|
|
9
|
+
```rust
|
|
10
|
+
use std::time::Instant;
|
|
11
|
+
|
|
12
|
+
// Simple timing using std::time::Instant
|
|
13
|
+
fn main() {
|
|
14
|
+
let start = Instant::now();
|
|
15
|
+
|
|
16
|
+
// Code to measure
|
|
17
|
+
let mut sum = 0;
|
|
18
|
+
for i in 0..1_000_000 {
|
|
19
|
+
sum += i;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let duration = start.elapsed();
|
|
23
|
+
|
|
24
|
+
println!("Time elapsed in expensive_function() is: {:?}", duration);
|
|
25
|
+
println!("Sum: {}", sum); // Prevent optimization from removing the loop
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// For proper benchmarking, use `cargo bench` with `criterion` crate
|
|
29
|
+
// Example (in benches/my_benchmark.rs):
|
|
30
|
+
/*
|
|
31
|
+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
32
|
+
|
|
33
|
+
fn fibonacci(n: u64) -> u64 {
|
|
34
|
+
match n {
|
|
35
|
+
0 => 1,
|
|
36
|
+
1 => 1,
|
|
37
|
+
n => fibonacci(n-1) + fibonacci(n-2),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn criterion_benchmark(c: &mut Criterion) {
|
|
42
|
+
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
criterion_group!(benches, criterion_benchmark);
|
|
46
|
+
criterion_main!(benches);
|
|
47
|
+
*/
|
|
48
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# TypeScript Performance Examples
|
|
2
|
+
|
|
3
|
+
This file provides TypeScript-specific examples related to the main [Performance Guide](../performance.g.md).
|
|
4
|
+
|
|
5
|
+
* **Benchmarking:** `console.time`/`console.timeEnd`, `performance.now()` (Node.js/Browser), libraries like `benchmark.js`.
|
|
6
|
+
* **Profiling:** Node.js inspector (`node --inspect`), Chrome DevTools profiler.
|
|
7
|
+
* **Memory Analysis:** Node.js inspector, Chrome DevTools memory tab.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// Simple benchmarking using console.time
|
|
11
|
+
const iterations = 100000;
|
|
12
|
+
|
|
13
|
+
console.time('Array Push');
|
|
14
|
+
const arr1: number[] = [];
|
|
15
|
+
for (let i = 0; i < iterations; i++) {
|
|
16
|
+
arr1.push(i);
|
|
17
|
+
}
|
|
18
|
+
console.timeEnd('Array Push');
|
|
19
|
+
|
|
20
|
+
console.time('Array Pre-alloc');
|
|
21
|
+
const arr2: number[] = new Array(iterations);
|
|
22
|
+
for (let i = 0; i < iterations; i++) {
|
|
23
|
+
arr2[i] = i;
|
|
24
|
+
}
|
|
25
|
+
console.timeEnd('Array Pre-alloc');
|
|
26
|
+
|
|
27
|
+
// Using performance.now() (more precise, available in Node and Browsers)
|
|
28
|
+
const start = performance.now();
|
|
29
|
+
// Code to measure
|
|
30
|
+
const end = performance.now();
|
|
31
|
+
console.log(`Execution time: ${end - start} ms`);
|
|
32
|
+
```
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: guide
|
|
3
|
+
title: Performance Tuning Guidelines
|
|
4
|
+
purpose: Documentation for ace-handbook/handbook/guides/performance.g.md
|
|
5
|
+
ace-docs:
|
|
6
|
+
last-updated: 2026-01-08
|
|
7
|
+
last-checked: 2026-03-21
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Performance Tuning Guidelines
|
|
11
|
+
|
|
12
|
+
## Goal
|
|
13
|
+
|
|
14
|
+
This guide provides standard practices and techniques for identifying, measuring, and optimizing
|
|
15
|
+
performance aspects (memory usage, execution speed, concurrency) within the project.
|
|
16
|
+
|
|
17
|
+
## 1. Memory Management
|
|
18
|
+
|
|
19
|
+
- **Object Pooling:** Use pooling for expensive or frequently created/destroyed objects (e.g.,
|
|
20
|
+
database connections, threads, large buffers) if your language/framework provides suitable libraries.
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
// Pseudo-code example: Using a generic connection pool
|
|
24
|
+
const connectionPool = createPool({
|
|
25
|
+
create: () => new DatabaseConnection(),
|
|
26
|
+
destroy: (conn) => conn.close(),
|
|
27
|
+
max: 10 // Max number of pooled connections
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function performDatabaseQuery() {
|
|
31
|
+
const connection = await connectionPool.acquire();
|
|
32
|
+
try {
|
|
33
|
+
// Use connection
|
|
34
|
+
} finally {
|
|
35
|
+
connectionPool.release(connection);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- **Memory Leaks:** Be vigilant about memory leaks in long-running processes or applications. Use
|
|
41
|
+
language-specific tools (profilers, heap analyzers) to detect and fix leaks.
|
|
42
|
+
- Explicitly release resources when done.
|
|
43
|
+
- Break circular references if using languages with reference counting or specific GC patterns.
|
|
44
|
+
- Consider explicit garbage collection triggers *judiciously* if needed, but prefer designing code to be GC-friendly.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
// Conceptual example of resource cleanup
|
|
48
|
+
function executeBatch(batch) {
|
|
49
|
+
// Optional: trigger GC before potentially large allocation/operation
|
|
50
|
+
triggerGarbageCollectionIfNeeded();
|
|
51
|
+
|
|
52
|
+
const results = batch.map(task => {
|
|
53
|
+
const agent = createAgentForTask(task);
|
|
54
|
+
try {
|
|
55
|
+
return agent.execute(task);
|
|
56
|
+
} finally {
|
|
57
|
+
agent.cleanupResources(); // Ensure resource cleanup
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Optional: trigger GC after potentially large operation
|
|
62
|
+
triggerGarbageCollectionIfNeeded();
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 2. Benchmarking
|
|
68
|
+
|
|
69
|
+
Use appropriate benchmarking libraries for your language/stack to measure the performance of critical code paths.
|
|
70
|
+
|
|
71
|
+
- **Micro-benchmarks:** Measure the speed of small functions or operations using dedicated benchmarking tools.
|
|
72
|
+
- **Memory Profiling:** Measure memory allocation and identify potential leaks using memory analysis tools.
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
// Pseudo-code example: Micro-benchmarking
|
|
76
|
+
const suite = new Benchmark.Suite;
|
|
77
|
+
|
|
78
|
+
suite
|
|
79
|
+
.add('Operation A', function() {
|
|
80
|
+
performOperationA();
|
|
81
|
+
})
|
|
82
|
+
.add('Operation B', function() {
|
|
83
|
+
performOperationB();
|
|
84
|
+
})
|
|
85
|
+
.on('cycle', function(event) {
|
|
86
|
+
console.log(String(event.target));
|
|
87
|
+
})
|
|
88
|
+
.on('complete', function() {
|
|
89
|
+
console.log('Fastest is ' + this.filter('fastest').map('name'));
|
|
90
|
+
})
|
|
91
|
+
.run({ 'async': true });
|
|
92
|
+
|
|
93
|
+
// Pseudo-code example: Memory profiling concept
|
|
94
|
+
startMemoryProfiling();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
// Pseudo-code example: Memory profiling concept
|
|
99
|
+
startMemoryProfiling();
|
|
100
|
+
|
|
101
|
+
for (let i = 0; i < 100; i++) {
|
|
102
|
+
agent.execute(someTask);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const report = stopMemoryProfiling();
|
|
106
|
+
printMemoryReport(report); // Analyze allocations, retained objects, etc.
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 3. Threading & Concurrency Optimization
|
|
110
|
+
|
|
111
|
+
Optimize concurrent operations carefully.
|
|
112
|
+
|
|
113
|
+
- **Thread Pools:** Use thread pools to manage a fixed number of threads, reducing the overhead of
|
|
114
|
+
thread creation/destruction and controlling resource usage using libraries appropriate for your
|
|
115
|
+
language.
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
// Pseudo-code example: Thread pool configuration
|
|
119
|
+
const threadPool = createThreadPool({
|
|
120
|
+
minThreads: 2,
|
|
121
|
+
maxThreads: Math.max(getCpuCoreCount() - 1, 2),
|
|
122
|
+
maxQueueSize: 100,
|
|
123
|
+
fallbackPolicy: 'callerRuns' // Policy if queue is full
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- **Asynchronous Operations:** Prefer non-blocking I/O and asynchronous patterns (`async/await`,
|
|
128
|
+
Promises, Futures, callbacks, etc.) where possible, especially for I/O-bound tasks.
|
|
129
|
+
- **Batch Processing:** Process tasks in batches using available concurrency mechanisms.
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
// Pseudo-code example: Batch processing with async/await and promises
|
|
133
|
+
async function processBatch(tasks) {
|
|
134
|
+
const promises = tasks.map(task => {
|
|
135
|
+
// Schedule task execution (e.g., using a thread pool or async function)
|
|
136
|
+
return scheduleAsyncTask(() => agent.execute(task));
|
|
137
|
+
});
|
|
138
|
+
// Wait for all tasks in the batch to complete
|
|
139
|
+
return await Promise.all(promises);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 4. Monitoring Points
|
|
144
|
+
|
|
145
|
+
Instrument your code to send performance metrics (timing, counts, gauges) to a monitoring system
|
|
146
|
+
(e.g., StatsD, Prometheus, Datadog).
|
|
147
|
+
|
|
148
|
+
- Wrap critical operations or external calls with timing measurements.
|
|
149
|
+
- Track queue sizes, pool usage, error rates.
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
// Pseudo-code example: Instrumentation
|
|
153
|
+
function measureOperation(operationName, func) {
|
|
154
|
+
const start = highResolutionTimeNow();
|
|
155
|
+
try {
|
|
156
|
+
const result = func();
|
|
157
|
+
const duration = highResolutionTimeNow() - start;
|
|
158
|
+
// Send timing metric to monitoring system (e.g., StatsD)
|
|
159
|
+
statsd.timing(`agent.${operationName}.success`, duration);
|
|
160
|
+
return result;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
const duration = highResolutionTimeNow() - start;
|
|
163
|
+
// Send error count and timing
|
|
164
|
+
statsd.increment(`agent.${operationName}.error`);
|
|
165
|
+
statsd.timing(`agent.${operationName}.error`, duration);
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```javascript
|
|
170
|
+
|
|
171
|
+
// Usage
|
|
172
|
+
function execute(task) {
|
|
173
|
+
return measureOperation('execution', () => {
|
|
174
|
+
// Original task execution logic
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 5. Performance Testing
|
|
181
|
+
|
|
182
|
+
- **Benchmarking:** Measure the execution time of critical code paths before and after optimization.
|
|
183
|
+
- **Load Testing:** Simulate realistic user load to identify bottlenecks under stress.
|
|
184
|
+
- **Profiling in CI:** Integrate basic performance checks into CI to catch regressions early.
|
|
185
|
+
|
|
186
|
+
**Example Benchmarking (Conceptual):**
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
// Pseudocode for benchmarking
|
|
190
|
+
startTime = getCurrentTime();
|
|
191
|
+
runCriticalFunction(testData);
|
|
192
|
+
endTime = getCurrentTime();
|
|
193
|
+
duration = endTime - startTime;
|
|
194
|
+
logBenchmarkResult("criticalFunction", duration);
|
|
195
|
+
|
|
196
|
+
// Compare against baseline or previous runs
|
|
197
|
+
if (duration > baselineDuration * 1.1) {
|
|
198
|
+
reportPerformanceRegression("criticalFunction", duration, baselineDuration);
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Language/Environment-Specific Examples
|
|
203
|
+
|
|
204
|
+
For specific examples of profiling tools, benchmarking libraries, memory analysis techniques, or language-specific
|
|
205
|
+
performance optimizations (e.g., Ruby's `benchmark` module, Python's `cProfile`, Go's `pprof`, Node.js performance
|
|
206
|
+
hooks), please refer to the examples in the [./performance/](./performance/) sub-directory.
|
|
207
|
+
|
|
208
|
+
## Related Documentation
|
|
209
|
+
|
|
210
|
+
- [Testing Guidelines](guide://testing) (Benchmarking, Load Testing)
|
|
211
|
+
- [Quality Assurance](./quality-assurance.g.md) (Monitoring)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: guide
|
|
3
|
+
title: Prompt Caching Pattern
|
|
4
|
+
purpose: Documentation for ace-handbook/handbook/guides/prompt-caching.g.md
|
|
5
|
+
ace-docs:
|
|
6
|
+
last-updated: 2026-03-04
|
|
7
|
+
last-checked: 2026-03-21
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Prompt Caching Pattern
|
|
11
|
+
|
|
12
|
+
Standardized pattern for gems that generate prompts for LLM interactions.
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
Gems that generate prompts (ace-review, ace-docs, ace-prompt-prep) use the `PromptCacheManager` from ace-support-core to store prompts in a predictable location for debugging and inspection.
|
|
17
|
+
|
|
18
|
+
## Directory Structure
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
.cache/
|
|
22
|
+
└── {gem-name}/
|
|
23
|
+
└── sessions/
|
|
24
|
+
└── {operation}-{timestamp}/
|
|
25
|
+
├── system.prompt.md # System prompt
|
|
26
|
+
├── user.prompt.md # User prompt
|
|
27
|
+
└── metadata.yml # Session metadata (optional)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API Usage
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
require 'ace/core/molecules/prompt_cache_manager'
|
|
34
|
+
|
|
35
|
+
# Create session directory
|
|
36
|
+
session_dir = Ace::Core::Molecules::PromptCacheManager.create_session(
|
|
37
|
+
"ace-my-gem",
|
|
38
|
+
"my-operation"
|
|
39
|
+
)
|
|
40
|
+
# Returns: .ace-local/my-gem/sessions/my-operation-20261116-143022/
|
|
41
|
+
|
|
42
|
+
# Save prompts
|
|
43
|
+
Ace::Core::Molecules::PromptCacheManager.save_system_prompt(
|
|
44
|
+
system_prompt_content,
|
|
45
|
+
session_dir
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
Ace::Core::Molecules::PromptCacheManager.save_user_prompt(
|
|
49
|
+
user_prompt_content,
|
|
50
|
+
session_dir
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Save metadata (optional)
|
|
54
|
+
metadata = {
|
|
55
|
+
"timestamp" => Time.now.utc.iso8601,
|
|
56
|
+
"gem" => "ace-my-gem",
|
|
57
|
+
"operation" => "my-operation",
|
|
58
|
+
"model" => "google:gemini-2.5-flash",
|
|
59
|
+
"prompt_sizes" => { "system" => 1234, "user" => 5678 }
|
|
60
|
+
}
|
|
61
|
+
Ace::Core::Molecules::PromptCacheManager.save_metadata(metadata, session_dir)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Benefits
|
|
65
|
+
|
|
66
|
+
- **Consistent locations**: All prompt caches in predictable `.cache/{gem}/sessions/` structure
|
|
67
|
+
- **Standard naming**: `system.prompt.md`, `user.prompt.md` across all gems
|
|
68
|
+
- **Git worktree support**: Uses ProjectRootFinder internally
|
|
69
|
+
- **Easy debugging**: Inspect exact prompts sent to LLMs
|
|
70
|
+
- **Metadata tracking**: Optional standardized metadata format
|
|
71
|
+
|
|
72
|
+
## Production Examples
|
|
73
|
+
|
|
74
|
+
| Gem | Usage |
|
|
75
|
+
|-----|-------|
|
|
76
|
+
| ace-docs | analyze-consistency operation |
|
|
77
|
+
| ace-prompt-prep | enhanced prompts with content-based deduplication |
|
|
78
|
+
| ace-review | session caching (optional migration to shared utility) |
|
|
79
|
+
|
|
80
|
+
## Related
|
|
81
|
+
|
|
82
|
+
- [ace-gems.g.md](../../../docs/ace-gems.g.md) - Gem development overview
|
|
83
|
+
- [ADR-022](../../../docs/decisions/ADR-022-configuration-default-and-override-pattern.md) - Configuration patterns
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Ruby Quality Assurance Examples
|
|
2
|
+
|
|
3
|
+
This file provides Ruby-specific examples related to the main [Quality Assurance Guide](../quality-assurance.g.md).
|
|
4
|
+
|
|
5
|
+
* **Linters/Formatters:** `rubocop`, `standardrb`
|
|
6
|
+
* **Static Analysis:** `brakeman` (Security), `reek` (Code Smells)
|
|
7
|
+
* **Test Coverage:** `simplecov`
|
|
8
|
+
* **CI Configuration:** Examples for GitHub Actions, GitLab CI, etc. using Ruby setup actions.
|
|
9
|
+
|
|
10
|
+
**Example `.standard.yml` (StandardRB config):**
|
|
11
|
+
|
|
12
|
+
```yaml
|
|
13
|
+
fix: true # default: false
|
|
14
|
+
parallel: true # default: false
|
|
15
|
+
format: progress # default: Standard::Formatter
|
|
16
|
+
ignore:
|
|
17
|
+
- 'db/schema.rb'
|
|
18
|
+
- 'vendor/**/*'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Example `simplecov` setup (in `spec/spec_helper.rb` or `test/test_helper.rb`):**
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
require 'simplecov'
|
|
25
|
+
SimpleCov.start do
|
|
26
|
+
add_filter '/spec/' # Ignore spec files themselves
|
|
27
|
+
add_filter '/vendor/'
|
|
28
|
+
# add_group 'Controllers', 'app/controllers'
|
|
29
|
+
# minimum_coverage 90
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Rest of spec_helper/test_helper
|
|
33
|
+
```
|