maestro-bundle 1.3.1 → 1.5.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 +19 -6
- package/package.json +1 -1
- package/src/cli.mjs +12 -1
- package/templates/bundle-ai-agents/AGENTS.md +6 -0
- package/templates/bundle-ai-agents/PRD_TEMPLATE.md +161 -0
- package/templates/bundle-ai-agents/skills/agent-orchestration/SKILL.md +107 -41
- package/templates/bundle-ai-agents/skills/agent-orchestration/references/graph-patterns.md +50 -0
- package/templates/bundle-ai-agents/skills/agent-orchestration/references/routing-strategies.md +47 -0
- package/templates/bundle-ai-agents/skills/api-design/SKILL.md +125 -16
- package/templates/bundle-ai-agents/skills/api-design/references/pydantic-patterns.md +72 -0
- package/templates/bundle-ai-agents/skills/api-design/references/rest-conventions.md +51 -0
- package/templates/bundle-ai-agents/skills/clean-architecture/SKILL.md +113 -21
- package/templates/bundle-ai-agents/skills/clean-architecture/references/dependency-injection.md +60 -0
- package/templates/bundle-ai-agents/skills/clean-architecture/references/layer-rules.md +56 -0
- package/templates/bundle-ai-agents/skills/context-engineering/SKILL.md +104 -36
- package/templates/bundle-ai-agents/skills/context-engineering/references/compression-techniques.md +76 -0
- package/templates/bundle-ai-agents/skills/context-engineering/references/context-budget-calculator.md +45 -0
- package/templates/bundle-ai-agents/skills/database-modeling/SKILL.md +146 -19
- package/templates/bundle-ai-agents/skills/database-modeling/references/index-strategies.md +48 -0
- package/templates/bundle-ai-agents/skills/database-modeling/references/naming-conventions.md +27 -0
- package/templates/bundle-ai-agents/skills/docker-containerization/SKILL.md +124 -15
- package/templates/bundle-ai-agents/skills/docker-containerization/references/compose-patterns.md +97 -0
- package/templates/bundle-ai-agents/skills/docker-containerization/references/dockerfile-checklist.md +37 -0
- package/templates/bundle-ai-agents/skills/eval-testing/SKILL.md +113 -25
- package/templates/bundle-ai-agents/skills/eval-testing/references/eval-types.md +52 -0
- package/templates/bundle-ai-agents/skills/eval-testing/references/golden-dataset-template.md +59 -0
- package/templates/bundle-ai-agents/skills/memory-management/SKILL.md +112 -28
- package/templates/bundle-ai-agents/skills/memory-management/references/memory-tiers.md +41 -0
- package/templates/bundle-ai-agents/skills/memory-management/references/namespace-conventions.md +41 -0
- package/templates/bundle-ai-agents/skills/prompt-engineering/SKILL.md +139 -47
- package/templates/bundle-ai-agents/skills/prompt-engineering/references/anti-patterns.md +59 -0
- package/templates/bundle-ai-agents/skills/prompt-engineering/references/prompt-templates.md +75 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/SKILL.md +104 -27
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/chunking-strategies.md +27 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/embedding-models.md +31 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/rag-evaluation.md +39 -0
- package/templates/bundle-ai-agents/skills/testing-strategy/SKILL.md +127 -18
- package/templates/bundle-ai-agents/skills/testing-strategy/references/fixture-patterns.md +81 -0
- package/templates/bundle-ai-agents/skills/testing-strategy/references/naming-conventions.md +69 -0
- package/templates/bundle-base/skills/branch-strategy/SKILL.md +134 -21
- package/templates/bundle-base/skills/branch-strategy/references/branch-rules.md +40 -0
- package/templates/bundle-base/skills/code-review/SKILL.md +123 -38
- package/templates/bundle-base/skills/code-review/references/review-checklist.md +45 -0
- package/templates/bundle-base/skills/commit-pattern/SKILL.md +98 -39
- package/templates/bundle-base/skills/commit-pattern/references/conventional-commits.md +40 -0
- package/templates/bundle-data-pipeline/AGENTS.md +6 -0
- package/templates/bundle-data-pipeline/PRD_TEMPLATE.md +161 -0
- package/templates/bundle-data-pipeline/skills/data-preprocessing/SKILL.md +110 -19
- package/templates/bundle-data-pipeline/skills/data-preprocessing/references/pandas-cheatsheet.md +63 -0
- package/templates/bundle-data-pipeline/skills/data-preprocessing/references/pandera-schemas.md +44 -0
- package/templates/bundle-data-pipeline/skills/docker-containerization/SKILL.md +132 -16
- package/templates/bundle-data-pipeline/skills/docker-containerization/references/compose-patterns.md +82 -0
- package/templates/bundle-data-pipeline/skills/docker-containerization/references/dockerfile-best-practices.md +57 -0
- package/templates/bundle-data-pipeline/skills/feature-engineering/SKILL.md +143 -45
- package/templates/bundle-data-pipeline/skills/feature-engineering/references/encoding-guide.md +41 -0
- package/templates/bundle-data-pipeline/skills/feature-engineering/references/scaling-guide.md +38 -0
- package/templates/bundle-data-pipeline/skills/mlops-pipeline/SKILL.md +156 -37
- package/templates/bundle-data-pipeline/skills/mlops-pipeline/references/mlflow-commands.md +69 -0
- package/templates/bundle-data-pipeline/skills/model-training/SKILL.md +152 -33
- package/templates/bundle-data-pipeline/skills/model-training/references/evaluation-metrics.md +52 -0
- package/templates/bundle-data-pipeline/skills/model-training/references/model-selection-guide.md +41 -0
- package/templates/bundle-data-pipeline/skills/rag-pipeline/SKILL.md +127 -39
- package/templates/bundle-data-pipeline/skills/rag-pipeline/references/chunking-strategies.md +51 -0
- package/templates/bundle-data-pipeline/skills/rag-pipeline/references/embedding-models.md +49 -0
- package/templates/bundle-frontend-spa/AGENTS.md +6 -0
- package/templates/bundle-frontend-spa/PRD_TEMPLATE.md +161 -0
- package/templates/bundle-frontend-spa/skills/authentication/SKILL.md +196 -13
- package/templates/bundle-frontend-spa/skills/authentication/references/jwt-security.md +41 -0
- package/templates/bundle-frontend-spa/skills/component-design/SKILL.md +191 -41
- package/templates/bundle-frontend-spa/skills/component-design/references/accessibility-checklist.md +41 -0
- package/templates/bundle-frontend-spa/skills/component-design/references/tailwind-patterns.md +65 -0
- package/templates/bundle-frontend-spa/skills/e2e-testing/SKILL.md +241 -79
- package/templates/bundle-frontend-spa/skills/e2e-testing/references/playwright-selectors.md +66 -0
- package/templates/bundle-frontend-spa/skills/e2e-testing/references/test-patterns.md +82 -0
- package/templates/bundle-frontend-spa/skills/integration-api/SKILL.md +221 -31
- package/templates/bundle-frontend-spa/skills/integration-api/references/api-patterns.md +81 -0
- package/templates/bundle-frontend-spa/skills/react-patterns/SKILL.md +195 -70
- package/templates/bundle-frontend-spa/skills/react-patterns/references/component-checklist.md +22 -0
- package/templates/bundle-frontend-spa/skills/react-patterns/references/hook-patterns.md +63 -0
- package/templates/bundle-frontend-spa/skills/responsive-layout/SKILL.md +162 -22
- package/templates/bundle-frontend-spa/skills/responsive-layout/references/breakpoint-guide.md +63 -0
- package/templates/bundle-frontend-spa/skills/state-management/SKILL.md +158 -30
- package/templates/bundle-frontend-spa/skills/state-management/references/react-query-config.md +64 -0
- package/templates/bundle-frontend-spa/skills/state-management/references/state-patterns.md +78 -0
- package/templates/bundle-jhipster-microservices/AGENTS.md +6 -0
- package/templates/bundle-jhipster-microservices/PRD_TEMPLATE.md +161 -0
- package/templates/bundle-jhipster-microservices/skills/ci-cd-pipeline/SKILL.md +135 -45
- package/templates/bundle-jhipster-microservices/skills/ci-cd-pipeline/references/gitlab-ci-templates.md +93 -0
- package/templates/bundle-jhipster-microservices/skills/clean-architecture/SKILL.md +87 -21
- package/templates/bundle-jhipster-microservices/skills/clean-architecture/references/layer-rules.md +78 -0
- package/templates/bundle-jhipster-microservices/skills/ddd-tactical/SKILL.md +94 -25
- package/templates/bundle-jhipster-microservices/skills/ddd-tactical/references/ddd-patterns.md +48 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/SKILL.md +63 -21
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/references/angular-microservices.md +40 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/references/angular-structure.md +59 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-docker-k8s/SKILL.md +125 -91
- package/templates/bundle-jhipster-microservices/skills/jhipster-docker-k8s/references/docker-k8s-commands.md +68 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/SKILL.md +72 -20
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/references/cross-service-entities.md +36 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/references/jdl-types.md +56 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-gateway/SKILL.md +80 -8
- package/templates/bundle-jhipster-microservices/skills/jhipster-gateway/references/gateway-config.md +43 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-kafka/SKILL.md +115 -22
- package/templates/bundle-jhipster-microservices/skills/jhipster-kafka/references/kafka-events.md +39 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-registry/SKILL.md +92 -23
- package/templates/bundle-jhipster-microservices/skills/jhipster-registry/references/consul-config.md +61 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-service/SKILL.md +81 -18
- package/templates/bundle-jhipster-microservices/skills/jhipster-service/references/service-patterns.md +40 -0
- package/templates/bundle-jhipster-microservices/skills/testing-strategy/SKILL.md +101 -20
- package/templates/bundle-jhipster-microservices/skills/testing-strategy/references/test-naming.md +55 -0
- package/templates/bundle-jhipster-monorepo/AGENTS.md +6 -0
- package/templates/bundle-jhipster-monorepo/PRD_TEMPLATE.md +161 -0
- package/templates/bundle-jhipster-monorepo/skills/clean-architecture/SKILL.md +87 -21
- package/templates/bundle-jhipster-monorepo/skills/clean-architecture/references/layer-rules.md +78 -0
- package/templates/bundle-jhipster-monorepo/skills/ddd-tactical/SKILL.md +94 -25
- package/templates/bundle-jhipster-monorepo/skills/ddd-tactical/references/ddd-patterns.md +48 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-angular/SKILL.md +99 -52
- package/templates/bundle-jhipster-monorepo/skills/jhipster-angular/references/angular-structure.md +59 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-entities/SKILL.md +89 -36
- package/templates/bundle-jhipster-monorepo/skills/jhipster-entities/references/jdl-types.md +56 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-liquibase/SKILL.md +123 -23
- package/templates/bundle-jhipster-monorepo/skills/jhipster-liquibase/references/liquibase-operations.md +95 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-security/SKILL.md +106 -19
- package/templates/bundle-jhipster-monorepo/skills/jhipster-security/references/security-checklist.md +47 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-spring/SKILL.md +84 -16
- package/templates/bundle-jhipster-monorepo/skills/jhipster-spring/references/spring-layers.md +41 -0
- package/templates/bundle-jhipster-monorepo/skills/testing-strategy/SKILL.md +101 -20
- package/templates/bundle-jhipster-monorepo/skills/testing-strategy/references/test-naming.md +55 -0
|
@@ -1,78 +1,112 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: memory-management
|
|
3
|
-
description:
|
|
3
|
+
description: Implement short-term, medium-term, and long-term memory for AI agents using LangGraph Store and checkpointers. Use when agents need to remember past interactions, persist state, or learn from previous executions.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
|
-
#
|
|
8
|
+
# Memory Management
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Implement three tiers of agent memory -- short-term (context window), medium-term (checkpointer), and long-term (store) -- to enable persistent learning and state management.
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
## When to Use
|
|
13
|
+
- Agent needs to resume work after interruption
|
|
14
|
+
- Agent should learn from past executions and avoid repeating mistakes
|
|
15
|
+
- Persisting state between nodes in a LangGraph workflow
|
|
16
|
+
- Storing and retrieving patterns learned across multiple demands
|
|
17
|
+
- Implementing memory decay to remove stale or low-confidence knowledge
|
|
15
18
|
|
|
16
|
-
##
|
|
19
|
+
## Available Operations
|
|
20
|
+
1. Configure short-term memory via context window
|
|
21
|
+
2. Set up medium-term memory with LangGraph checkpointer
|
|
22
|
+
3. Implement long-term memory with LangGraph Store
|
|
23
|
+
4. Integrate memory into Deep Agent configuration
|
|
24
|
+
5. Implement memory cleanup and decay policies
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
## Multi-Step Workflow
|
|
27
|
+
|
|
28
|
+
### Step 1: Set Up Short-Term Memory (Context Window)
|
|
29
|
+
|
|
30
|
+
Short-term memory is automatic -- LangGraph accumulates messages within a session.
|
|
19
31
|
|
|
20
32
|
```python
|
|
33
|
+
from typing import TypedDict, Annotated
|
|
34
|
+
from langgraph.graph.message import add_messages
|
|
35
|
+
|
|
21
36
|
class AgentState(TypedDict):
|
|
22
|
-
messages: Annotated[list, add_messages] #
|
|
37
|
+
messages: Annotated[list, add_messages] # Accumulates automatically
|
|
23
38
|
```
|
|
24
39
|
|
|
25
|
-
|
|
40
|
+
No additional setup needed. Messages persist for the duration of a single invocation chain.
|
|
26
41
|
|
|
27
|
-
|
|
42
|
+
### Step 2: Set Up Medium-Term Memory (Checkpointer)
|
|
43
|
+
|
|
44
|
+
Persists graph state between invocations of the same demand. Enables resume after failure.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install langgraph-checkpoint-postgres psycopg
|
|
48
|
+
```
|
|
28
49
|
|
|
29
50
|
```python
|
|
30
51
|
from langgraph.checkpoint.postgres.aio import AsyncPostgresSaver
|
|
52
|
+
from langgraph.graph import StateGraph
|
|
31
53
|
|
|
32
54
|
checkpointer = AsyncPostgresSaver.from_conn_string(DATABASE_URL)
|
|
33
55
|
|
|
34
56
|
graph = StateGraph(OrchestratorState)
|
|
35
|
-
# ...
|
|
57
|
+
# ... define nodes and edges ...
|
|
36
58
|
app = graph.compile(checkpointer=checkpointer)
|
|
37
59
|
|
|
38
|
-
#
|
|
60
|
+
# Use consistent thread_id per demand
|
|
39
61
|
config = {"configurable": {"thread_id": f"demand-{demand_id}"}}
|
|
40
62
|
result = await app.ainvoke({"messages": [...]}, config=config)
|
|
41
63
|
|
|
42
|
-
#
|
|
43
|
-
result2 = await app.ainvoke({"messages": [
|
|
64
|
+
# Next invocation with same thread_id resumes from saved state
|
|
65
|
+
result2 = await app.ainvoke({"messages": [new_msg]}, config=config)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Verify checkpointer is working:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
psql $DATABASE_URL -c "SELECT thread_id, created_at FROM checkpoints ORDER BY created_at DESC LIMIT 5;"
|
|
44
72
|
```
|
|
45
73
|
|
|
46
|
-
|
|
74
|
+
### Step 3: Set Up Long-Term Memory (Store)
|
|
47
75
|
|
|
48
|
-
|
|
76
|
+
Persists knowledge across different demands. The agent remembers patterns, preferences, and learnings.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install langgraph-store-postgres
|
|
80
|
+
```
|
|
49
81
|
|
|
50
82
|
```python
|
|
51
83
|
from langgraph.store.postgres import AsyncPostgresStore
|
|
52
84
|
|
|
53
85
|
store = AsyncPostgresStore.from_conn_string(DATABASE_URL)
|
|
54
86
|
|
|
55
|
-
#
|
|
87
|
+
# Save a learned pattern
|
|
56
88
|
await store.aput(
|
|
57
89
|
namespace=("agent", "backend", "patterns"),
|
|
58
90
|
key="spring-crud-pattern",
|
|
59
91
|
value={
|
|
60
|
-
"pattern": "
|
|
92
|
+
"pattern": "Use record for DTO, entity for domain",
|
|
61
93
|
"learned_from": "demand-123",
|
|
62
94
|
"confidence": 0.95,
|
|
63
95
|
"created_at": "2026-03-27"
|
|
64
96
|
}
|
|
65
97
|
)
|
|
66
98
|
|
|
67
|
-
#
|
|
99
|
+
# Search for relevant learnings
|
|
68
100
|
results = await store.asearch(
|
|
69
101
|
namespace=("agent", "backend", "patterns"),
|
|
70
|
-
query="
|
|
102
|
+
query="how to create DTO for REST API",
|
|
71
103
|
limit=5
|
|
72
104
|
)
|
|
73
105
|
```
|
|
74
106
|
|
|
75
|
-
|
|
107
|
+
### Step 4: Integrate Memory into Deep Agent
|
|
108
|
+
|
|
109
|
+
Wire all three memory tiers into a Deep Agent configuration.
|
|
76
110
|
|
|
77
111
|
```python
|
|
78
112
|
from deepagents import create_deep_agent
|
|
@@ -85,22 +119,72 @@ agent = create_deep_agent(
|
|
|
85
119
|
backend=FilesystemBackend(root_dir=".", virtual_mode=True),
|
|
86
120
|
checkpointer=PostgresSaver(conn_string=DATABASE_URL),
|
|
87
121
|
store=PostgresStore(conn_string=DATABASE_URL),
|
|
88
|
-
system_prompt="
|
|
122
|
+
system_prompt="You are a backend agent..."
|
|
89
123
|
)
|
|
90
124
|
```
|
|
91
125
|
|
|
92
|
-
|
|
126
|
+
### Step 5: Implement Memory Cleanup and Decay
|
|
93
127
|
|
|
94
|
-
|
|
128
|
+
Memories age. Remove stale or low-confidence entries to keep the store relevant.
|
|
95
129
|
|
|
96
130
|
```python
|
|
131
|
+
from datetime import datetime, timedelta
|
|
132
|
+
|
|
97
133
|
async def cleanup_stale_memories(store, max_age_days: int = 90):
|
|
98
|
-
"""Remove
|
|
134
|
+
"""Remove old or low-confidence memories."""
|
|
99
135
|
cutoff = datetime.now() - timedelta(days=max_age_days)
|
|
100
136
|
memories = await store.alist(namespace=("agent",))
|
|
137
|
+
removed = 0
|
|
101
138
|
for mem in memories:
|
|
102
139
|
if mem.value.get("created_at", "") < cutoff.isoformat():
|
|
103
140
|
await store.adelete(namespace=mem.namespace, key=mem.key)
|
|
141
|
+
removed += 1
|
|
104
142
|
elif mem.value.get("confidence", 1.0) < 0.3:
|
|
105
143
|
await store.adelete(namespace=mem.namespace, key=mem.key)
|
|
144
|
+
removed += 1
|
|
145
|
+
return removed
|
|
106
146
|
```
|
|
147
|
+
|
|
148
|
+
Run cleanup:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
python -m memory.cleanup --max-age-days 90 --min-confidence 0.3
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Resources
|
|
155
|
+
- `references/memory-tiers.md` - Detailed comparison of memory tiers with use cases
|
|
156
|
+
- `references/namespace-conventions.md` - Naming conventions for store namespaces
|
|
157
|
+
|
|
158
|
+
## Examples
|
|
159
|
+
|
|
160
|
+
### Example 1: Enable Resume After Failure
|
|
161
|
+
User asks: "Our agent crashes mid-task and loses all progress. Fix it."
|
|
162
|
+
Response approach:
|
|
163
|
+
1. Add PostgresSaver checkpointer to the agent's graph compilation
|
|
164
|
+
2. Use `thread_id` based on the demand ID for consistent state
|
|
165
|
+
3. On restart, invoke with the same thread_id -- LangGraph automatically resumes
|
|
166
|
+
4. Verify with: `psql $DATABASE_URL -c "SELECT * FROM checkpoints WHERE thread_id='demand-xyz';"`
|
|
167
|
+
|
|
168
|
+
### Example 2: Agent Should Learn From Past Work
|
|
169
|
+
User asks: "The backend agent keeps making the same pagination mistake. Make it learn."
|
|
170
|
+
Response approach:
|
|
171
|
+
1. After each successful demand, save patterns to the Store
|
|
172
|
+
2. Before each new task, search the Store for relevant learnings
|
|
173
|
+
3. Inject top-3 relevant learnings into the agent's context
|
|
174
|
+
4. Track confidence scores -- boost on positive feedback, decay on negative
|
|
175
|
+
|
|
176
|
+
### Example 3: Clean Up Old Memories
|
|
177
|
+
User asks: "The memory store has grown too large. Clean it up."
|
|
178
|
+
Response approach:
|
|
179
|
+
1. Run `memory.cleanup --max-age-days 90` to remove entries older than 90 days
|
|
180
|
+
2. Remove entries with confidence below 0.3
|
|
181
|
+
3. Audit remaining entries for duplicates
|
|
182
|
+
4. Set up a weekly cron job for automatic cleanup
|
|
183
|
+
|
|
184
|
+
## Notes
|
|
185
|
+
- Always use `thread_id` based on a stable identifier (demand_id, session_id)
|
|
186
|
+
- Checkpointer handles resume automatically -- no custom logic needed
|
|
187
|
+
- Store namespaces should follow the convention: `("agent", agent_type, category)`
|
|
188
|
+
- Memory cleanup should run on a schedule (weekly recommended)
|
|
189
|
+
- Include `confidence` and `created_at` in all store entries for decay management
|
|
190
|
+
- Long-term memories should be surfaced via retrieval, not dumped into the prompt
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Memory Tiers Reference
|
|
2
|
+
|
|
3
|
+
## Comparison
|
|
4
|
+
|
|
5
|
+
| Tier | Duration | Mechanism | Storage | Cost | Use Case |
|
|
6
|
+
|---|---|---|---|---|---|
|
|
7
|
+
| Short-term | 1 session | Context window | In-memory | Free | Current conversation messages |
|
|
8
|
+
| Medium-term | 1 demand | Checkpointer | PostgreSQL | Low | Graph state between invocations |
|
|
9
|
+
| Long-term | Permanent | Store | PostgreSQL | Low | Patterns, preferences, learnings |
|
|
10
|
+
|
|
11
|
+
## Short-Term Memory
|
|
12
|
+
|
|
13
|
+
- **What**: Messages in the current invocation chain.
|
|
14
|
+
- **How**: `Annotated[list, add_messages]` in state schema.
|
|
15
|
+
- **Limit**: Bounded by context window size.
|
|
16
|
+
- **When it resets**: End of the invocation chain.
|
|
17
|
+
|
|
18
|
+
## Medium-Term Memory
|
|
19
|
+
|
|
20
|
+
- **What**: Full graph state (all state fields) at each node execution.
|
|
21
|
+
- **How**: `graph.compile(checkpointer=PostgresSaver(...))`.
|
|
22
|
+
- **Limit**: Bounded by database storage.
|
|
23
|
+
- **When it resets**: When the demand is completed or explicitly cleared.
|
|
24
|
+
- **Key feature**: Enables resume after crash.
|
|
25
|
+
|
|
26
|
+
## Long-Term Memory
|
|
27
|
+
|
|
28
|
+
- **What**: Extracted patterns, preferences, and learnings.
|
|
29
|
+
- **How**: `store.aput(namespace=..., key=..., value=...)`.
|
|
30
|
+
- **Limit**: Bounded by database storage and relevance decay.
|
|
31
|
+
- **When it resets**: Only when explicitly cleaned up.
|
|
32
|
+
- **Key feature**: Enables cross-demand learning.
|
|
33
|
+
|
|
34
|
+
## Decision Guide
|
|
35
|
+
|
|
36
|
+
| Question | Answer | Use |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| Does the agent need to remember within this conversation? | Yes | Short-term |
|
|
39
|
+
| Does the agent need to resume after a crash? | Yes | Medium-term (checkpointer) |
|
|
40
|
+
| Should the agent learn from past demands? | Yes | Long-term (store) |
|
|
41
|
+
| Does the agent need to share knowledge with other agents? | Yes | Long-term (store with shared namespace) |
|
package/templates/bundle-ai-agents/skills/memory-management/references/namespace-conventions.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Namespace Conventions Reference
|
|
2
|
+
|
|
3
|
+
## Store Namespace Structure
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
("agent", agent_type, category)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Standard Namespaces
|
|
10
|
+
|
|
11
|
+
| Namespace | Purpose | Example Key |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| `("agent", "backend", "patterns")` | Code patterns learned by backend agent | `"fastapi-crud-pattern"` |
|
|
14
|
+
| `("agent", "frontend", "patterns")` | UI patterns learned by frontend agent | `"react-form-pattern"` |
|
|
15
|
+
| `("agent", "backend", "errors")` | Common errors and their fixes | `"alembic-migration-conflict"` |
|
|
16
|
+
| `("agent", "backend", "preferences")` | Team preferences for code style | `"prefer-dataclass-over-dict"` |
|
|
17
|
+
| `("project", "decisions")` | Architectural decisions | `"chose-fastapi-over-flask"` |
|
|
18
|
+
| `("project", "standards")` | Project-wide coding standards | `"naming-conventions"` |
|
|
19
|
+
|
|
20
|
+
## Value Schema
|
|
21
|
+
|
|
22
|
+
Every store entry should include these fields:
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
{
|
|
26
|
+
"pattern": str, # The actual knowledge
|
|
27
|
+
"learned_from": str, # Which demand/task this came from
|
|
28
|
+
"confidence": float, # 0.0 to 1.0 (boost on positive feedback, decay on negative)
|
|
29
|
+
"created_at": str, # ISO timestamp
|
|
30
|
+
"updated_at": str, # ISO timestamp (updated on reinforcement)
|
|
31
|
+
"usage_count": int, # How many times this memory was retrieved
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Confidence Management
|
|
36
|
+
|
|
37
|
+
- **Initial**: 0.7 (new learning, not yet validated)
|
|
38
|
+
- **Reinforced**: +0.1 per positive use (max 1.0)
|
|
39
|
+
- **Contradicted**: -0.2 per negative feedback (min 0.0)
|
|
40
|
+
- **Cleanup threshold**: < 0.3 (remove on next cleanup run)
|
|
41
|
+
- **Time decay**: -0.05 per month without usage
|
|
@@ -1,66 +1,158 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: prompt-engineering
|
|
3
|
-
description:
|
|
3
|
+
description: Create and optimize system prompts for AI agents following context engineering best practices. Use when writing prompts, improving existing prompts, or creating agent instructions.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
|
-
# Prompt Engineering
|
|
8
|
+
# Prompt Engineering
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Craft effective system prompts for AI agents using structured templates, best practices, and iterative refinement.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
- Writing a new system prompt for an agent
|
|
14
|
+
- Improving an underperforming agent's instructions
|
|
15
|
+
- Creating role-specific prompts for multi-agent systems
|
|
16
|
+
- Reviewing prompts for anti-patterns and clarity issues
|
|
17
|
+
- Optimizing prompts to reduce token usage without losing quality
|
|
18
|
+
|
|
19
|
+
## Available Operations
|
|
20
|
+
1. Write a structured system prompt from scratch
|
|
21
|
+
2. Audit an existing prompt for anti-patterns
|
|
22
|
+
3. Refine a prompt based on agent evaluation results
|
|
23
|
+
4. Create few-shot examples for a prompt
|
|
24
|
+
5. Optimize prompt token count
|
|
25
|
+
|
|
26
|
+
## Multi-Step Workflow
|
|
27
|
+
|
|
28
|
+
### Step 1: Define the Prompt Structure
|
|
29
|
+
|
|
30
|
+
Every agent system prompt should follow this 6-part structure:
|
|
9
31
|
|
|
10
32
|
```
|
|
11
|
-
1.
|
|
12
|
-
2.
|
|
13
|
-
3.
|
|
14
|
-
4.
|
|
15
|
-
5.
|
|
16
|
-
6.
|
|
33
|
+
1. IDENTITY -- Who the agent is
|
|
34
|
+
2. OBJECTIVE -- What it must achieve
|
|
35
|
+
3. TOOLS -- What it has available
|
|
36
|
+
4. RULES -- Non-negotiable constraints
|
|
37
|
+
5. FORMAT -- How to structure output
|
|
38
|
+
6. EXAMPLES -- Concrete demonstrations
|
|
17
39
|
```
|
|
18
40
|
|
|
19
|
-
|
|
41
|
+
### Step 2: Write the System Prompt
|
|
42
|
+
|
|
43
|
+
Use the template below, filling in each section with specific details.
|
|
20
44
|
|
|
21
45
|
```python
|
|
22
46
|
SYSTEM_PROMPT = """
|
|
23
|
-
##
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
##
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
##
|
|
34
|
-
1.
|
|
35
|
-
2.
|
|
36
|
-
3.
|
|
37
|
-
4.
|
|
38
|
-
5.
|
|
39
|
-
|
|
40
|
-
##
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
##
|
|
46
|
-
Task: "
|
|
47
|
-
|
|
47
|
+
## Identity
|
|
48
|
+
You are {role}, specialized in {specialty}.
|
|
49
|
+
|
|
50
|
+
## Objective
|
|
51
|
+
Your mission is {primary_objective}. You work within Maestro,
|
|
52
|
+
a development governance platform.
|
|
53
|
+
|
|
54
|
+
## Available Tools
|
|
55
|
+
{list_of_tools_with_descriptions}
|
|
56
|
+
|
|
57
|
+
## Rules
|
|
58
|
+
1. Always follow the {bundle_name} bundle for code standards
|
|
59
|
+
2. Every commit must reference the task: {task_id}
|
|
60
|
+
3. Work only in the designated worktree: {worktree_path}
|
|
61
|
+
4. Report progress at every significant step
|
|
62
|
+
5. Request human review for destructive operations
|
|
63
|
+
|
|
64
|
+
## Response Format
|
|
65
|
+
- For code: use fenced code blocks with language specified
|
|
66
|
+
- For decisions: justify with "why"
|
|
67
|
+
- For errors: include context and suggested fix
|
|
68
|
+
|
|
69
|
+
## Example
|
|
70
|
+
Task: "Create endpoint GET /api/v1/demands"
|
|
71
|
+
Action: Create controller, use case, repository following Clean Architecture
|
|
48
72
|
Branch: feature/backend-{task_id}
|
|
49
73
|
"""
|
|
50
74
|
```
|
|
51
75
|
|
|
52
|
-
|
|
76
|
+
### Step 3: Apply Best Practices
|
|
77
|
+
|
|
78
|
+
Review the prompt against these rules:
|
|
79
|
+
|
|
80
|
+
1. **Be specific** -- "Create a REST API with FastAPI" > "Create an API"
|
|
81
|
+
2. **Explain why** -- "Use Value Objects because they enforce validation at construction" > "Use Value Objects"
|
|
82
|
+
3. **Give examples** -- One good example is worth 10 lines of instruction
|
|
83
|
+
4. **Avoid negatives** -- "Keep functions under 20 lines" > "Don't write long functions"
|
|
84
|
+
5. **Prioritize** -- Put the most important rules first (models pay more attention to early content)
|
|
85
|
+
6. **Test** -- Run the prompt with real scenarios before deploying
|
|
86
|
+
|
|
87
|
+
### Step 4: Check for Anti-Patterns
|
|
88
|
+
|
|
89
|
+
Audit the prompt for these common problems:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Count NEVER/ALWAYS occurrences (too many weaken their impact)
|
|
93
|
+
grep -c -i "never\|always" prompt.md
|
|
94
|
+
|
|
95
|
+
# Check prompt length (over 5000 words causes focus loss)
|
|
96
|
+
wc -w prompt.md
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Anti-patterns to fix:
|
|
100
|
+
- Excessive NEVER/ALWAYS (loses emphasis when overused)
|
|
101
|
+
- Contradictory instructions (e.g., "be concise" + "explain everything in detail")
|
|
102
|
+
- Prompts over 5000 words (agent loses focus on key instructions)
|
|
103
|
+
- Rules without justification (agent cannot reason about when to flex)
|
|
104
|
+
|
|
105
|
+
### Step 5: Test and Iterate
|
|
106
|
+
|
|
107
|
+
Run the prompt through evaluation scenarios to measure effectiveness.
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
python -m evals.run_prompt_eval --prompt prompts/agent_backend.md --scenarios evals/prompt_scenarios.json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Compare scores across prompt versions:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
python -m evals.compare_prompts --v1 prompts/v1.md --v2 prompts/v2.md --scenarios evals/prompt_scenarios.json
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Resources
|
|
120
|
+
- `references/prompt-templates.md` - Ready-to-use prompt templates for common agent roles
|
|
121
|
+
- `references/anti-patterns.md` - Detailed anti-pattern catalog with fix examples
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
### Example 1: Write a Backend Agent Prompt
|
|
126
|
+
User asks: "Create a system prompt for our backend agent that builds FastAPI endpoints."
|
|
127
|
+
Response approach:
|
|
128
|
+
1. Set identity to "Backend Engineer Agent, specialized in FastAPI and Clean Architecture"
|
|
129
|
+
2. Define objective: "Build production-ready REST API endpoints following bundle standards"
|
|
130
|
+
3. List tools: file operations, git commands, test runner, linter
|
|
131
|
+
4. Set rules: follow clean-architecture skill, enforce test coverage > 80%, use typed DTOs
|
|
132
|
+
5. Add format section for code blocks and error reporting
|
|
133
|
+
6. Include a concrete example of building a CRUD endpoint
|
|
53
134
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
135
|
+
### Example 2: Fix an Underperforming Prompt
|
|
136
|
+
User asks: "Our agent keeps ignoring the coding standards. Fix the prompt."
|
|
137
|
+
Response approach:
|
|
138
|
+
1. Read the current prompt and check for vague instructions
|
|
139
|
+
2. Look for missing justifications on rules (agent doesn't understand importance)
|
|
140
|
+
3. Move coding standards rules higher in the prompt (priority by position)
|
|
141
|
+
4. Add a concrete example showing compliant vs non-compliant code
|
|
142
|
+
5. Add a "Common Mistakes" section with specific things to avoid
|
|
60
143
|
|
|
61
|
-
|
|
144
|
+
### Example 3: Reduce Prompt Token Count
|
|
145
|
+
User asks: "The system prompt is too long, cut it down without losing quality."
|
|
146
|
+
Response approach:
|
|
147
|
+
1. Count current tokens with `tiktoken`
|
|
148
|
+
2. Move detailed reference material to skill files loaded on-demand
|
|
149
|
+
3. Replace verbose explanations with concise bullet points
|
|
150
|
+
4. Keep examples (they're high-value) but trim redundant ones
|
|
151
|
+
5. Target: system prompt under 2000 tokens, details in skills
|
|
62
152
|
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
153
|
+
## Notes
|
|
154
|
+
- System prompts should stay under 2000 tokens; move details to on-demand skills
|
|
155
|
+
- Test every prompt change with at least 5 real-world scenarios
|
|
156
|
+
- Version your prompts (v1, v2, etc.) and track performance across versions
|
|
157
|
+
- The first 500 tokens of a prompt get the most attention from the model
|
|
158
|
+
- Few-shot examples are the single most effective prompting technique
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Prompt Anti-Patterns Reference
|
|
2
|
+
|
|
3
|
+
## 1. NEVER/ALWAYS Overuse
|
|
4
|
+
|
|
5
|
+
**Problem**: Using NEVER and ALWAYS too frequently dilutes their impact.
|
|
6
|
+
|
|
7
|
+
**Bad**:
|
|
8
|
+
```
|
|
9
|
+
NEVER use var. ALWAYS use const. NEVER use any. ALWAYS type everything.
|
|
10
|
+
NEVER skip tests. ALWAYS write docs. NEVER commit without review.
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Good**:
|
|
14
|
+
```
|
|
15
|
+
Use const by default, let when reassignment is needed.
|
|
16
|
+
Type all function parameters and return values.
|
|
17
|
+
Critical: NEVER commit secrets or credentials to the repository.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Fix**: Reserve NEVER/ALWAYS for truly critical rules (security, data integrity). Use softer language for preferences.
|
|
21
|
+
|
|
22
|
+
## 2. Contradictory Instructions
|
|
23
|
+
|
|
24
|
+
**Problem**: Instructions that conflict cause unpredictable behavior.
|
|
25
|
+
|
|
26
|
+
**Bad**:
|
|
27
|
+
```
|
|
28
|
+
Be concise in your responses.
|
|
29
|
+
Explain every decision in detail with full justification.
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Good**:
|
|
33
|
+
```
|
|
34
|
+
Be concise by default. When making architectural decisions, explain the reasoning.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Fix**: Qualify when each instruction applies.
|
|
38
|
+
|
|
39
|
+
## 3. Excessive Length (> 5000 words)
|
|
40
|
+
|
|
41
|
+
**Problem**: The agent loses focus on key instructions when the prompt is too long.
|
|
42
|
+
|
|
43
|
+
**Fix**: Move reference material to skill files. Keep the system prompt under 2000 tokens. Load details on-demand.
|
|
44
|
+
|
|
45
|
+
## 4. Rules Without Justification
|
|
46
|
+
|
|
47
|
+
**Problem**: Without knowing why, the agent cannot reason about edge cases.
|
|
48
|
+
|
|
49
|
+
**Bad**: "Use Value Objects for all domain primitives."
|
|
50
|
+
|
|
51
|
+
**Good**: "Use Value Objects for domain primitives because they enforce validation at construction time and make the domain model self-documenting."
|
|
52
|
+
|
|
53
|
+
## 5. Vague Instructions
|
|
54
|
+
|
|
55
|
+
**Problem**: Ambiguity leads to inconsistent agent behavior.
|
|
56
|
+
|
|
57
|
+
**Bad**: "Write good code."
|
|
58
|
+
|
|
59
|
+
**Good**: "Write code that follows Clean Architecture: separate controllers, use cases, and repositories. Keep functions under 20 lines. Include type hints on all function signatures."
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Prompt Templates Reference
|
|
2
|
+
|
|
3
|
+
## Backend Agent Template
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
## Identity
|
|
7
|
+
You are a Backend Engineer Agent, specialized in building REST APIs with FastAPI and Clean Architecture.
|
|
8
|
+
|
|
9
|
+
## Objective
|
|
10
|
+
Build production-ready API endpoints that follow the project's bundle standards, including proper error handling, validation, pagination, and test coverage.
|
|
11
|
+
|
|
12
|
+
## Tools
|
|
13
|
+
- File read/write operations
|
|
14
|
+
- Git commands (commit, branch, push)
|
|
15
|
+
- pytest for running tests
|
|
16
|
+
- ruff for linting
|
|
17
|
+
|
|
18
|
+
## Rules
|
|
19
|
+
1. Follow Clean Architecture: controller -> use case -> repository
|
|
20
|
+
2. Every endpoint must have input validation with Pydantic models
|
|
21
|
+
3. Test coverage must be >= 80% for new code
|
|
22
|
+
4. Use typed DTOs for all API responses
|
|
23
|
+
5. Handle errors with standardized ErrorResponse format
|
|
24
|
+
|
|
25
|
+
## Response Format
|
|
26
|
+
- Code in fenced blocks with language specified
|
|
27
|
+
- Explain architectural decisions with "why"
|
|
28
|
+
- Report test results after implementation
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Frontend Agent Template
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
## Identity
|
|
35
|
+
You are a Frontend Engineer Agent, specialized in React with TypeScript.
|
|
36
|
+
|
|
37
|
+
## Objective
|
|
38
|
+
Build responsive, accessible UI components following the project's design system and bundle standards.
|
|
39
|
+
|
|
40
|
+
## Tools
|
|
41
|
+
- File read/write operations
|
|
42
|
+
- npm/pnpm commands
|
|
43
|
+
- Jest/Vitest for testing
|
|
44
|
+
- ESLint for linting
|
|
45
|
+
|
|
46
|
+
## Rules
|
|
47
|
+
1. Use functional components with hooks
|
|
48
|
+
2. All props must be typed with TypeScript interfaces
|
|
49
|
+
3. Components must be accessible (ARIA labels, keyboard navigation)
|
|
50
|
+
4. Write unit tests for business logic, integration tests for user flows
|
|
51
|
+
5. Use the project's design tokens for spacing, colors, typography
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## DevOps Agent Template
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
## Identity
|
|
58
|
+
You are a DevOps Engineer Agent, specialized in Docker, CI/CD, and infrastructure.
|
|
59
|
+
|
|
60
|
+
## Objective
|
|
61
|
+
Containerize applications, configure CI/CD pipelines, and manage deployment infrastructure.
|
|
62
|
+
|
|
63
|
+
## Tools
|
|
64
|
+
- Docker CLI (build, push, compose)
|
|
65
|
+
- Git commands
|
|
66
|
+
- kubectl for Kubernetes
|
|
67
|
+
- Terraform for infrastructure
|
|
68
|
+
|
|
69
|
+
## Rules
|
|
70
|
+
1. All Dockerfiles must use multi-stage builds
|
|
71
|
+
2. Never run containers as root
|
|
72
|
+
3. Include health checks in all service containers
|
|
73
|
+
4. Secrets must come from environment variables, never hardcoded
|
|
74
|
+
5. CI pipelines must include lint, test, build, and security scan stages
|
|
75
|
+
```
|