maestro-bundle 1.3.1 → 1.4.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/package.json +1 -1
- 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/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/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/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/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
package/package.json
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: agent-orchestration
|
|
3
|
-
description:
|
|
3
|
+
description: Build multi-agent systems with LangGraph including orchestrator, subagents, routing, and delegation. Use when coordinating multiple agents, creating agent teams, or implementing orchestration workflows.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
|
-
#
|
|
8
|
+
# Agent Orchestration
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Design and implement multi-agent systems where an orchestrator coordinates specialized subagents through task planning, intelligent routing, compliance validation, and human-in-the-loop approval.
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
## When to Use
|
|
13
|
+
- Coordinating multiple specialized agents (frontend, backend, devops)
|
|
14
|
+
- Implementing task decomposition and delegation workflows
|
|
15
|
+
- Building a LangGraph StateGraph with routing logic
|
|
16
|
+
- Adding human-in-the-loop approval gates for destructive operations
|
|
17
|
+
- Creating agent pipelines that validate compliance before merging work
|
|
18
|
+
|
|
19
|
+
## Available Operations
|
|
20
|
+
1. Define orchestrator state schema
|
|
21
|
+
2. Build the orchestrator graph with nodes and edges
|
|
22
|
+
3. Implement intelligent task routing
|
|
23
|
+
4. Delegate tasks to specialized subagents
|
|
24
|
+
5. Add compliance validation nodes
|
|
25
|
+
6. Wire up human-in-the-loop interrupt gates
|
|
26
|
+
7. Merge work from multiple agent branches
|
|
20
27
|
|
|
21
|
-
##
|
|
28
|
+
## Multi-Step Workflow
|
|
29
|
+
|
|
30
|
+
### Step 1: Define the Orchestrator State
|
|
31
|
+
|
|
32
|
+
Create a typed state schema that tracks the full lifecycle of a demand.
|
|
22
33
|
|
|
23
34
|
```python
|
|
24
35
|
from typing import TypedDict, Annotated, Literal
|
|
@@ -36,14 +47,17 @@ class OrchestratorState(TypedDict):
|
|
|
36
47
|
final_status: str
|
|
37
48
|
```
|
|
38
49
|
|
|
39
|
-
|
|
50
|
+
### Step 2: Build the Graph Structure
|
|
51
|
+
|
|
52
|
+
Wire up the orchestrator nodes and conditional edges.
|
|
40
53
|
|
|
41
54
|
```python
|
|
42
55
|
from langgraph.graph import StateGraph, START, END
|
|
56
|
+
from langgraph.checkpoint.postgres import PostgresSaver
|
|
43
57
|
|
|
44
58
|
graph = StateGraph(OrchestratorState)
|
|
45
59
|
|
|
46
|
-
#
|
|
60
|
+
# Add nodes
|
|
47
61
|
graph.add_node("analyze_demand", analyze_demand_node)
|
|
48
62
|
graph.add_node("plan_tasks", plan_tasks_node)
|
|
49
63
|
graph.add_node("route_to_agent", route_to_agent_node)
|
|
@@ -52,7 +66,7 @@ graph.add_node("validate_compliance", validate_compliance_node)
|
|
|
52
66
|
graph.add_node("human_review", human_review_node)
|
|
53
67
|
graph.add_node("merge_work", merge_work_node)
|
|
54
68
|
|
|
55
|
-
#
|
|
69
|
+
# Wire edges
|
|
56
70
|
graph.add_edge(START, "analyze_demand")
|
|
57
71
|
graph.add_edge("analyze_demand", "plan_tasks")
|
|
58
72
|
graph.add_edge("plan_tasks", "route_to_agent")
|
|
@@ -71,14 +85,37 @@ graph.add_edge("merge_work", END)
|
|
|
71
85
|
app = graph.compile(checkpointer=PostgresSaver(conn))
|
|
72
86
|
```
|
|
73
87
|
|
|
74
|
-
|
|
88
|
+
### Step 3: Implement Intelligent Routing
|
|
89
|
+
|
|
90
|
+
Route tasks to the right subagent based on keywords or LLM classification.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
def route_to_agent(state: OrchestratorState) -> dict:
|
|
94
|
+
task = state["task_plan"][state["current_task_index"]]
|
|
95
|
+
|
|
96
|
+
routing_map = {
|
|
97
|
+
"frontend": ["ui", "component", "screen", "react", "css"],
|
|
98
|
+
"backend": ["api", "endpoint", "database", "service", "entity"],
|
|
99
|
+
"devops": ["deploy", "pipeline", "docker", "k8s", "ci"],
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for agent_type, keywords in routing_map.items():
|
|
103
|
+
if any(kw in task["description"].lower() for kw in keywords):
|
|
104
|
+
return {"assigned_agents": {task["id"]: agent_type}}
|
|
105
|
+
|
|
106
|
+
# Fallback: use LLM to decide
|
|
107
|
+
return {"assigned_agents": {task["id"]: llm_route(task)}}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Step 4: Delegate to Subagents
|
|
111
|
+
|
|
112
|
+
Each subagent has its own graph, tools, and worktree.
|
|
75
113
|
|
|
76
114
|
```python
|
|
77
115
|
async def execute_agent_node(state: OrchestratorState):
|
|
78
116
|
task = state["task_plan"][state["current_task_index"]]
|
|
79
117
|
agent_type = state["assigned_agents"][task["id"]]
|
|
80
118
|
|
|
81
|
-
# Cada agente tem seu próprio grafo/tools
|
|
82
119
|
agent = agent_registry.get(agent_type)
|
|
83
120
|
result = await agent.ainvoke({
|
|
84
121
|
"task": task,
|
|
@@ -95,28 +132,9 @@ async def execute_agent_node(state: OrchestratorState):
|
|
|
95
132
|
}
|
|
96
133
|
```
|
|
97
134
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
```python
|
|
101
|
-
def route_to_agent(state: OrchestratorState) -> dict:
|
|
102
|
-
"""Decide qual tipo de agente executar baseado na task"""
|
|
103
|
-
task = state["task_plan"][state["current_task_index"]]
|
|
104
|
-
|
|
105
|
-
routing_map = {
|
|
106
|
-
"frontend": ["ui", "componente", "tela", "react", "css"],
|
|
107
|
-
"backend": ["api", "endpoint", "banco", "service", "entity"],
|
|
108
|
-
"devops": ["deploy", "pipeline", "docker", "k8s", "ci"],
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
for agent_type, keywords in routing_map.items():
|
|
112
|
-
if any(kw in task["description"].lower() for kw in keywords):
|
|
113
|
-
return {"assigned_agents": {task["id"]: agent_type}}
|
|
114
|
-
|
|
115
|
-
# Fallback: usar LLM para decidir
|
|
116
|
-
return {"assigned_agents": {task["id"]: llm_route(task)}}
|
|
117
|
-
```
|
|
135
|
+
### Step 5: Add Human-in-the-Loop Approval
|
|
118
136
|
|
|
119
|
-
|
|
137
|
+
Use LangGraph interrupts for merge approval gates.
|
|
120
138
|
|
|
121
139
|
```python
|
|
122
140
|
from langgraph.types import interrupt
|
|
@@ -126,7 +144,55 @@ def human_review_node(state: OrchestratorState):
|
|
|
126
144
|
"type": "merge_approval",
|
|
127
145
|
"branches": state["branch_status"],
|
|
128
146
|
"compliance": state["compliance_results"],
|
|
129
|
-
"message": "
|
|
147
|
+
"message": "Approve merging branches?"
|
|
130
148
|
})
|
|
131
149
|
return {"needs_human_review": False, "final_status": approval["decision"]}
|
|
132
150
|
```
|
|
151
|
+
|
|
152
|
+
### Step 6: Run and Test the Orchestrator
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Run the orchestrator with a test demand
|
|
156
|
+
python -m orchestrator.run --demand "Create CRUD for demands with REST API and React UI"
|
|
157
|
+
|
|
158
|
+
# Verify the graph structure
|
|
159
|
+
python -c "from orchestrator.graph import app; app.get_graph().print_ascii()"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Resources
|
|
163
|
+
- `references/graph-patterns.md` - Common LangGraph graph patterns for orchestration
|
|
164
|
+
- `references/routing-strategies.md` - Detailed routing strategies and fallback mechanisms
|
|
165
|
+
|
|
166
|
+
## Examples
|
|
167
|
+
|
|
168
|
+
### Example 1: Decompose and Execute a Full-Stack Demand
|
|
169
|
+
User asks: "Set up an orchestrator that decomposes a demand into frontend and backend tasks and delegates them."
|
|
170
|
+
Response approach:
|
|
171
|
+
1. Define OrchestratorState with task_plan and assigned_agents
|
|
172
|
+
2. Create analyze_demand node that uses LLM to break down the demand
|
|
173
|
+
3. Create plan_tasks node that structures tasks with dependencies
|
|
174
|
+
4. Implement keyword-based routing for frontend vs backend
|
|
175
|
+
5. Wire up execute_agent to delegate each task to the right subagent
|
|
176
|
+
6. Add compliance validation before merge
|
|
177
|
+
|
|
178
|
+
### Example 2: Add a New Agent Type
|
|
179
|
+
User asks: "Add a QA agent that runs tests after backend tasks complete."
|
|
180
|
+
Response approach:
|
|
181
|
+
1. Create a QA agent graph with test-running tools
|
|
182
|
+
2. Register it in the agent_registry
|
|
183
|
+
3. Add "qa" keywords to the routing map (e.g., "test", "quality", "coverage")
|
|
184
|
+
4. Add a conditional edge from execute_agent to route QA tasks after backend
|
|
185
|
+
|
|
186
|
+
### Example 3: Implement Parallel Agent Execution
|
|
187
|
+
User asks: "Make frontend and backend agents run in parallel instead of sequentially."
|
|
188
|
+
Response approach:
|
|
189
|
+
1. Use LangGraph's `Send` API to fan out to multiple agents simultaneously
|
|
190
|
+
2. Add a `join_results` node that waits for all parallel branches
|
|
191
|
+
3. Wire conditional edges from join_results to validate_compliance
|
|
192
|
+
|
|
193
|
+
## Notes
|
|
194
|
+
- Always use a checkpointer (PostgresSaver) so the orchestrator can resume after failures
|
|
195
|
+
- Each subagent should operate in its own git worktree to avoid conflicts
|
|
196
|
+
- Compliance validation should run before any merge operation
|
|
197
|
+
- Human review gates are mandatory for destructive operations (merges, deployments)
|
|
198
|
+
- Use thread_id based on demand_id for consistent state across invocations
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Graph Patterns Reference
|
|
2
|
+
|
|
3
|
+
## Common LangGraph Orchestration Patterns
|
|
4
|
+
|
|
5
|
+
### 1. Sequential Pipeline
|
|
6
|
+
```
|
|
7
|
+
START -> analyze -> plan -> execute -> validate -> END
|
|
8
|
+
```
|
|
9
|
+
Best for: Simple workflows with no branching.
|
|
10
|
+
|
|
11
|
+
### 2. Router Pattern
|
|
12
|
+
```
|
|
13
|
+
START -> analyze -> router --(frontend)--> agent_frontend -> merge
|
|
14
|
+
\--(backend)---> agent_backend -> merge
|
|
15
|
+
\--(devops)----> agent_devops -> merge
|
|
16
|
+
```
|
|
17
|
+
Best for: Task delegation to specialized agents.
|
|
18
|
+
|
|
19
|
+
### 3. Loop with Exit Condition
|
|
20
|
+
```
|
|
21
|
+
START -> plan -> execute -> check_done --(more tasks)--> execute
|
|
22
|
+
\--(all done)---> validate -> END
|
|
23
|
+
```
|
|
24
|
+
Best for: Iterating through a task list.
|
|
25
|
+
|
|
26
|
+
### 4. Fan-Out / Fan-In (Parallel)
|
|
27
|
+
```python
|
|
28
|
+
from langgraph.types import Send
|
|
29
|
+
|
|
30
|
+
def fan_out(state):
|
|
31
|
+
return [Send("execute_agent", {"task": t}) for t in state["task_plan"]]
|
|
32
|
+
```
|
|
33
|
+
Best for: Independent tasks that can run concurrently.
|
|
34
|
+
|
|
35
|
+
### 5. Human-in-the-Loop Gate
|
|
36
|
+
```python
|
|
37
|
+
from langgraph.types import interrupt
|
|
38
|
+
|
|
39
|
+
def approval_gate(state):
|
|
40
|
+
result = interrupt({"message": "Approve?", "data": state["summary"]})
|
|
41
|
+
return {"approved": result["decision"] == "yes"}
|
|
42
|
+
```
|
|
43
|
+
Best for: Destructive operations requiring human approval.
|
|
44
|
+
|
|
45
|
+
## State Design Principles
|
|
46
|
+
|
|
47
|
+
- Use `Annotated[list, add_messages]` for message accumulation.
|
|
48
|
+
- Use `dict[str, str]` for mappings that grow over time (branch_status, assigned_agents).
|
|
49
|
+
- Keep state flat -- avoid deeply nested structures.
|
|
50
|
+
- Include a `current_task_index` integer for loop-based task execution.
|
package/templates/bundle-ai-agents/skills/agent-orchestration/references/routing-strategies.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Routing Strategies Reference
|
|
2
|
+
|
|
3
|
+
## Strategy 1: Keyword-Based Routing
|
|
4
|
+
|
|
5
|
+
Fast, deterministic, zero-cost. Use as primary router.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
routing_map = {
|
|
9
|
+
"frontend": ["ui", "component", "screen", "react", "css", "layout", "form"],
|
|
10
|
+
"backend": ["api", "endpoint", "database", "service", "entity", "migration"],
|
|
11
|
+
"devops": ["deploy", "pipeline", "docker", "k8s", "ci", "monitoring"],
|
|
12
|
+
"qa": ["test", "coverage", "quality", "e2e", "integration test"],
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Strategy 2: LLM-Based Routing (Fallback)
|
|
17
|
+
|
|
18
|
+
Use when keywords are ambiguous. Costs tokens but handles edge cases.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
async def llm_route(task: dict) -> str:
|
|
22
|
+
response = await llm.ainvoke(f"""
|
|
23
|
+
Classify this task into exactly one category: frontend, backend, devops, qa.
|
|
24
|
+
Task: {task['description']}
|
|
25
|
+
Respond with just the category name.
|
|
26
|
+
""")
|
|
27
|
+
return response.content.strip().lower()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Strategy 3: Embedding Similarity
|
|
31
|
+
|
|
32
|
+
Pre-embed descriptions for each agent type, route by cosine similarity.
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
agent_descriptions = {
|
|
36
|
+
"frontend": "UI components, React, CSS, forms, layouts, user interactions",
|
|
37
|
+
"backend": "REST APIs, business logic, database operations, services",
|
|
38
|
+
"devops": "Docker, CI/CD, deployments, infrastructure, monitoring",
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Fallback Chain
|
|
43
|
+
|
|
44
|
+
1. Try keyword match first (fastest).
|
|
45
|
+
2. If no match, try embedding similarity (medium cost).
|
|
46
|
+
3. If confidence < 0.7, use LLM routing (highest cost, best accuracy).
|
|
47
|
+
4. If LLM is uncertain, default to "backend" and flag for human review.
|
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: api-design
|
|
3
|
-
description:
|
|
3
|
+
description: Design REST APIs with FastAPI or Spring Boot following patterns for versioning, pagination, error handling, and documentation. Use when creating endpoints, defining API contracts, or structuring controllers.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# API Design
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Build production-ready REST APIs with standardized patterns for routing, pagination, error handling, versioning, and OpenAPI documentation.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
## When to Use
|
|
13
|
+
- Creating new REST API endpoints
|
|
14
|
+
- Defining API contracts and response schemas
|
|
15
|
+
- Adding pagination, filtering, or sorting to list endpoints
|
|
16
|
+
- Implementing standardized error handling
|
|
17
|
+
- Setting up API versioning strategy
|
|
18
|
+
- Generating OpenAPI/Swagger documentation
|
|
19
|
+
|
|
20
|
+
## Available Operations
|
|
21
|
+
1. Create CRUD endpoints with FastAPI
|
|
22
|
+
2. Define request/response models with Pydantic
|
|
23
|
+
3. Implement standardized error handling
|
|
24
|
+
4. Add pagination to list endpoints
|
|
25
|
+
5. Configure API versioning
|
|
26
|
+
6. Generate and validate OpenAPI documentation
|
|
27
|
+
|
|
28
|
+
## Multi-Step Workflow
|
|
29
|
+
|
|
30
|
+
### Step 1: Define the REST Contract
|
|
31
|
+
|
|
32
|
+
Map business operations to HTTP methods and paths.
|
|
33
|
+
|
|
34
|
+
| Operation | Method | Path | Status | Body |
|
|
11
35
|
|---|---|---|---|---|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
| Patch | PATCH | `/api/v1/demands/{id}` | 200 |
|
|
17
|
-
|
|
|
36
|
+
| List | GET | `/api/v1/demands` | 200 | Paginated list |
|
|
37
|
+
| Get | GET | `/api/v1/demands/{id}` | 200 | Single object |
|
|
38
|
+
| Create | POST | `/api/v1/demands` | 201 | Created object |
|
|
39
|
+
| Update | PUT | `/api/v1/demands/{id}` | 200 | Updated object |
|
|
40
|
+
| Patch | PATCH | `/api/v1/demands/{id}` | 200 | Updated object |
|
|
41
|
+
| Delete | DELETE | `/api/v1/demands/{id}` | 204 | Empty |
|
|
18
42
|
|
|
19
|
-
|
|
43
|
+
### Step 2: Create the Controller with FastAPI
|
|
20
44
|
|
|
21
45
|
```python
|
|
22
46
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
@@ -56,9 +80,14 @@ async def get_demand(
|
|
|
56
80
|
return result
|
|
57
81
|
```
|
|
58
82
|
|
|
59
|
-
|
|
83
|
+
### Step 3: Implement Error Handling
|
|
84
|
+
|
|
85
|
+
Standardize error responses across all endpoints.
|
|
60
86
|
|
|
61
87
|
```python
|
|
88
|
+
from pydantic import BaseModel
|
|
89
|
+
from fastapi.responses import JSONResponse
|
|
90
|
+
|
|
62
91
|
class ErrorResponse(BaseModel):
|
|
63
92
|
error: str
|
|
64
93
|
message: str
|
|
@@ -68,20 +97,28 @@ class ErrorResponse(BaseModel):
|
|
|
68
97
|
async def domain_exception_handler(request, exc: DomainException):
|
|
69
98
|
return JSONResponse(
|
|
70
99
|
status_code=422,
|
|
71
|
-
content=ErrorResponse(error="domain_error", message=str(exc)).
|
|
100
|
+
content=ErrorResponse(error="domain_error", message=str(exc)).model_dump()
|
|
72
101
|
)
|
|
73
102
|
|
|
74
103
|
@app.exception_handler(NotFoundException)
|
|
75
104
|
async def not_found_handler(request, exc: NotFoundException):
|
|
76
105
|
return JSONResponse(
|
|
77
106
|
status_code=404,
|
|
78
|
-
content=ErrorResponse(error="not_found", message=str(exc)).
|
|
107
|
+
content=ErrorResponse(error="not_found", message=str(exc)).model_dump()
|
|
79
108
|
)
|
|
80
109
|
```
|
|
81
110
|
|
|
82
|
-
|
|
111
|
+
### Step 4: Add Pagination
|
|
112
|
+
|
|
113
|
+
Create a reusable pagination response model.
|
|
83
114
|
|
|
84
115
|
```python
|
|
116
|
+
from math import ceil
|
|
117
|
+
from pydantic import BaseModel, model_validator
|
|
118
|
+
from typing import Generic, TypeVar
|
|
119
|
+
|
|
120
|
+
T = TypeVar("T")
|
|
121
|
+
|
|
85
122
|
class PaginatedResponse(BaseModel, Generic[T]):
|
|
86
123
|
items: list[T]
|
|
87
124
|
total: int
|
|
@@ -95,6 +132,78 @@ class PaginatedResponse(BaseModel, Generic[T]):
|
|
|
95
132
|
return values
|
|
96
133
|
```
|
|
97
134
|
|
|
98
|
-
|
|
135
|
+
### Step 5: Configure Versioning
|
|
136
|
+
|
|
137
|
+
Use path-based versioning: `/api/v1/`, `/api/v2/`.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from fastapi import FastAPI
|
|
141
|
+
|
|
142
|
+
app = FastAPI(title="Maestro API", version="1.0.0")
|
|
143
|
+
|
|
144
|
+
# Mount versioned routers
|
|
145
|
+
app.include_router(demands_v1_router, prefix="/api/v1")
|
|
146
|
+
app.include_router(demands_v2_router, prefix="/api/v2")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Rule**: Keep v1 running until all clients have migrated to v2.
|
|
150
|
+
|
|
151
|
+
### Step 6: Validate the API
|
|
152
|
+
|
|
153
|
+
Test endpoints and verify OpenAPI docs.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Run the API server
|
|
157
|
+
uvicorn src.main:app --reload --port 8000
|
|
158
|
+
|
|
159
|
+
# Test an endpoint
|
|
160
|
+
curl -s http://localhost:8000/api/v1/demands?page=1&size=10 | python -m json.tool
|
|
161
|
+
|
|
162
|
+
# Verify OpenAPI schema is valid
|
|
163
|
+
curl -s http://localhost:8000/openapi.json | python -m json.tool > /dev/null && echo "Valid OpenAPI schema"
|
|
164
|
+
|
|
165
|
+
# Run API tests
|
|
166
|
+
pytest tests/api/ -v
|
|
167
|
+
```
|
|
99
168
|
|
|
100
|
-
|
|
169
|
+
## Resources
|
|
170
|
+
- `references/rest-conventions.md` - Complete REST naming and status code conventions
|
|
171
|
+
- `references/pydantic-patterns.md` - Common Pydantic model patterns for API schemas
|
|
172
|
+
|
|
173
|
+
## Examples
|
|
174
|
+
|
|
175
|
+
### Example 1: Build a Complete CRUD API
|
|
176
|
+
User asks: "Create a full CRUD API for managing tasks."
|
|
177
|
+
Response approach:
|
|
178
|
+
1. Define the 6 REST operations (list, get, create, update, patch, delete)
|
|
179
|
+
2. Create Pydantic models: `CreateTaskRequest`, `UpdateTaskRequest`, `TaskResponse`
|
|
180
|
+
3. Create `PaginatedResponse[TaskResponse]` for the list endpoint
|
|
181
|
+
4. Wire each endpoint to its corresponding use case
|
|
182
|
+
5. Add error handlers for `NotFoundException` and `ValidationError`
|
|
183
|
+
6. Test all endpoints with `pytest` and `httpx.AsyncClient`
|
|
184
|
+
|
|
185
|
+
### Example 2: Add Filtering and Sorting
|
|
186
|
+
User asks: "Add status filtering and date sorting to the demands list endpoint."
|
|
187
|
+
Response approach:
|
|
188
|
+
1. Add query parameters: `status: str | None`, `sort_by: str = "created_at"`, `sort_order: str = "desc"`
|
|
189
|
+
2. Pass parameters to the use case
|
|
190
|
+
3. Update the repository query to support filtering and ordering
|
|
191
|
+
4. Add index on the filtered/sorted columns if not present
|
|
192
|
+
5. Test with: `curl "http://localhost:8000/api/v1/demands?status=active&sort_by=created_at&sort_order=desc"`
|
|
193
|
+
|
|
194
|
+
### Example 3: Add API Authentication
|
|
195
|
+
User asks: "Protect our endpoints with JWT authentication."
|
|
196
|
+
Response approach:
|
|
197
|
+
1. Create a `get_current_user` dependency that validates JWT tokens
|
|
198
|
+
2. Add the dependency to protected endpoints
|
|
199
|
+
3. Create a `/auth/token` endpoint for token generation
|
|
200
|
+
4. Add 401 and 403 error handlers
|
|
201
|
+
5. Update OpenAPI schema with security definitions
|
|
202
|
+
|
|
203
|
+
## Notes
|
|
204
|
+
- Controllers should be thin: parse request -> call use case -> format response
|
|
205
|
+
- Always use Pydantic models for request validation (never trust raw input)
|
|
206
|
+
- Use `response_model` in route decorators to enforce response schema
|
|
207
|
+
- Pagination defaults: page=1, size=20, max size=100
|
|
208
|
+
- Path-based versioning (`/api/v1/`) is the simplest and most maintainable approach
|
|
209
|
+
- Generate OpenAPI docs automatically -- never maintain them manually
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Pydantic Patterns Reference
|
|
2
|
+
|
|
3
|
+
## Request Models
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from pydantic import BaseModel, Field, EmailStr
|
|
7
|
+
|
|
8
|
+
class CreateDemandRequest(BaseModel):
|
|
9
|
+
description: str = Field(..., min_length=10, max_length=1000)
|
|
10
|
+
requester: str = Field(..., min_length=1)
|
|
11
|
+
priority: str = Field(default="medium", pattern="^(low|medium|high|critical)$")
|
|
12
|
+
|
|
13
|
+
class UpdateDemandRequest(BaseModel):
|
|
14
|
+
description: str | None = Field(None, min_length=10, max_length=1000)
|
|
15
|
+
priority: str | None = Field(None, pattern="^(low|medium|high|critical)$")
|
|
16
|
+
status: str | None = Field(None, pattern="^(created|planned|in_progress|completed)$")
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Response Models
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from datetime import datetime
|
|
23
|
+
|
|
24
|
+
class DemandResponse(BaseModel):
|
|
25
|
+
id: str
|
|
26
|
+
description: str
|
|
27
|
+
status: str
|
|
28
|
+
requester: str
|
|
29
|
+
created_at: datetime
|
|
30
|
+
updated_at: datetime
|
|
31
|
+
|
|
32
|
+
model_config = {"from_attributes": True}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Pagination
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from math import ceil
|
|
39
|
+
from typing import Generic, TypeVar
|
|
40
|
+
|
|
41
|
+
T = TypeVar("T")
|
|
42
|
+
|
|
43
|
+
class PaginatedResponse(BaseModel, Generic[T]):
|
|
44
|
+
items: list[T]
|
|
45
|
+
total: int
|
|
46
|
+
page: int
|
|
47
|
+
size: int
|
|
48
|
+
pages: int
|
|
49
|
+
|
|
50
|
+
@model_validator(mode="before")
|
|
51
|
+
def calc_pages(cls, values):
|
|
52
|
+
if values.get("size", 0) > 0:
|
|
53
|
+
values["pages"] = ceil(values["total"] / values["size"])
|
|
54
|
+
return values
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Validation Patterns
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pydantic import field_validator
|
|
61
|
+
|
|
62
|
+
class CreateUserRequest(BaseModel):
|
|
63
|
+
email: EmailStr
|
|
64
|
+
username: str = Field(..., min_length=3, max_length=50)
|
|
65
|
+
|
|
66
|
+
@field_validator("username")
|
|
67
|
+
@classmethod
|
|
68
|
+
def username_alphanumeric(cls, v: str) -> str:
|
|
69
|
+
if not v.replace("_", "").replace("-", "").isalnum():
|
|
70
|
+
raise ValueError("Username must be alphanumeric (with _ and -)")
|
|
71
|
+
return v.lower()
|
|
72
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# REST Conventions Reference
|
|
2
|
+
|
|
3
|
+
## URL Naming
|
|
4
|
+
|
|
5
|
+
- Use plural nouns: `/demands`, `/tasks`, `/users`
|
|
6
|
+
- Use kebab-case for multi-word resources: `/task-assignments`
|
|
7
|
+
- Nest for relationships: `/demands/{id}/tasks`
|
|
8
|
+
- Maximum 2 levels of nesting
|
|
9
|
+
- Query parameters for filtering: `?status=active&sort_by=created_at`
|
|
10
|
+
|
|
11
|
+
## HTTP Methods
|
|
12
|
+
|
|
13
|
+
| Method | Idempotent | Safe | Use For |
|
|
14
|
+
|---|---|---|---|
|
|
15
|
+
| GET | Yes | Yes | Read resources |
|
|
16
|
+
| POST | No | No | Create resources |
|
|
17
|
+
| PUT | Yes | No | Full update (replace) |
|
|
18
|
+
| PATCH | No | No | Partial update |
|
|
19
|
+
| DELETE | Yes | No | Remove resources |
|
|
20
|
+
|
|
21
|
+
## Status Codes
|
|
22
|
+
|
|
23
|
+
| Code | Meaning | When to Use |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| 200 | OK | Successful GET, PUT, PATCH |
|
|
26
|
+
| 201 | Created | Successful POST |
|
|
27
|
+
| 204 | No Content | Successful DELETE |
|
|
28
|
+
| 400 | Bad Request | Malformed request body |
|
|
29
|
+
| 401 | Unauthorized | Missing or invalid authentication |
|
|
30
|
+
| 403 | Forbidden | Authenticated but not authorized |
|
|
31
|
+
| 404 | Not Found | Resource does not exist |
|
|
32
|
+
| 409 | Conflict | Duplicate resource or state conflict |
|
|
33
|
+
| 422 | Unprocessable Entity | Valid syntax but business rule violation |
|
|
34
|
+
| 500 | Internal Server Error | Unexpected server failure |
|
|
35
|
+
|
|
36
|
+
## Error Response Format
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"error": "not_found",
|
|
41
|
+
"message": "Demand with id 'abc-123' not found",
|
|
42
|
+
"details": ["Check the demand ID and try again"]
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Headers
|
|
47
|
+
|
|
48
|
+
- `Content-Type: application/json` on all responses
|
|
49
|
+
- `Location: /api/v1/demands/{id}` on 201 Created
|
|
50
|
+
- `X-Request-Id: uuid` for tracing
|
|
51
|
+
- `X-Total-Count: 42` for pagination metadata (optional)
|