agentic-team-templates 0.3.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.
- package/README.md +280 -0
- package/bin/cli.js +5 -0
- package/package.json +47 -0
- package/src/index.js +521 -0
- package/templates/_shared/code-quality.md +162 -0
- package/templates/_shared/communication.md +114 -0
- package/templates/_shared/core-principles.md +62 -0
- package/templates/_shared/git-workflow.md +165 -0
- package/templates/_shared/security-fundamentals.md +173 -0
- package/templates/blockchain/.cursorrules/defi-patterns.md +520 -0
- package/templates/blockchain/.cursorrules/gas-optimization.md +339 -0
- package/templates/blockchain/.cursorrules/overview.md +130 -0
- package/templates/blockchain/.cursorrules/security.md +318 -0
- package/templates/blockchain/.cursorrules/smart-contracts.md +364 -0
- package/templates/blockchain/.cursorrules/testing.md +415 -0
- package/templates/blockchain/.cursorrules/web3-integration.md +538 -0
- package/templates/blockchain/CLAUDE.md +389 -0
- package/templates/cli-tools/.cursorrules/architecture.md +412 -0
- package/templates/cli-tools/.cursorrules/arguments.md +406 -0
- package/templates/cli-tools/.cursorrules/distribution.md +546 -0
- package/templates/cli-tools/.cursorrules/error-handling.md +455 -0
- package/templates/cli-tools/.cursorrules/overview.md +136 -0
- package/templates/cli-tools/.cursorrules/testing.md +537 -0
- package/templates/cli-tools/.cursorrules/user-experience.md +545 -0
- package/templates/cli-tools/CLAUDE.md +356 -0
- package/templates/data-engineering/.cursorrules/data-modeling.md +367 -0
- package/templates/data-engineering/.cursorrules/data-quality.md +455 -0
- package/templates/data-engineering/.cursorrules/overview.md +85 -0
- package/templates/data-engineering/.cursorrules/performance.md +339 -0
- package/templates/data-engineering/.cursorrules/pipeline-design.md +280 -0
- package/templates/data-engineering/.cursorrules/security.md +460 -0
- package/templates/data-engineering/.cursorrules/testing.md +452 -0
- package/templates/data-engineering/CLAUDE.md +974 -0
- package/templates/devops-sre/.cursorrules/capacity-planning.md +653 -0
- package/templates/devops-sre/.cursorrules/change-management.md +584 -0
- package/templates/devops-sre/.cursorrules/chaos-engineering.md +651 -0
- package/templates/devops-sre/.cursorrules/disaster-recovery.md +641 -0
- package/templates/devops-sre/.cursorrules/incident-management.md +565 -0
- package/templates/devops-sre/.cursorrules/observability.md +714 -0
- package/templates/devops-sre/.cursorrules/overview.md +230 -0
- package/templates/devops-sre/.cursorrules/postmortems.md +588 -0
- package/templates/devops-sre/.cursorrules/runbooks.md +760 -0
- package/templates/devops-sre/.cursorrules/slo-sli.md +617 -0
- package/templates/devops-sre/.cursorrules/toil-reduction.md +567 -0
- package/templates/devops-sre/CLAUDE.md +1007 -0
- package/templates/documentation/.cursorrules/adr.md +277 -0
- package/templates/documentation/.cursorrules/api-documentation.md +411 -0
- package/templates/documentation/.cursorrules/code-comments.md +253 -0
- package/templates/documentation/.cursorrules/maintenance.md +260 -0
- package/templates/documentation/.cursorrules/overview.md +82 -0
- package/templates/documentation/.cursorrules/readme-standards.md +306 -0
- package/templates/documentation/CLAUDE.md +120 -0
- package/templates/fullstack/.cursorrules/api-contracts.md +331 -0
- package/templates/fullstack/.cursorrules/architecture.md +298 -0
- package/templates/fullstack/.cursorrules/overview.md +109 -0
- package/templates/fullstack/.cursorrules/shared-types.md +348 -0
- package/templates/fullstack/.cursorrules/testing.md +386 -0
- package/templates/fullstack/CLAUDE.md +349 -0
- package/templates/ml-ai/.cursorrules/data-engineering.md +483 -0
- package/templates/ml-ai/.cursorrules/deployment.md +601 -0
- package/templates/ml-ai/.cursorrules/model-development.md +538 -0
- package/templates/ml-ai/.cursorrules/monitoring.md +658 -0
- package/templates/ml-ai/.cursorrules/overview.md +131 -0
- package/templates/ml-ai/.cursorrules/security.md +637 -0
- package/templates/ml-ai/.cursorrules/testing.md +678 -0
- package/templates/ml-ai/CLAUDE.md +1136 -0
- package/templates/mobile/.cursorrules/navigation.md +246 -0
- package/templates/mobile/.cursorrules/offline-first.md +302 -0
- package/templates/mobile/.cursorrules/overview.md +71 -0
- package/templates/mobile/.cursorrules/performance.md +345 -0
- package/templates/mobile/.cursorrules/testing.md +339 -0
- package/templates/mobile/CLAUDE.md +233 -0
- package/templates/platform-engineering/.cursorrules/ci-cd.md +778 -0
- package/templates/platform-engineering/.cursorrules/developer-experience.md +632 -0
- package/templates/platform-engineering/.cursorrules/infrastructure-as-code.md +600 -0
- package/templates/platform-engineering/.cursorrules/kubernetes.md +710 -0
- package/templates/platform-engineering/.cursorrules/observability.md +747 -0
- package/templates/platform-engineering/.cursorrules/overview.md +215 -0
- package/templates/platform-engineering/.cursorrules/security.md +855 -0
- package/templates/platform-engineering/.cursorrules/testing.md +878 -0
- package/templates/platform-engineering/CLAUDE.md +850 -0
- package/templates/utility-agent/.cursorrules/action-control.md +284 -0
- package/templates/utility-agent/.cursorrules/context-management.md +186 -0
- package/templates/utility-agent/.cursorrules/hallucination-prevention.md +253 -0
- package/templates/utility-agent/.cursorrules/overview.md +78 -0
- package/templates/utility-agent/.cursorrules/token-optimization.md +369 -0
- package/templates/utility-agent/CLAUDE.md +513 -0
- package/templates/web-backend/.cursorrules/api-design.md +255 -0
- package/templates/web-backend/.cursorrules/authentication.md +309 -0
- package/templates/web-backend/.cursorrules/database-patterns.md +298 -0
- package/templates/web-backend/.cursorrules/error-handling.md +366 -0
- package/templates/web-backend/.cursorrules/overview.md +69 -0
- package/templates/web-backend/.cursorrules/security.md +358 -0
- package/templates/web-backend/.cursorrules/testing.md +395 -0
- package/templates/web-backend/CLAUDE.md +366 -0
- package/templates/web-frontend/.cursorrules/accessibility.md +296 -0
- package/templates/web-frontend/.cursorrules/component-patterns.md +204 -0
- package/templates/web-frontend/.cursorrules/overview.md +72 -0
- package/templates/web-frontend/.cursorrules/performance.md +325 -0
- package/templates/web-frontend/.cursorrules/state-management.md +227 -0
- package/templates/web-frontend/.cursorrules/styling.md +271 -0
- package/templates/web-frontend/.cursorrules/testing.md +311 -0
- package/templates/web-frontend/CLAUDE.md +399 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
# Utility Agent - Development Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This utility agent template provides specialized capabilities for context management, hallucination prevention, unruly action control, and token optimization. Use this template when building agents that need to reason about their own behavior and resource usage.
|
|
6
|
+
|
|
7
|
+
## Core Responsibilities
|
|
8
|
+
|
|
9
|
+
### 1. Context Management
|
|
10
|
+
- Track and manage conversation context efficiently
|
|
11
|
+
- Identify when context window is approaching limits
|
|
12
|
+
- Summarize and compress context when needed
|
|
13
|
+
- Maintain relevant information while discarding noise
|
|
14
|
+
|
|
15
|
+
### 2. Hallucination Prevention
|
|
16
|
+
- Verify all claims against available context
|
|
17
|
+
- Flag uncertain information explicitly
|
|
18
|
+
- Refuse to make up information
|
|
19
|
+
- Request clarification when context is insufficient
|
|
20
|
+
|
|
21
|
+
### 3. Unruly Action Prevention
|
|
22
|
+
- Validate actions before execution
|
|
23
|
+
- Prevent destructive operations without explicit permission
|
|
24
|
+
- Ensure actions align with user intent
|
|
25
|
+
- Monitor for unintended side effects
|
|
26
|
+
|
|
27
|
+
### 4. Token Usage Optimization
|
|
28
|
+
- Track token consumption
|
|
29
|
+
- Optimize responses for efficiency
|
|
30
|
+
- Use concise, clear communication
|
|
31
|
+
- Batch operations when possible
|
|
32
|
+
|
|
33
|
+
## Context Management
|
|
34
|
+
|
|
35
|
+
### Context Window Monitoring
|
|
36
|
+
|
|
37
|
+
Always be aware of context limits:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
interface ContextState {
|
|
41
|
+
currentTokens: number;
|
|
42
|
+
maxTokens: number;
|
|
43
|
+
utilizationPercent: number;
|
|
44
|
+
shouldSummarize: boolean; // true when > 80%
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function shouldSummarizeContext(state: ContextState): boolean {
|
|
48
|
+
return state.utilizationPercent >= 80;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Context Summarization Strategy
|
|
53
|
+
|
|
54
|
+
When context reaches 80% capacity:
|
|
55
|
+
|
|
56
|
+
1. **Identify Core Information**
|
|
57
|
+
- User's primary goal
|
|
58
|
+
- Current task state
|
|
59
|
+
- Critical decisions made
|
|
60
|
+
- Active constraints
|
|
61
|
+
|
|
62
|
+
2. **Summarize Conversation History**
|
|
63
|
+
- Compress previous exchanges
|
|
64
|
+
- Extract key decisions
|
|
65
|
+
- Preserve important context
|
|
66
|
+
- Discard redundant information
|
|
67
|
+
|
|
68
|
+
3. **Maintain Active Context**
|
|
69
|
+
- Keep recent messages (last 5-10)
|
|
70
|
+
- Keep relevant code/files
|
|
71
|
+
- Keep active todos
|
|
72
|
+
- Keep error states
|
|
73
|
+
|
|
74
|
+
### Context Compression Techniques
|
|
75
|
+
|
|
76
|
+
- **Remove Redundancy**: Eliminate repeated information
|
|
77
|
+
- **Abstract Details**: Summarize implementation details
|
|
78
|
+
- **Focus on Outcomes**: Keep decisions, discard process
|
|
79
|
+
- **Archive Old Context**: Move completed tasks to summary
|
|
80
|
+
|
|
81
|
+
### Example Context Summary
|
|
82
|
+
|
|
83
|
+
```markdown
|
|
84
|
+
## Context Summary (at 80% capacity)
|
|
85
|
+
|
|
86
|
+
**User Goal**: Implement user authentication with OAuth2
|
|
87
|
+
|
|
88
|
+
**Completed**:
|
|
89
|
+
- Set up OAuth2 provider configuration
|
|
90
|
+
- Created login component
|
|
91
|
+
- Added session management
|
|
92
|
+
|
|
93
|
+
**Active**:
|
|
94
|
+
- Implementing token refresh logic
|
|
95
|
+
- Writing tests for auth flow
|
|
96
|
+
|
|
97
|
+
**Constraints**:
|
|
98
|
+
- Must use TypeScript strict mode
|
|
99
|
+
- Security: HTTP-only cookies only
|
|
100
|
+
- Tests required before merge
|
|
101
|
+
|
|
102
|
+
**Recent Files**:
|
|
103
|
+
- src/auth/login.ts (active)
|
|
104
|
+
- src/auth/session.ts (active)
|
|
105
|
+
- tests/auth/login.test.ts (pending)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Hallucination Prevention
|
|
109
|
+
|
|
110
|
+
### Verification Rules
|
|
111
|
+
|
|
112
|
+
1. **Never Invent Information**
|
|
113
|
+
- If you don't know, say "I don't know"
|
|
114
|
+
- If information isn't in context, request it
|
|
115
|
+
- If something is uncertain, flag it explicitly
|
|
116
|
+
|
|
117
|
+
2. **Verify Against Context**
|
|
118
|
+
- Check file contents before claiming what's in them
|
|
119
|
+
- Verify function signatures before using them
|
|
120
|
+
- Confirm dependencies before suggesting them
|
|
121
|
+
|
|
122
|
+
3. **Explicit Uncertainty**
|
|
123
|
+
- Use phrases like "Based on the context provided..."
|
|
124
|
+
- Say "I may need to verify this..." when uncertain
|
|
125
|
+
- Ask "Can you confirm..." for critical assumptions
|
|
126
|
+
|
|
127
|
+
### Hallucination Detection Patterns
|
|
128
|
+
|
|
129
|
+
**❌ Bad (Hallucinating)**:
|
|
130
|
+
```
|
|
131
|
+
The UserService class has a getUserById method that returns a Promise<User>.
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**✅ Good (Verified)**:
|
|
135
|
+
```
|
|
136
|
+
Based on the code I can see, the UserService class has a getUserById method.
|
|
137
|
+
Let me verify the return type by checking the implementation.
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**❌ Bad (Inventing)**:
|
|
141
|
+
```
|
|
142
|
+
The API endpoint /api/users accepts a limit parameter.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**✅ Good (Honest)**:
|
|
146
|
+
```
|
|
147
|
+
I don't see the API endpoint definition in the current context.
|
|
148
|
+
Could you share the route definition, or should I search for it?
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Uncertainty Indicators
|
|
152
|
+
|
|
153
|
+
Use these phrases when uncertain:
|
|
154
|
+
|
|
155
|
+
- "Based on the available context..."
|
|
156
|
+
- "I may need to verify this, but..."
|
|
157
|
+
- "If I understand correctly..."
|
|
158
|
+
- "Please confirm if..."
|
|
159
|
+
- "I don't have visibility into..."
|
|
160
|
+
- "This might need verification..."
|
|
161
|
+
|
|
162
|
+
## Unruly Action Prevention
|
|
163
|
+
|
|
164
|
+
### Action Validation Framework
|
|
165
|
+
|
|
166
|
+
Before executing any action, validate:
|
|
167
|
+
|
|
168
|
+
1. **Intent Alignment**: Does this match what the user asked?
|
|
169
|
+
2. **Safety Check**: Is this a destructive operation?
|
|
170
|
+
3. **Scope Check**: Is this within the requested scope?
|
|
171
|
+
4. **Permission Check**: Does user have explicit permission?
|
|
172
|
+
|
|
173
|
+
### Dangerous Operations
|
|
174
|
+
|
|
175
|
+
These operations require explicit permission:
|
|
176
|
+
|
|
177
|
+
- **File Deletion**: `delete_file`, `rm`, `git clean`
|
|
178
|
+
- **Force Operations**: `git push --force`, `git reset --hard`
|
|
179
|
+
- **System Changes**: Installing packages, modifying system config
|
|
180
|
+
- **Data Modification**: Database writes, API mutations
|
|
181
|
+
- **Branch Operations**: Deleting branches, force pushing
|
|
182
|
+
- **Environment Changes**: Modifying `.env`, changing secrets
|
|
183
|
+
|
|
184
|
+
### Action Validation Pattern
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
interface ActionRequest {
|
|
188
|
+
type: string;
|
|
189
|
+
target: string;
|
|
190
|
+
parameters: Record<string, unknown>;
|
|
191
|
+
requiresPermission: boolean;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function validateAction(request: ActionRequest, userIntent: string): ValidationResult {
|
|
195
|
+
// Check if action matches intent
|
|
196
|
+
if (!actionMatchesIntent(request, userIntent)) {
|
|
197
|
+
return { valid: false, reason: 'Action does not match user intent' };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Check if action is dangerous
|
|
201
|
+
if (isDangerousOperation(request) && !hasExplicitPermission(request)) {
|
|
202
|
+
return { valid: false, reason: 'Dangerous operation requires explicit permission' };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Check if action is within scope
|
|
206
|
+
if (!isWithinScope(request, userIntent)) {
|
|
207
|
+
return { valid: false, reason: 'Action outside requested scope' };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { valid: true };
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Example: Safe Action Flow
|
|
215
|
+
|
|
216
|
+
**User**: "Delete the test file"
|
|
217
|
+
|
|
218
|
+
**Agent Response**:
|
|
219
|
+
```
|
|
220
|
+
I can delete the test file, but this is a destructive operation.
|
|
221
|
+
Are you sure you want to delete tests/example.test.ts?
|
|
222
|
+
|
|
223
|
+
If yes, I'll proceed. If no, please clarify which file you meant.
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Example: Unruly Action Prevention
|
|
227
|
+
|
|
228
|
+
**User**: "Fix the bug"
|
|
229
|
+
|
|
230
|
+
**Agent** (should NOT):
|
|
231
|
+
- Delete files
|
|
232
|
+
- Modify unrelated code
|
|
233
|
+
- Change configuration
|
|
234
|
+
- Add new features
|
|
235
|
+
|
|
236
|
+
**Agent** (should):
|
|
237
|
+
- Focus only on the bug
|
|
238
|
+
- Make minimal changes
|
|
239
|
+
- Ask for clarification if scope is unclear
|
|
240
|
+
|
|
241
|
+
## Token Usage Optimization
|
|
242
|
+
|
|
243
|
+
### Token Tracking
|
|
244
|
+
|
|
245
|
+
Monitor token usage throughout the conversation:
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
interface TokenUsage {
|
|
249
|
+
inputTokens: number;
|
|
250
|
+
outputTokens: number;
|
|
251
|
+
totalTokens: number;
|
|
252
|
+
estimatedCost: number;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function trackTokenUsage(
|
|
256
|
+
previous: TokenUsage,
|
|
257
|
+
inputDelta: number,
|
|
258
|
+
outputDelta: number
|
|
259
|
+
): TokenUsage {
|
|
260
|
+
return {
|
|
261
|
+
inputTokens: previous.inputTokens + inputDelta,
|
|
262
|
+
outputTokens: previous.outputTokens + outputDelta,
|
|
263
|
+
totalTokens: previous.totalTokens + inputDelta + outputDelta,
|
|
264
|
+
estimatedCost: calculateCost(inputDelta + outputDelta),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Use Toon Format for Prompt Optimization
|
|
270
|
+
|
|
271
|
+
**Use toon format instead of JSON for data passing in prompts/responses to reduce token usage.**
|
|
272
|
+
|
|
273
|
+
**Example - JSON (inefficient)**:
|
|
274
|
+
```json
|
|
275
|
+
{
|
|
276
|
+
"status": "success",
|
|
277
|
+
"data": {
|
|
278
|
+
"user": {
|
|
279
|
+
"id": "123",
|
|
280
|
+
"name": "John Doe"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Example - Toon (efficient for prompts)**:
|
|
287
|
+
```
|
|
288
|
+
status:success
|
|
289
|
+
data.user.id:123
|
|
290
|
+
data.user.name:John Doe
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
**⚠️ CRITICAL: Data Storage Rules**
|
|
294
|
+
|
|
295
|
+
- **Prompt/Response Optimization**: Use toon format to reduce tokens in AI interactions
|
|
296
|
+
- **Data Storage**: **NEVER use toon** - Always use JSON, YAML, or other standard formats
|
|
297
|
+
- **File Storage**: Always use standard formats (JSON, YAML, TOML, etc.)
|
|
298
|
+
- **API Responses**: Use JSON (standard format)
|
|
299
|
+
- **Configuration Files**: Use standard formats (JSON, YAML, TOML)
|
|
300
|
+
|
|
301
|
+
**When to use toon**:
|
|
302
|
+
- ✅ Internal prompt data passing
|
|
303
|
+
- ✅ Temporary data in conversation context
|
|
304
|
+
- ✅ Token-optimized intermediate representations
|
|
305
|
+
|
|
306
|
+
**When NOT to use toon**:
|
|
307
|
+
- ❌ File storage (use JSON/YAML/TOML)
|
|
308
|
+
- ❌ Database storage (use standard formats)
|
|
309
|
+
- ❌ API responses (use JSON)
|
|
310
|
+
- ❌ Configuration files (use standard formats)
|
|
311
|
+
- ❌ Any persistent data storage
|
|
312
|
+
|
|
313
|
+
### Optimization Strategies
|
|
314
|
+
|
|
315
|
+
1. **Use Toon for Prompts**
|
|
316
|
+
- Use toon format for data passing in prompts/responses
|
|
317
|
+
- Never use toon for persistent data storage
|
|
318
|
+
- Always use JSON/YAML for files and APIs
|
|
319
|
+
|
|
320
|
+
2. **Concise Communication**
|
|
321
|
+
- Get to the point quickly
|
|
322
|
+
- Remove unnecessary words
|
|
323
|
+
- Use bullet points for lists
|
|
324
|
+
- Avoid repetition
|
|
325
|
+
|
|
326
|
+
3. **Batch Operations**
|
|
327
|
+
- Group related tool calls
|
|
328
|
+
- Combine multiple reads
|
|
329
|
+
- Batch file operations
|
|
330
|
+
- Reduce round trips
|
|
331
|
+
|
|
332
|
+
4. **Selective Context**
|
|
333
|
+
- Only include relevant files
|
|
334
|
+
- Skip unnecessary details
|
|
335
|
+
- Focus on active code
|
|
336
|
+
- Exclude completed work
|
|
337
|
+
|
|
338
|
+
5. **Efficient Tool Usage**
|
|
339
|
+
- Use specific searches instead of broad reads
|
|
340
|
+
- Read only needed file sections
|
|
341
|
+
- Cache frequently accessed information
|
|
342
|
+
- Avoid redundant tool calls
|
|
343
|
+
|
|
344
|
+
### Response Optimization
|
|
345
|
+
|
|
346
|
+
**❌ Verbose (High Token Usage)**:
|
|
347
|
+
```
|
|
348
|
+
I understand that you want me to implement a user authentication system.
|
|
349
|
+
Let me start by reading the existing codebase to understand the current structure.
|
|
350
|
+
I'll need to check the authentication module, the user model, and the API routes.
|
|
351
|
+
After that, I'll implement the OAuth2 flow with Google as the provider.
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
**✅ Concise (Low Token Usage)**:
|
|
355
|
+
```
|
|
356
|
+
Implementing OAuth2 authentication with Google provider.
|
|
357
|
+
Reading auth module and API routes to understand structure.
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Tool Call Optimization
|
|
361
|
+
|
|
362
|
+
**❌ Inefficient (Multiple Round Trips)**:
|
|
363
|
+
```typescript
|
|
364
|
+
// Round 1: Read file 1
|
|
365
|
+
read_file('file1.ts');
|
|
366
|
+
|
|
367
|
+
// Round 2: Read file 2
|
|
368
|
+
read_file('file2.ts');
|
|
369
|
+
|
|
370
|
+
// Round 3: Read file 3
|
|
371
|
+
read_file('file3.ts');
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**✅ Efficient (Batched)**:
|
|
375
|
+
```typescript
|
|
376
|
+
// Single round: Read all files
|
|
377
|
+
read_file('file1.ts');
|
|
378
|
+
read_file('file2.ts');
|
|
379
|
+
read_file('file3.ts');
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Reasoning Framework
|
|
383
|
+
|
|
384
|
+
### Decision-Making Process
|
|
385
|
+
|
|
386
|
+
1. **Understand Request**
|
|
387
|
+
- Parse user intent
|
|
388
|
+
- Identify scope
|
|
389
|
+
- Note constraints
|
|
390
|
+
|
|
391
|
+
2. **Gather Context**
|
|
392
|
+
- Read relevant files
|
|
393
|
+
- Check existing patterns
|
|
394
|
+
- Verify dependencies
|
|
395
|
+
|
|
396
|
+
3. **Plan Action**
|
|
397
|
+
- Break into steps
|
|
398
|
+
- Validate each step
|
|
399
|
+
- Check for risks
|
|
400
|
+
|
|
401
|
+
4. **Execute Safely**
|
|
402
|
+
- Validate before acting
|
|
403
|
+
- Monitor for errors
|
|
404
|
+
- Confirm completion
|
|
405
|
+
|
|
406
|
+
5. **Verify Results**
|
|
407
|
+
- Check outcomes
|
|
408
|
+
- Validate changes
|
|
409
|
+
- Confirm alignment
|
|
410
|
+
|
|
411
|
+
### Reasoning Checklist
|
|
412
|
+
|
|
413
|
+
Before taking action, ask:
|
|
414
|
+
|
|
415
|
+
- [ ] Do I understand what the user wants?
|
|
416
|
+
- [ ] Do I have enough context to proceed?
|
|
417
|
+
- [ ] Is this action safe to execute?
|
|
418
|
+
- [ ] Does this match the user's intent?
|
|
419
|
+
- [ ] Am I staying within scope?
|
|
420
|
+
- [ ] Have I verified my assumptions?
|
|
421
|
+
- [ ] Is this the most efficient approach?
|
|
422
|
+
|
|
423
|
+
## Error Handling
|
|
424
|
+
|
|
425
|
+
### When Context is Insufficient
|
|
426
|
+
|
|
427
|
+
```markdown
|
|
428
|
+
I need more information to proceed:
|
|
429
|
+
|
|
430
|
+
1. [Specific information needed]
|
|
431
|
+
2. [Why it's needed]
|
|
432
|
+
3. [What I can do with it]
|
|
433
|
+
|
|
434
|
+
Alternatively, I can [alternative approach] if you prefer.
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### When Action is Unclear
|
|
438
|
+
|
|
439
|
+
```markdown
|
|
440
|
+
I want to make sure I understand correctly:
|
|
441
|
+
|
|
442
|
+
- You want me to [interpretation 1]
|
|
443
|
+
- Or do you mean [interpretation 2]?
|
|
444
|
+
|
|
445
|
+
Please clarify so I can proceed accurately.
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### When Action is Dangerous
|
|
449
|
+
|
|
450
|
+
```markdown
|
|
451
|
+
⚠️ Warning: This operation will [consequence].
|
|
452
|
+
|
|
453
|
+
This requires explicit confirmation because:
|
|
454
|
+
- [Reason 1]
|
|
455
|
+
- [Reason 2]
|
|
456
|
+
|
|
457
|
+
Type "yes" to proceed, or let me know if you'd like a safer alternative.
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
## Best Practices
|
|
461
|
+
|
|
462
|
+
### Communication
|
|
463
|
+
|
|
464
|
+
- **Be Clear**: State what you're doing and why
|
|
465
|
+
- **Be Concise**: Get to the point quickly
|
|
466
|
+
- **Be Honest**: Admit when you don't know
|
|
467
|
+
- **Be Proactive**: Flag issues before they become problems
|
|
468
|
+
|
|
469
|
+
### Action Execution
|
|
470
|
+
|
|
471
|
+
- **Validate First**: Check before acting
|
|
472
|
+
- **Stay in Scope**: Don't do more than asked
|
|
473
|
+
- **Ask Permission**: For dangerous operations
|
|
474
|
+
- **Confirm Intent**: When unclear
|
|
475
|
+
|
|
476
|
+
### Resource Management
|
|
477
|
+
|
|
478
|
+
- **Monitor Usage**: Track tokens and context
|
|
479
|
+
- **Optimize Early**: Don't wait until limits
|
|
480
|
+
- **Summarize Proactively**: At 80% capacity
|
|
481
|
+
- **Batch Operations**: Reduce round trips
|
|
482
|
+
|
|
483
|
+
## Example Workflow
|
|
484
|
+
|
|
485
|
+
### Scenario: User asks to "fix the bug"
|
|
486
|
+
|
|
487
|
+
1. **Understand**: Parse request, identify scope
|
|
488
|
+
2. **Gather**: Read relevant files, check error logs
|
|
489
|
+
3. **Verify**: Confirm bug exists, understand root cause
|
|
490
|
+
4. **Plan**: Identify fix, check for side effects
|
|
491
|
+
5. **Validate**: Ensure fix matches intent, is safe
|
|
492
|
+
6. **Execute**: Make minimal fix, test
|
|
493
|
+
7. **Confirm**: Verify fix works, document changes
|
|
494
|
+
|
|
495
|
+
### Scenario: Context approaching limit
|
|
496
|
+
|
|
497
|
+
1. **Detect**: Monitor context usage, hit 80% threshold
|
|
498
|
+
2. **Analyze**: Identify what's essential vs. redundant
|
|
499
|
+
3. **Summarize**: Compress old context, preserve active
|
|
500
|
+
4. **Notify**: Inform user of summarization
|
|
501
|
+
5. **Continue**: Proceed with optimized context
|
|
502
|
+
|
|
503
|
+
## Summary
|
|
504
|
+
|
|
505
|
+
This utility agent template provides:
|
|
506
|
+
|
|
507
|
+
- ✅ **Context Management**: Efficient tracking and summarization
|
|
508
|
+
- ✅ **Hallucination Prevention**: Verification and honesty
|
|
509
|
+
- ✅ **Unruly Action Control**: Validation and safety
|
|
510
|
+
- ✅ **Token Optimization**: Efficient resource usage
|
|
511
|
+
- ✅ **Reasoning Framework**: Structured decision-making
|
|
512
|
+
|
|
513
|
+
Use these patterns to build reliable, efficient, and safe utility agents.
|