sweagent 0.0.2 → 0.0.3
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 +829 -1072
- package/dist/index.cjs +341 -449
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +504 -966
- package/dist/index.d.ts +504 -966
- package/dist/index.js +341 -449
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<h1 align="center">sweagent</h1>
|
|
3
3
|
<p align="center">
|
|
4
|
-
<strong>The
|
|
4
|
+
<strong>The Deep Thinking layer that makes Cursor, Claude Code, and Codex 10x more effective.</strong>
|
|
5
5
|
</p>
|
|
6
6
|
<p align="center">
|
|
7
|
-
|
|
7
|
+
Deep, multi-stage reasoning before a single line of code is written. Domain-specialized agent pipelines generate structured blueprints -- requirements, data models, API contracts, auth flows, and architecture specs -- through iterative LLM calls and sub-agent decomposition. Hand the result to your coding agent.
|
|
8
8
|
</p>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
@@ -16,15 +16,20 @@
|
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
18
|
<p align="center">
|
|
19
|
-
<a href="#
|
|
19
|
+
<a href="#the-problem">The Problem</a> •
|
|
20
20
|
<a href="#use-with-cursor-claude-code-and-codex">Use with Coding Agents</a> •
|
|
21
|
-
<a href="#
|
|
21
|
+
<a href="#why-sweagent">Why sweagent?</a> •
|
|
22
|
+
<a href="#deep-reasoning-philosophy">Deep Reasoning</a> •
|
|
23
|
+
<a href="#how-it-works">How It Works</a> •
|
|
24
|
+
<a href="#features">Features</a> •
|
|
25
|
+
<a href="#planning-pipeline">Planning Pipeline</a> •
|
|
22
26
|
<a href="#full-pipeline">Full Pipeline</a> •
|
|
23
|
-
<a href="#
|
|
27
|
+
<a href="#domain-agent-modules">Modules</a> •
|
|
24
28
|
<a href="#getting-started">Getting Started</a> •
|
|
29
|
+
<a href="#installation">Installation</a> •
|
|
25
30
|
<a href="#architecture">Architecture</a> •
|
|
26
31
|
<a href="#api-reference">API Reference</a> •
|
|
27
|
-
<a href="#
|
|
32
|
+
<a href="#reference">Reference</a> •
|
|
28
33
|
<a href="#examples">Examples</a> •
|
|
29
34
|
<a href="#contributing">Contributing</a>
|
|
30
35
|
</p>
|
|
@@ -33,65 +38,58 @@
|
|
|
33
38
|
|
|
34
39
|
## Table of Contents
|
|
35
40
|
|
|
36
|
-
- [
|
|
41
|
+
- [The Problem](#the-problem)
|
|
37
42
|
- [Use with Cursor, Claude Code, and Codex](#use-with-cursor-claude-code-and-codex)
|
|
38
43
|
- [Why sweagent?](#why-sweagent)
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
41
|
-
- [Planning Pipeline](#planning-pipeline)
|
|
44
|
+
- [Deep Reasoning Philosophy](#deep-reasoning-philosophy)
|
|
45
|
+
- [How It Works](#how-it-works)
|
|
42
46
|
- [Features](#features)
|
|
43
|
-
- [
|
|
47
|
+
- [Planning Pipeline](#planning-pipeline)
|
|
48
|
+
- [Full Pipeline](#full-pipeline)
|
|
49
|
+
- [Domain Agent Modules](#domain-agent-modules)
|
|
44
50
|
- [Getting Started](#getting-started)
|
|
51
|
+
- [Installation](#installation)
|
|
45
52
|
- [Architecture](#architecture)
|
|
46
53
|
- [API Reference](#api-reference)
|
|
47
|
-
- [
|
|
54
|
+
- [Reference](#reference)
|
|
48
55
|
- [Examples](#examples)
|
|
49
|
-
- [Configuration Reference](#configuration-reference)
|
|
50
|
-
- [FAQ](#faq)
|
|
51
|
-
- [Troubleshooting](#troubleshooting)
|
|
52
56
|
- [Contributing](#contributing)
|
|
53
57
|
- [License](#license)
|
|
54
58
|
|
|
55
59
|
---
|
|
56
60
|
|
|
57
|
-
##
|
|
61
|
+
## The Problem
|
|
58
62
|
|
|
59
|
-
AI coding agents -- Claude Code, Codex
|
|
63
|
+
AI coding agents -- Cursor, Claude Code, Codex -- are powerful executors, but they fail at planning. Hand one a vague requirement and it guesses a tech stack, skips data modeling, forgets auth, and produces half-finished code. Enterprise teams need the same rigor from AI that they expect from senior engineers: structured discovery, explicit requirements, deliberate design, and traceable decisions.
|
|
60
64
|
|
|
61
|
-
**sweagent
|
|
65
|
+
**Without sweagent**, a coding agent receives `"build a task manager"` and immediately starts writing code:
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
| **Next.js Builder** | `runNextjsBuilderAgent` | `route-planner`, `api-route-generator` | Next.js App Router config |
|
|
77
|
-
| **Execution Plan** | `runExecutionPlannerAgent` | `edge-case-analyzer`, `testing-strategist` | Phased implementation plan |
|
|
78
|
-
| **Hello World** | `runHelloWorldAgent` | -- | Template module for custom agents |
|
|
67
|
+
- Picks a random framework (maybe Express, maybe Fastify, who knows)
|
|
68
|
+
- Invents a database schema on the fly, misses relationships
|
|
69
|
+
- Forgets authentication entirely
|
|
70
|
+
- Skips error handling and edge cases
|
|
71
|
+
- Produces something that sort-of runs but needs a rewrite
|
|
72
|
+
|
|
73
|
+
**With sweagent**, the coding agent receives a structured blueprint before writing a single line:
|
|
74
|
+
|
|
75
|
+
- **11-section markdown plan** with tech stack, data models, API routes, auth flow, implementation order, edge cases, and testing checklist
|
|
76
|
+
- **Structured JSON requirements** with actors, user flows, stories, and module breakdowns
|
|
77
|
+
- **Database schemas** with exact field types, relationships, indexes, and validation rules
|
|
78
|
+
- **API contracts** with endpoints, methods, request/response shapes, and auth requirements
|
|
79
|
+
- **Frontend architecture** with pages, components, routing, and state management
|
|
79
80
|
|
|
80
81
|
Each pipeline walks through structured stages -- discovery, analysis, design, synthesis -- not a single LLM call. The result is a professional-grade artifact that a coding agent can execute step-by-step, or that a human architect can review and approve.
|
|
81
82
|
|
|
82
83
|
```typescript
|
|
83
|
-
import {
|
|
84
|
+
import { runPlanningAgent } from 'sweagent';
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
const { planning, plan } = await runPlanningWithResult({
|
|
86
|
+
const result = await runPlanningAgent({
|
|
87
87
|
input: 'Task manager app with user auth, task CRUD, assignments, and a dashboard',
|
|
88
88
|
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
console.log(plan); // Full markdown blueprint
|
|
94
|
-
}
|
|
91
|
+
console.log('Plan is implementation-ready. Hand it to your coding agent.');
|
|
92
|
+
console.log(result.output); // Full markdown blueprint
|
|
95
93
|
```
|
|
96
94
|
|
|
97
95
|
TypeScript-first, built on the Vercel AI SDK, ships with all provider SDKs (OpenAI, Anthropic, Google). Set your API keys and go.
|
|
@@ -119,15 +117,15 @@ flowchart LR
|
|
|
119
117
|
Generate a plan, save it to your project, and reference it in Cursor chat or `.cursor/rules/`:
|
|
120
118
|
|
|
121
119
|
```typescript
|
|
122
|
-
import {
|
|
120
|
+
import { runPlanningAgent } from 'sweagent';
|
|
123
121
|
import { writeFileSync } from 'fs';
|
|
124
122
|
|
|
125
|
-
const
|
|
123
|
+
const result = await runPlanningAgent({
|
|
126
124
|
input: 'E-commerce with users, products, cart, checkout, admin dashboard',
|
|
127
125
|
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
128
126
|
});
|
|
129
127
|
|
|
130
|
-
writeFileSync('plan.md',
|
|
128
|
+
writeFileSync('plan.md', result.output);
|
|
131
129
|
// Open plan.md in Cursor and say: "Implement this plan step by step"
|
|
132
130
|
// Or copy plan.md to .cursor/rules/ so every agent session uses it as context
|
|
133
131
|
```
|
|
@@ -137,19 +135,19 @@ writeFileSync('plan.md', plan);
|
|
|
137
135
|
Generate a plan and save it as `CLAUDE.md` or a reference file. Claude Code automatically reads `CLAUDE.md` for project context:
|
|
138
136
|
|
|
139
137
|
```typescript
|
|
140
|
-
import {
|
|
138
|
+
import { runPlanningAgent } from 'sweagent';
|
|
141
139
|
import { writeFileSync } from 'fs';
|
|
142
140
|
|
|
143
|
-
const
|
|
141
|
+
const result = await runPlanningAgent({
|
|
144
142
|
input: 'SaaS dashboard with multi-tenancy, billing, and analytics',
|
|
145
143
|
model: { provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
|
|
146
144
|
});
|
|
147
145
|
|
|
148
146
|
// Option 1: Save as CLAUDE.md for automatic context
|
|
149
|
-
writeFileSync('CLAUDE.md', `# Implementation Plan\n\n${
|
|
147
|
+
writeFileSync('CLAUDE.md', `# Implementation Plan\n\n${result.output}`);
|
|
150
148
|
|
|
151
149
|
// Option 2: Save as plan.md and reference it
|
|
152
|
-
writeFileSync('plan.md',
|
|
150
|
+
writeFileSync('plan.md', result.output);
|
|
153
151
|
// Then tell Claude Code: "Read plan.md and implement phase 1"
|
|
154
152
|
```
|
|
155
153
|
|
|
@@ -190,7 +188,7 @@ The coding agent stops guessing and starts executing a professional-grade bluepr
|
|
|
190
188
|
|
|
191
189
|
### 1. Domain-specialized agents, not generic wrappers
|
|
192
190
|
|
|
193
|
-
Each module is a self-contained agent pipeline purpose-built for its domain. The
|
|
191
|
+
Each module is a self-contained agent pipeline purpose-built for its domain. The Data Modeler doesn't reuse the Planning Agent's prompts -- it has its own `entity-analyzer` and `schema-refiner` sub-agents, its own tools (`design_schema`, `validate_data_model`), and its own output schema. The React Builder has a `graphql-analyzer` and `config-validator`. Every domain gets the specialized treatment it deserves.
|
|
194
192
|
|
|
195
193
|
### 2. Multi-stage pipelines with structured outputs
|
|
196
194
|
|
|
@@ -198,7 +196,7 @@ Every domain agent progresses through deliberate stages -- discovery, requiremen
|
|
|
198
196
|
|
|
199
197
|
### 3. Sub-agent orchestration for complex domains
|
|
200
198
|
|
|
201
|
-
When a domain is too complex for a single agent, sweagent delegates to specialized sub-agents. The
|
|
199
|
+
When a domain is too complex for a single agent, sweagent delegates to specialized sub-agents. The Data Modeler orchestrator spawns an `entity-analyzer` to extract entities and relationships, then a `schema-refiner` to normalize and validate the schema. The React Builder uses a `graphql-analyzer` to parse the schema and a `config-validator` to verify the output. Sub-agents run in isolation with their own context, tools, and models -- then return condensed results to the orchestrator.
|
|
202
200
|
|
|
203
201
|
### 4. Enterprise-quality output, not bullet points
|
|
204
202
|
|
|
@@ -214,222 +212,480 @@ Long-running agents fail when they lose context. sweagent encodes patterns for s
|
|
|
214
212
|
|
|
215
213
|
---
|
|
216
214
|
|
|
217
|
-
##
|
|
215
|
+
## Deep Reasoning Philosophy
|
|
216
|
+
|
|
217
|
+
Coding agents generate code fast. But speed without depth produces fragile, incomplete software. sweagent applies deep reasoning -- structured, multi-stage, decomposed -- so your coding agent receives a blueprint that has been thoroughly worked through before implementation begins.
|
|
218
|
+
|
|
219
|
+
### Multi-Stage Reasoning
|
|
218
220
|
|
|
219
|
-
sweagent
|
|
221
|
+
sweagent never produces one-shot answers. The Planning Agent progresses through four deliberate stages -- discovery, requirements, design, synthesis -- with dedicated LLM calls at each step. Each stage consumes the output of the previous one, building context incrementally rather than cramming everything into a single prompt. Requirements inform design decisions, design decisions shape API contracts, and API contracts feed the implementation order.
|
|
220
222
|
|
|
221
223
|
```mermaid
|
|
222
224
|
flowchart LR
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
Input["Requirement"] --> Discovery["Discovery"]
|
|
226
|
+
Discovery --> Requirements["Requirements"]
|
|
227
|
+
Requirements --> SubReq1["entity-analyzer"]
|
|
228
|
+
Requirements --> SubReq2["page-planner"]
|
|
229
|
+
Requirements --> SubReq3["flow-designer"]
|
|
230
|
+
SubReq1 --> Design["Design"]
|
|
231
|
+
SubReq2 --> Design
|
|
232
|
+
SubReq3 --> Design
|
|
233
|
+
Design --> SubDes1["endpoint-analyzer"]
|
|
234
|
+
Design --> SubDes2["contract-designer"]
|
|
235
|
+
SubDes1 --> Synthesis["Synthesis"]
|
|
236
|
+
SubDes2 --> Synthesis
|
|
237
|
+
Synthesis --> Output["Blueprint"]
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Sub-Agent Decomposition
|
|
241
|
+
|
|
242
|
+
When a domain is too complex for a single agent, sweagent delegates to specialized sub-agents that run in isolation with their own context, tools, and models. The Data Modeler spawns an `entity-analyzer` to extract entities, a `relationship-mapper` for cardinality, and a `schema-refiner` to normalize the result. The React Builder uses a `graphql-analyzer` to parse schema structure and a `config-validator` to check the output. Each sub-agent returns condensed results to its orchestrator, keeping context windows focused and reasoning sharp.
|
|
243
|
+
|
|
244
|
+
### Inference-Time Depth
|
|
245
|
+
|
|
246
|
+
Unlike single-prompt planning tools, sweagent deliberately spends more inference-time compute for higher-quality output. The Planning Agent alone makes 12+ LLM calls across 4 stages and 7 sub-agents. The Data Modeler adds 3 more sub-agent calls. The full pipeline chains 7+ domain agents end-to-end, each with its own multi-call pipeline. This is not a design accident -- more structured reasoning steps produce measurably better blueprints than a single large prompt, the same way a senior engineer produces better architecture by working through each layer separately rather than designing everything at once.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## How It Works
|
|
251
|
+
|
|
252
|
+
sweagent is not a single agent. It is a system of domain-specialized agent pipelines organized across the full software planning lifecycle. Each module can run independently, or you can chain them into a full-stack specification pipeline.
|
|
253
|
+
|
|
254
|
+
```mermaid
|
|
255
|
+
flowchart TB
|
|
256
|
+
subgraph input [Your Idea]
|
|
257
|
+
Idea["Natural language requirement"]
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
subgraph discovery [Discovery Layer]
|
|
225
261
|
ReqGatherer["Requirement Gatherer"]
|
|
226
|
-
|
|
262
|
+
Planning["Planning Agent"]
|
|
227
263
|
end
|
|
228
264
|
|
|
229
|
-
subgraph
|
|
230
|
-
|
|
231
|
-
DbDesigner["DB Designer"]
|
|
265
|
+
subgraph bridge [Bridge]
|
|
266
|
+
FromReqs["from-requirements"]
|
|
232
267
|
end
|
|
233
268
|
|
|
234
|
-
subgraph
|
|
269
|
+
subgraph specialists [Specialist Architects]
|
|
270
|
+
DataModeler["Data Modeler"]
|
|
235
271
|
ApiDesigner["API Designer"]
|
|
236
272
|
AuthDesigner["Auth Designer"]
|
|
273
|
+
BackendArch["Backend Architect"]
|
|
274
|
+
FrontendArch["Frontend Architect"]
|
|
237
275
|
end
|
|
238
276
|
|
|
239
|
-
subgraph
|
|
240
|
-
BackendArch["Backend Architect"]
|
|
277
|
+
subgraph builders [Framework Builders]
|
|
241
278
|
ExpressBuilder["Express Builder"]
|
|
242
279
|
ApolloBuilder["Apollo Builder"]
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
subgraph frontend [Frontend]
|
|
246
|
-
FrontendArch["Frontend Architect"]
|
|
247
280
|
ReactBuilder["React Builder"]
|
|
248
281
|
NextjsBuilder["Next.js Builder"]
|
|
249
282
|
end
|
|
250
283
|
|
|
284
|
+
subgraph execution [Execution]
|
|
285
|
+
ExecPlanner["Execution Planner"]
|
|
286
|
+
CodingAgent["Cursor / Claude Code / Codex"]
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
Idea --> ReqGatherer
|
|
290
|
+
Idea --> Planning
|
|
291
|
+
ReqGatherer -->|"FinalRequirement JSON"| FromReqs
|
|
292
|
+
FromReqs -->|"PlanningContext"| Planning
|
|
251
293
|
ReqGatherer --> DataModeler
|
|
252
|
-
ReqGatherer --> DbDesigner
|
|
253
294
|
DataModeler --> ApiDesigner
|
|
254
|
-
DbDesigner --> ApiDesigner
|
|
255
295
|
ApiDesigner --> AuthDesigner
|
|
256
296
|
AuthDesigner --> BackendArch
|
|
257
|
-
BackendArch --> ExpressBuilder
|
|
258
|
-
BackendArch --> ApolloBuilder
|
|
259
297
|
ApiDesigner --> FrontendArch
|
|
260
|
-
|
|
261
|
-
|
|
298
|
+
BackendArch -->|"Express selected"| ExpressBuilder
|
|
299
|
+
BackendArch -->|"Apollo selected"| ApolloBuilder
|
|
300
|
+
FrontendArch -->|"React selected"| ReactBuilder
|
|
301
|
+
FrontendArch -->|"Next.js selected"| NextjsBuilder
|
|
262
302
|
Planning --> ExecPlanner
|
|
303
|
+
ExecPlanner --> CodingAgent
|
|
304
|
+
builders --> CodingAgent
|
|
305
|
+
specialists --> CodingAgent
|
|
263
306
|
```
|
|
264
307
|
|
|
265
|
-
###
|
|
266
|
-
|
|
267
|
-
Turns a natural-language project description into an implementation-ready markdown plan through 4 stages and 8+ LLM calls. Covers tech stack, data models, API routes, implementation order, edge cases, and testing checklists. Optional LLM validation judges completeness.
|
|
308
|
+
### Three usage modes
|
|
268
309
|
|
|
269
|
-
|
|
270
|
-
import { runPlanningWithResult } from 'sweagent';
|
|
310
|
+
**1. Quick plan** -- Planning Agent standalone. One call, one markdown plan. Best for getting a coding agent started fast.
|
|
271
311
|
|
|
272
|
-
|
|
273
|
-
input: 'E-commerce: users, products, cart, checkout, admin dashboard',
|
|
274
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
275
|
-
});
|
|
276
|
-
// planning === true means the plan passed all validation criteria
|
|
277
|
-
// plan is the full markdown blueprint
|
|
278
|
-
```
|
|
312
|
+
**2. Structured requirements** -- Requirement Gatherer produces typed JSON (actors, flows, stories, modules, database, API). Feed the JSON to specialist modules (Data Modeler, API Designer, etc.) for detailed specs per layer. Use `runPlanningFromRequirements` to bridge requirement-gatherer output into the planning pipeline, skipping redundant discovery stages.
|
|
279
313
|
|
|
280
|
-
**
|
|
314
|
+
**3. Full pipeline** -- Chain all agents together. Each agent's output feeds the next: requirements -> data model -> API design -> auth -> backend architecture -> frontend architecture. Save all specs and hand the directory to your coding agent.
|
|
281
315
|
|
|
282
316
|
---
|
|
283
317
|
|
|
284
|
-
|
|
318
|
+
## Features
|
|
285
319
|
|
|
286
|
-
|
|
320
|
+
| Feature | Description |
|
|
321
|
+
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
322
|
+
| **Domain Agent Modules** | Planning, Requirement Gatherer, Data Modeler, API Designer, Auth Designer, Backend Architect, Express Builder, Apollo Builder, Frontend Architect, React Builder, Next.js Builder, Execution Planner, and Hello World template -- each a self-contained pipeline. |
|
|
323
|
+
| **Multi-Stage Pipelines** | Every domain agent progresses through structured stages (discovery, requirements, design, synthesis) with dedicated LLM calls at each step. No single-shot prompts. |
|
|
324
|
+
| **Sub-Agent Orchestration** | Complex domains delegate to specialized sub-agents (`entity-analyzer`, `schema-refiner`, `graphql-analyzer`, `config-validator`) that run in isolation and return condensed results. |
|
|
325
|
+
| **Structured Outputs** | Requirements as typed JSON (actors, flows, stories, modules). DB schemas with field-level detail. Frontend configs with pages, hooks, and branding. Plans with 11 sections. |
|
|
326
|
+
| **Multi-Provider Models** | Unified API for OpenAI, Anthropic, and Google. One `createModel()` call, zero provider lock-in. |
|
|
327
|
+
| **Type-Safe Tools** | Define tools with Zod schemas; full type inference and validation before execution. Minimal, workflow-oriented tool sets. |
|
|
328
|
+
| **Agent Framework** | Iterative agent loop with tool calling, step callbacks, and configurable max iterations. |
|
|
329
|
+
| **MCP Protocol** | Connect to Model Context Protocol servers over HTTP or stdio. Lazy connection, typed tool invocation. |
|
|
330
|
+
| **Vision** | Image inputs via `model.generateVision()` for vision-capable models. |
|
|
331
|
+
| **Zero Extra Deps** | All provider SDKs (OpenAI, Anthropic, Google) included. Set API keys and run. |
|
|
287
332
|
|
|
288
|
-
|
|
289
|
-
import { runRequirementGathererAgent } from 'sweagent';
|
|
333
|
+
---
|
|
290
334
|
|
|
291
|
-
|
|
292
|
-
input: 'Project management tool with teams, Kanban boards, and time tracking',
|
|
293
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
294
|
-
maxIterations: 15,
|
|
295
|
-
});
|
|
296
|
-
// result.output contains structured JSON: actors, flows, stories, modules
|
|
297
|
-
```
|
|
335
|
+
## Planning Pipeline
|
|
298
336
|
|
|
299
|
-
|
|
337
|
+
The planning module is the centerpiece for AI coding agents. It turns a natural-language project description into a structured, implementation-ready markdown plan through four stages.
|
|
300
338
|
|
|
301
|
-
|
|
339
|
+
### How it works
|
|
302
340
|
|
|
303
|
-
|
|
341
|
+
```mermaid
|
|
342
|
+
flowchart LR
|
|
343
|
+
Input["User Requirement"] --> Discovery["Discovery"]
|
|
344
|
+
Discovery --> Requirements["Requirements"]
|
|
345
|
+
Requirements --> Design["Design"]
|
|
346
|
+
Design --> Synthesis["Synthesis"]
|
|
347
|
+
Synthesis --> Output["plan.md"]
|
|
348
|
+
```
|
|
304
349
|
|
|
305
|
-
|
|
350
|
+
### Stages
|
|
306
351
|
|
|
307
|
-
|
|
308
|
-
|
|
352
|
+
| Stage | What it produces | Sections |
|
|
353
|
+
| ---------------- | -------------------------------------------------- | ------------------------------------------------------------------- |
|
|
354
|
+
| **Discovery** | Understands the project, asks clarifying questions | Project overview |
|
|
355
|
+
| **Requirements** | 4 sequential LLM calls to flesh out the spec | Tech stack, feature decisions, data models, pages/routes, auth flow |
|
|
356
|
+
| **Design** | 2 sequential LLM calls for technical design | API routes, implementation details |
|
|
357
|
+
| **Synthesis** | Assembles the final plan | Implementation order, edge cases, testing checklist |
|
|
309
358
|
|
|
310
|
-
|
|
311
|
-
input: 'E-commerce: users, orders, products. Admins manage products.',
|
|
312
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
313
|
-
maxIterations: 15,
|
|
314
|
-
});
|
|
315
|
-
// result.output contains the full database schema
|
|
316
|
-
```
|
|
359
|
+
### Output
|
|
317
360
|
|
|
318
|
-
|
|
361
|
+
The plan is a markdown document with these sections:
|
|
319
362
|
|
|
320
|
-
|
|
363
|
+
- **Overview** -- project scope and goals
|
|
364
|
+
- **Tech Stack** -- languages, frameworks, database, auth approach
|
|
365
|
+
- **Feature Decisions** -- what to build and what to defer
|
|
366
|
+
- **Data Models** -- schemas, relationships, fields
|
|
367
|
+
- **Pages and Routes** -- frontend structure
|
|
368
|
+
- **Authentication Flow** -- auth strategy and implementation
|
|
369
|
+
- **API Routes** -- endpoints, methods, request/response shapes
|
|
370
|
+
- **Implementation Details** -- architecture decisions, file structure
|
|
371
|
+
- **Execution Plan** -- phased implementation order
|
|
372
|
+
- **Edge Cases** -- error handling, boundary conditions
|
|
373
|
+
- **Testing Checklist** -- what to verify at each phase
|
|
321
374
|
|
|
322
|
-
###
|
|
375
|
+
### Two modes
|
|
323
376
|
|
|
324
|
-
|
|
377
|
+
**One-shot mode** -- pass a requirement, get a plan:
|
|
325
378
|
|
|
326
379
|
```typescript
|
|
327
|
-
import {
|
|
380
|
+
import { runPlanningAgent } from 'sweagent';
|
|
328
381
|
|
|
329
|
-
const result = await
|
|
330
|
-
input: '
|
|
331
|
-
model: { provider: '
|
|
332
|
-
maxIterations: 15,
|
|
382
|
+
const result = await runPlanningAgent({
|
|
383
|
+
input: 'Fitness app with workouts, nutrition tracking, and social features',
|
|
384
|
+
model: { provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
|
|
333
385
|
});
|
|
334
|
-
|
|
386
|
+
console.log(result.output); // Full plan markdown
|
|
335
387
|
```
|
|
336
388
|
|
|
337
|
-
**
|
|
338
|
-
|
|
339
|
-
---
|
|
340
|
-
|
|
341
|
-
### Data Modeler Agent
|
|
342
|
-
|
|
343
|
-
Designs data models for MongoDB or PostgreSQL with entities, fields, indexes, and relationships. Uses three sub-agents for entity analysis, relationship mapping, and schema refinement.
|
|
389
|
+
**Interactive chat mode** -- multi-turn conversation where you refine the plan:
|
|
344
390
|
|
|
345
391
|
```typescript
|
|
346
|
-
import {
|
|
392
|
+
import { processPlanningChat } from 'sweagent';
|
|
393
|
+
import type { PlanningContext } from 'sweagent';
|
|
347
394
|
|
|
348
|
-
|
|
349
|
-
|
|
395
|
+
let context: PlanningContext | null = null;
|
|
396
|
+
|
|
397
|
+
// Turn 1: describe the project
|
|
398
|
+
const turn1 = await processPlanningChat('Build a task manager with teams', context, {
|
|
350
399
|
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
351
|
-
maxIterations: 15,
|
|
352
400
|
});
|
|
353
|
-
|
|
354
|
-
|
|
401
|
+
context = turn1.context;
|
|
402
|
+
console.log(turn1.message); // Assistant asks clarifying questions
|
|
403
|
+
console.log(turn1.pendingQuestions); // ["What auth provider?", ...]
|
|
355
404
|
|
|
356
|
-
|
|
405
|
+
// Turn 2: answer and advance
|
|
406
|
+
const turn2 = await processPlanningChat('Use NextAuth with GitHub OAuth', context, {
|
|
407
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
408
|
+
});
|
|
409
|
+
context = turn2.context;
|
|
357
410
|
|
|
358
|
-
|
|
411
|
+
// Continue until turn.planMarkdown is set (plan complete)
|
|
412
|
+
```
|
|
359
413
|
|
|
360
|
-
###
|
|
414
|
+
### Requirements to plan (the bridge)
|
|
361
415
|
|
|
362
|
-
|
|
416
|
+
When you already have structured requirements from the Requirement Gatherer, `runPlanningFromRequirements` converts the `FinalRequirement` JSON into a `PlanningContext` pre-filled at the design stage, skipping the redundant discovery and requirements stages:
|
|
363
417
|
|
|
364
418
|
```typescript
|
|
365
|
-
import {
|
|
419
|
+
import { runRequirementGathererAgent, runPlanningFromRequirements } from 'sweagent';
|
|
366
420
|
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
421
|
+
const model = { provider: 'openai', model: 'gpt-4o-mini' } as const;
|
|
422
|
+
|
|
423
|
+
// Step 1: Gather structured requirements (actors, flows, stories, modules, DB)
|
|
424
|
+
const reqResult = await runRequirementGathererAgent({
|
|
425
|
+
input: 'Task manager with teams, Kanban boards, and time tracking',
|
|
426
|
+
model,
|
|
370
427
|
maxIterations: 15,
|
|
371
428
|
});
|
|
372
|
-
// result.output: ApiDesign JSON with REST endpoints and/or GraphQL operations
|
|
373
|
-
```
|
|
374
429
|
|
|
375
|
-
|
|
430
|
+
// Step 2: Convert requirements into a planning context and generate the plan
|
|
431
|
+
// Skips discovery + requirements stages; begins at design
|
|
432
|
+
const planResult = await runPlanningFromRequirements({
|
|
433
|
+
requirement: JSON.parse(reqResult.output),
|
|
434
|
+
model,
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
console.log(planResult.output); // Full implementation plan as markdown
|
|
438
|
+
```
|
|
376
439
|
|
|
377
440
|
---
|
|
378
441
|
|
|
379
|
-
|
|
442
|
+
## Full Pipeline
|
|
380
443
|
|
|
381
|
-
|
|
444
|
+
Chain multiple agents together to go from a vague idea to implementation-ready specs for every layer of your stack. Each agent's output feeds the next.
|
|
382
445
|
|
|
383
446
|
```typescript
|
|
384
|
-
import {
|
|
447
|
+
import {
|
|
448
|
+
runRequirementGathererAgent,
|
|
449
|
+
runDataModelerAgent,
|
|
450
|
+
runApiDesignerAgent,
|
|
451
|
+
runAuthDesignerAgent,
|
|
452
|
+
runBackendArchitectAgent,
|
|
453
|
+
runFrontendArchitectAgent,
|
|
454
|
+
runExecutionPlannerAgent,
|
|
455
|
+
} from 'sweagent';
|
|
456
|
+
import { writeFileSync } from 'fs';
|
|
385
457
|
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
458
|
+
const model = { provider: 'openai', model: 'gpt-4o-mini' } as const;
|
|
459
|
+
|
|
460
|
+
// Step 1: Gather structured requirements
|
|
461
|
+
const requirements = await runRequirementGathererAgent({
|
|
462
|
+
input: 'Project management SaaS with teams, Kanban boards, time tracking, and billing',
|
|
463
|
+
model,
|
|
389
464
|
maxIterations: 15,
|
|
390
465
|
});
|
|
391
|
-
// result.output: AuthDesign JSON with strategy, flows, middleware, roles, policies
|
|
392
|
-
```
|
|
393
466
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
467
|
+
// Step 2: Design the data model from requirements
|
|
468
|
+
const dataModel = await runDataModelerAgent({
|
|
469
|
+
input: `Design a data model based on these requirements:\n${requirements.output}`,
|
|
470
|
+
model,
|
|
471
|
+
maxIterations: 15,
|
|
472
|
+
});
|
|
397
473
|
|
|
398
|
-
|
|
474
|
+
// Step 3: Design the API from the data model
|
|
475
|
+
const apiDesign = await runApiDesignerAgent({
|
|
476
|
+
input: `Design REST API for this data model:\n${dataModel.output}`,
|
|
477
|
+
model,
|
|
478
|
+
maxIterations: 15,
|
|
479
|
+
});
|
|
399
480
|
|
|
400
|
-
|
|
481
|
+
// Step 4: Design auth from the requirements and API
|
|
482
|
+
const authDesign = await runAuthDesignerAgent({
|
|
483
|
+
input: `Design auth for this project:\nRequirements: ${requirements.output}\nAPI: ${apiDesign.output}`,
|
|
484
|
+
model,
|
|
485
|
+
maxIterations: 15,
|
|
486
|
+
});
|
|
401
487
|
|
|
402
|
-
|
|
403
|
-
|
|
488
|
+
// Step 5: Plan backend architecture
|
|
489
|
+
const backendDesign = await runBackendArchitectAgent({
|
|
490
|
+
input: `Design backend:\nData model: ${dataModel.output}\nAPI: ${apiDesign.output}\nAuth: ${authDesign.output}`,
|
|
491
|
+
model,
|
|
492
|
+
maxIterations: 15,
|
|
493
|
+
});
|
|
404
494
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
495
|
+
// Step 6: Plan frontend architecture
|
|
496
|
+
const frontendDesign = await runFrontendArchitectAgent({
|
|
497
|
+
input: `Design frontend:\nAPI: ${apiDesign.output}\nRequirements: ${requirements.output}`,
|
|
498
|
+
model,
|
|
408
499
|
maxIterations: 15,
|
|
409
500
|
});
|
|
410
|
-
|
|
501
|
+
|
|
502
|
+
// Save all specs for your coding agent
|
|
503
|
+
writeFileSync('specs/requirements.json', requirements.output);
|
|
504
|
+
writeFileSync('specs/data-model.json', dataModel.output);
|
|
505
|
+
writeFileSync('specs/api-design.json', apiDesign.output);
|
|
506
|
+
writeFileSync('specs/auth-design.json', authDesign.output);
|
|
507
|
+
writeFileSync('specs/backend-design.json', backendDesign.output);
|
|
508
|
+
writeFileSync('specs/frontend-design.json', frontendDesign.output);
|
|
509
|
+
|
|
510
|
+
// Now hand the specs/ directory to Cursor, Claude Code, or Codex
|
|
511
|
+
// "Implement the backend using specs/backend-design.json and specs/data-model.json"
|
|
411
512
|
```
|
|
412
513
|
|
|
413
|
-
|
|
514
|
+
You can also run individual agents standalone -- each works independently with natural-language input. The pipeline approach gives you maximum control over each design decision.
|
|
414
515
|
|
|
415
516
|
---
|
|
416
517
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
Plans backend architecture including framework selection, services, middleware, routes, and folder structure. Routes to Express Builder or Apollo Builder based on framework choice.
|
|
518
|
+
## Domain Agent Modules
|
|
420
519
|
|
|
421
|
-
|
|
422
|
-
import { runBackendArchitectAgent } from 'sweagent';
|
|
520
|
+
Each module is a self-contained domain agent with its own orchestrator, pipeline stages, tools, sub-agents, and output format. All are exported from the main package.
|
|
423
521
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
522
|
+
| Stage | Agent | Sub-Agents | Output |
|
|
523
|
+
| ------------------- | ----------------------------- | ---------------------------------------------------------- | ------------------------------------------------- |
|
|
524
|
+
| **Planning** | `runPlanningAgent` | -- | Implementation-ready markdown plan (11 sections) |
|
|
525
|
+
| **Requirements** | `runRequirementGathererAgent` | -- | Structured JSON (actors, flows, stories, modules) |
|
|
526
|
+
| **Data Modeling** | `runDataModelerAgent` | `entity-analyzer`, `relationship-mapper`, `schema-refiner` | MongoDB/PostgreSQL schemas |
|
|
527
|
+
| **API Design** | `runApiDesignerAgent` | `endpoint-analyzer`, `contract-designer` | REST and/or GraphQL API design |
|
|
528
|
+
| **Auth Design** | `runAuthDesignerAgent` | `security-analyzer`, `flow-designer` | Auth strategy, flows, middleware, RBAC |
|
|
529
|
+
| **Backend Arch.** | `runBackendArchitectAgent` | `framework-selector`, `service-planner` | Backend architecture (Express/Apollo) |
|
|
530
|
+
| **Express Builder** | `runExpressBuilderAgent` | `route-generator`, `middleware-configurator` | Express.js REST API config |
|
|
531
|
+
| **Apollo Builder** | `runApolloBuilderAgent` | `schema-generator`, `resolver-planner` | Apollo GraphQL subgraph config |
|
|
532
|
+
| **Frontend Arch.** | `runFrontendArchitectAgent` | `page-planner`, `component-analyzer`, `framework-selector` | Frontend architecture (React/Next.js) |
|
|
533
|
+
| **React Builder** | `runReactBuilderAgent` | `graphql-analyzer`, `config-validator` | React + Vite app config from GraphQL |
|
|
534
|
+
| **Next.js Builder** | `runNextjsBuilderAgent` | `route-planner`, `api-route-generator` | Next.js App Router config |
|
|
535
|
+
| **Execution Plan** | `runExecutionPlannerAgent` | `edge-case-analyzer`, `testing-strategist` | Phased implementation plan |
|
|
536
|
+
| **Hello World** | `runAgent` + `helloWorldTool` | -- | Template module for custom agents |
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
### Planning Agent
|
|
541
|
+
|
|
542
|
+
Turns a natural-language project description into an implementation-ready markdown plan through 4 stages and 12+ LLM calls. Covers tech stack, data models, API routes, implementation order, edge cases, and testing checklists.
|
|
543
|
+
|
|
544
|
+
| Attribute | Detail |
|
|
545
|
+
| ----------------- | ----------------------------------------------------------------------- |
|
|
546
|
+
| **Stages** | Discovery, Requirements (4 LLM calls), Design (2 LLM calls), Synthesis |
|
|
547
|
+
| **Sub-Agents** | -- |
|
|
548
|
+
| **Tools** | -- (pipeline stages, not tool-based) |
|
|
549
|
+
| **Output Format** | Markdown plan (11 sections) |
|
|
550
|
+
| **Modes** | One-shot (`runPlanningAgent`), interactive chat (`processPlanningChat`) |
|
|
551
|
+
|
|
552
|
+
```typescript
|
|
553
|
+
import { runPlanningAgent } from 'sweagent';
|
|
554
|
+
|
|
555
|
+
const result = await runPlanningAgent({
|
|
556
|
+
input: 'E-commerce: users, orders, products. Admins manage products.',
|
|
557
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
558
|
+
});
|
|
559
|
+
console.log(result.output); // Full markdown blueprint
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
See [Planning Pipeline](#planning-pipeline) for stage-by-stage details.
|
|
563
|
+
|
|
564
|
+
---
|
|
565
|
+
|
|
566
|
+
### Requirement Gatherer Agent
|
|
567
|
+
|
|
568
|
+
Produces structured JSON requirements -- not prose. Unlike the Planning module (markdown output), the Requirement Gatherer extracts typed data that downstream systems can consume programmatically.
|
|
569
|
+
|
|
570
|
+
| Attribute | Detail |
|
|
571
|
+
| ----------------- | ------------------------------------------------------------------------------------- |
|
|
572
|
+
| **Stages** | Discovery, Requirements, Design, Synthesis |
|
|
573
|
+
| **Sub-Agents** | -- |
|
|
574
|
+
| **Tools** | Stage-specific tools |
|
|
575
|
+
| **Output Format** | Structured JSON |
|
|
576
|
+
| **Schemas** | Actors, User Flows, User Stories, Modules, Database Design, API Design |
|
|
577
|
+
| **Modes** | One-shot (`runRequirementGathererAgent`), interactive chat (`processRequirementChat`) |
|
|
578
|
+
|
|
579
|
+
**Output structure:** Actors (with permissions), User Flows (step-by-step sequences), User Stories (with acceptance criteria), Modules (with CRUD operations), Database Design (schemas, relationships), API Design (REST/GraphQL endpoints).
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
import { runRequirementGathererAgent } from 'sweagent';
|
|
583
|
+
|
|
584
|
+
const result = await runRequirementGathererAgent({
|
|
585
|
+
input: 'Project management tool with teams and Kanban boards',
|
|
586
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
587
|
+
maxIterations: 15,
|
|
588
|
+
});
|
|
589
|
+
// result.output: structured JSON with actors, flows, stories, modules
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
---
|
|
593
|
+
|
|
594
|
+
### Data Modeler Agent
|
|
595
|
+
|
|
596
|
+
Designs data models for MongoDB or PostgreSQL with entities, fields, indexes, and relationships. Uses three sub-agents for entity analysis, relationship mapping, and schema refinement.
|
|
597
|
+
|
|
598
|
+
| Attribute | Detail |
|
|
599
|
+
| ----------------- | ---------------------------------------------------------------------------- |
|
|
600
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
601
|
+
| **Sub-Agents** | `entity-analyzer`, `relationship-mapper`, `schema-refiner` |
|
|
602
|
+
| **Tools** | `design_schema`, `design_schema_pro`, `refine_schema`, `validate_data_model` |
|
|
603
|
+
| **Output Format** | Data model JSON (entities, fields, indexes, relationships) |
|
|
604
|
+
| **Databases** | MongoDB, PostgreSQL |
|
|
605
|
+
|
|
606
|
+
```typescript
|
|
607
|
+
import { runDataModelerAgent } from 'sweagent';
|
|
608
|
+
|
|
609
|
+
const result = await runDataModelerAgent({
|
|
610
|
+
input: 'SaaS platform with organizations, users, projects, and billing',
|
|
611
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
612
|
+
maxIterations: 15,
|
|
613
|
+
});
|
|
614
|
+
// result.output: DataModelDesign JSON with entities, fields, indexes, relationships
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
---
|
|
618
|
+
|
|
619
|
+
### API Designer Agent
|
|
620
|
+
|
|
621
|
+
Designs REST and/or GraphQL APIs from data models, producing endpoint definitions with request/response contracts, auth requirements, and operation details.
|
|
622
|
+
|
|
623
|
+
| Attribute | Detail |
|
|
624
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------- |
|
|
625
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
626
|
+
| **Sub-Agents** | `endpoint-analyzer` (derives endpoints from data model), `contract-designer` (designs request/response) |
|
|
627
|
+
| **Tools** | `design_api`, `design_api_pro`, `validate_api` |
|
|
628
|
+
| **Output Format** | API design JSON (REST endpoints and/or GraphQL operations) |
|
|
629
|
+
|
|
630
|
+
```typescript
|
|
631
|
+
import { runApiDesignerAgent } from 'sweagent';
|
|
632
|
+
|
|
633
|
+
const result = await runApiDesignerAgent({
|
|
634
|
+
input: 'Design REST API for a task manager with users, projects, and tasks',
|
|
635
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
636
|
+
maxIterations: 15,
|
|
637
|
+
});
|
|
638
|
+
// result.output: ApiDesign JSON with REST endpoints and/or GraphQL operations
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
---
|
|
642
|
+
|
|
643
|
+
### Auth Designer Agent
|
|
644
|
+
|
|
645
|
+
Designs authentication and authorization systems with strategies, flows, middleware, roles, and security policies.
|
|
646
|
+
|
|
647
|
+
| Attribute | Detail |
|
|
648
|
+
| ----------------- | ------------------------------------------------------------------------------------------ |
|
|
649
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
650
|
+
| **Sub-Agents** | `security-analyzer` (analyzes security requirements), `flow-designer` (designs auth flows) |
|
|
651
|
+
| **Tools** | `design_auth`, `validate_auth` |
|
|
652
|
+
| **Output Format** | Auth design JSON (strategy, flows, middleware, roles, policies) |
|
|
653
|
+
|
|
654
|
+
```typescript
|
|
655
|
+
import { runAuthDesignerAgent } from 'sweagent';
|
|
656
|
+
|
|
657
|
+
const result = await runAuthDesignerAgent({
|
|
658
|
+
input: 'JWT auth with email/password, Google OAuth, role-based access (admin, member)',
|
|
659
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
660
|
+
maxIterations: 15,
|
|
661
|
+
});
|
|
662
|
+
// result.output: AuthDesign JSON with strategy, flows, middleware, roles, policies
|
|
430
663
|
```
|
|
431
664
|
|
|
432
|
-
|
|
665
|
+
---
|
|
666
|
+
|
|
667
|
+
### Backend Architect Agent
|
|
668
|
+
|
|
669
|
+
Plans backend architecture including framework selection, services, middleware, routes, and folder structure. Routes to Express Builder or Apollo Builder based on framework choice.
|
|
670
|
+
|
|
671
|
+
| Attribute | Detail |
|
|
672
|
+
| ----------------- | ------------------------------------------------------------------------------- |
|
|
673
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
674
|
+
| **Sub-Agents** | `framework-selector`, `service-planner` |
|
|
675
|
+
| **Tools** | `design_backend`, `validate_backend` |
|
|
676
|
+
| **Output Format** | Backend design JSON (framework, services, middleware, routes, folder structure) |
|
|
677
|
+
| **Frameworks** | Express, Apollo, or both |
|
|
678
|
+
|
|
679
|
+
```typescript
|
|
680
|
+
import { runBackendArchitectAgent } from 'sweagent';
|
|
681
|
+
|
|
682
|
+
const result = await runBackendArchitectAgent({
|
|
683
|
+
input: 'REST API backend with user auth, CRUD operations, and file uploads',
|
|
684
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
685
|
+
maxIterations: 15,
|
|
686
|
+
});
|
|
687
|
+
// result.output: BackendDesign JSON with framework, services, middleware, routes
|
|
688
|
+
```
|
|
433
689
|
|
|
434
690
|
---
|
|
435
691
|
|
|
@@ -437,6 +693,13 @@ const result = await runBackendArchitectAgent({
|
|
|
437
693
|
|
|
438
694
|
Generates Express.js REST API configuration with routers, models, middleware, and environment variables.
|
|
439
695
|
|
|
696
|
+
| Attribute | Detail |
|
|
697
|
+
| ----------------- | ----------------------------------------------------------- |
|
|
698
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
699
|
+
| **Sub-Agents** | `route-generator`, `middleware-configurator` |
|
|
700
|
+
| **Tools** | `generate_express`, `scaffold_express`, `validate_express` |
|
|
701
|
+
| **Output Format** | Express config JSON (routers, models, middleware, env vars) |
|
|
702
|
+
|
|
440
703
|
```typescript
|
|
441
704
|
import { runExpressBuilderAgent } from 'sweagent';
|
|
442
705
|
|
|
@@ -448,14 +711,19 @@ const result = await runExpressBuilderAgent({
|
|
|
448
711
|
// result.output: ExpressConfig JSON with routers, models, middleware, env vars
|
|
449
712
|
```
|
|
450
713
|
|
|
451
|
-
**Sub-agents:** `route-generator`, `middleware-configurator` | **Tools:** `generate_express`, `scaffold_express`, `validate_express` | **Output:** Express config JSON
|
|
452
|
-
|
|
453
714
|
---
|
|
454
715
|
|
|
455
716
|
### Apollo Builder Agent
|
|
456
717
|
|
|
457
718
|
Generates Apollo GraphQL subgraph configuration with modules, types, resolvers, datasources, and Federation v2 support.
|
|
458
719
|
|
|
720
|
+
| Attribute | Detail |
|
|
721
|
+
| ----------------- | --------------------------------------------------------------------- |
|
|
722
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
723
|
+
| **Sub-Agents** | `schema-generator`, `resolver-planner` |
|
|
724
|
+
| **Tools** | `generate_subgraph`, `scaffold_subgraph`, `validate_subgraph` |
|
|
725
|
+
| **Output Format** | Apollo subgraph config JSON (modules, types, operations, datasources) |
|
|
726
|
+
|
|
459
727
|
```typescript
|
|
460
728
|
import { runApolloBuilderAgent } from 'sweagent';
|
|
461
729
|
|
|
@@ -467,7 +735,54 @@ const result = await runApolloBuilderAgent({
|
|
|
467
735
|
// result.output: SubgraphConfig JSON with modules, types, operations, datasources
|
|
468
736
|
```
|
|
469
737
|
|
|
470
|
-
|
|
738
|
+
---
|
|
739
|
+
|
|
740
|
+
### Frontend Architect Agent
|
|
741
|
+
|
|
742
|
+
Plans frontend architecture including pages, components, routing, and state management. Routes to React Builder or Next.js Builder based on framework selection.
|
|
743
|
+
|
|
744
|
+
| Attribute | Detail |
|
|
745
|
+
| ----------------- | ------------------------------------------------------------------- |
|
|
746
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
747
|
+
| **Sub-Agents** | `page-planner`, `component-analyzer`, `framework-selector` |
|
|
748
|
+
| **Output Format** | Frontend design JSON (pages, components, state management, routing) |
|
|
749
|
+
| **Frameworks** | React + Vite, Next.js |
|
|
750
|
+
|
|
751
|
+
```typescript
|
|
752
|
+
import { runFrontendArchitectAgent } from 'sweagent';
|
|
753
|
+
|
|
754
|
+
const result = await runFrontendArchitectAgent({
|
|
755
|
+
input: 'Dashboard app with analytics, settings, and user management pages',
|
|
756
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
757
|
+
maxIterations: 15,
|
|
758
|
+
});
|
|
759
|
+
// result.output: FrontendDesign JSON with pages, components, state management, routing
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
---
|
|
763
|
+
|
|
764
|
+
### React Builder Agent
|
|
765
|
+
|
|
766
|
+
Generates complete frontend application configuration from a GraphQL schema. A `graphql-analyzer` sub-agent parses the schema structure, and a `config-validator` sub-agent verifies the output. Produces app config, modules, pages, fields, and API hooks.
|
|
767
|
+
|
|
768
|
+
| Attribute | Detail |
|
|
769
|
+
| ----------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
770
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
771
|
+
| **Sub-Agents** | `graphql-analyzer` (parses GraphQL schema structure), `config-validator` (validates frontend config output) |
|
|
772
|
+
| **Tools** | `generate_frontend`, `generate_feature_breakdown`, `validate_frontend_config` |
|
|
773
|
+
| **Output Format** | React app config JSON (app, modules, pages, fields, API hooks, branding) |
|
|
774
|
+
| **Schemas** | App config, User config, Page config, Field config, Branding |
|
|
775
|
+
|
|
776
|
+
```typescript
|
|
777
|
+
import { runReactBuilderAgent } from 'sweagent';
|
|
778
|
+
|
|
779
|
+
const result = await runReactBuilderAgent({
|
|
780
|
+
input: 'GraphQL schema: type User { id: ID! name: String! } type Task { ... }',
|
|
781
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
782
|
+
maxIterations: 15,
|
|
783
|
+
});
|
|
784
|
+
// result.output: frontend config JSON with pages, fields, hooks, branding
|
|
785
|
+
```
|
|
471
786
|
|
|
472
787
|
---
|
|
473
788
|
|
|
@@ -475,6 +790,13 @@ const result = await runApolloBuilderAgent({
|
|
|
475
790
|
|
|
476
791
|
Generates Next.js App Router configuration with pages, layouts, API routes, server actions, and middleware.
|
|
477
792
|
|
|
793
|
+
| Attribute | Detail |
|
|
794
|
+
| ----------------- | ---------------------------------------------------------------------------- |
|
|
795
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
796
|
+
| **Sub-Agents** | `route-planner`, `api-route-generator` |
|
|
797
|
+
| **Tools** | `generate_nextjs`, `validate_nextjs` |
|
|
798
|
+
| **Output Format** | Next.js config JSON (pages, layouts, API routes, server actions, middleware) |
|
|
799
|
+
|
|
478
800
|
```typescript
|
|
479
801
|
import { runNextjsBuilderAgent } from 'sweagent';
|
|
480
802
|
|
|
@@ -486,14 +808,19 @@ const result = await runNextjsBuilderAgent({
|
|
|
486
808
|
// result.output: NextjsConfig JSON with pages, layouts, API routes, server actions
|
|
487
809
|
```
|
|
488
810
|
|
|
489
|
-
**Sub-agents:** `route-planner`, `api-route-generator` | **Tools:** `generate_nextjs`, `validate_nextjs` | **Output:** Next.js config JSON
|
|
490
|
-
|
|
491
811
|
---
|
|
492
812
|
|
|
493
813
|
### Execution Planner Agent
|
|
494
814
|
|
|
495
815
|
Creates phased implementation execution plans from plan sections, with edge case analysis and testing checklists.
|
|
496
816
|
|
|
817
|
+
| Attribute | Detail |
|
|
818
|
+
| ----------------- | --------------------------------------------------------------------------------------- |
|
|
819
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
820
|
+
| **Sub-Agents** | `edge-case-analyzer`, `testing-strategist` |
|
|
821
|
+
| **Tools** | `create_execution_plan`, `validate_execution_plan` |
|
|
822
|
+
| **Output Format** | Execution plan JSON (phases, edge cases, testing checklist, security/performance notes) |
|
|
823
|
+
|
|
497
824
|
```typescript
|
|
498
825
|
import { runExecutionPlannerAgent } from 'sweagent';
|
|
499
826
|
|
|
@@ -505,8 +832,6 @@ const result = await runExecutionPlannerAgent({
|
|
|
505
832
|
// result.output: ExecutionPlan JSON with phases, edge cases, testing checklist
|
|
506
833
|
```
|
|
507
834
|
|
|
508
|
-
**Sub-agents:** `edge-case-analyzer`, `testing-strategist` | **Tools:** `create_execution_plan`, `validate_execution_plan` | **Output:** Execution plan JSON
|
|
509
|
-
|
|
510
835
|
---
|
|
511
836
|
|
|
512
837
|
### Hello World (Template)
|
|
@@ -526,202 +851,125 @@ const result = await runAgent({
|
|
|
526
851
|
|
|
527
852
|
---
|
|
528
853
|
|
|
529
|
-
##
|
|
854
|
+
## Getting Started
|
|
530
855
|
|
|
531
|
-
|
|
856
|
+
### Level 1: Model invocation
|
|
532
857
|
|
|
533
|
-
|
|
858
|
+
```typescript
|
|
859
|
+
import { createModel } from 'sweagent';
|
|
534
860
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
861
|
+
const model = createModel({
|
|
862
|
+
provider: 'openai', // 'openai' | 'anthropic' | 'google'
|
|
863
|
+
model: 'gpt-4o-mini',
|
|
864
|
+
temperature: 0.7,
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
const response = await model.invoke([
|
|
868
|
+
{ role: 'user', content: 'Explain TypeScript in one sentence.' },
|
|
869
|
+
]);
|
|
870
|
+
console.log(response.text);
|
|
544
871
|
```
|
|
545
872
|
|
|
546
|
-
###
|
|
547
|
-
|
|
548
|
-
| Stage | What it produces | Sections |
|
|
549
|
-
| ---------------- | -------------------------------------------------- | ------------------------------------------------------------------- |
|
|
550
|
-
| **Discovery** | Understands the project, asks clarifying questions | Project overview |
|
|
551
|
-
| **Requirements** | 4 sequential LLM calls to flesh out the spec | Tech stack, feature decisions, data models, pages/routes, auth flow |
|
|
552
|
-
| **Design** | 2 sequential LLM calls for technical design | API routes, implementation details |
|
|
553
|
-
| **Synthesis** | Assembles the final plan | Implementation order, edge cases, testing checklist |
|
|
554
|
-
|
|
555
|
-
### Output
|
|
556
|
-
|
|
557
|
-
The plan is a markdown document with these sections:
|
|
558
|
-
|
|
559
|
-
- **Overview** — project scope and goals
|
|
560
|
-
- **Tech Stack** — languages, frameworks, database, auth approach
|
|
561
|
-
- **Feature Decisions** — what to build and what to defer
|
|
562
|
-
- **Data Models** — schemas, relationships, fields
|
|
563
|
-
- **Pages and Routes** — frontend structure
|
|
564
|
-
- **Authentication Flow** — auth strategy and implementation
|
|
565
|
-
- **API Routes** — endpoints, methods, request/response shapes
|
|
566
|
-
- **Implementation Details** — architecture decisions, file structure
|
|
567
|
-
- **Execution Plan** — phased implementation order
|
|
568
|
-
- **Edge Cases** — error handling, boundary conditions
|
|
569
|
-
- **Testing Checklist** — what to verify at each phase
|
|
570
|
-
|
|
571
|
-
### Two modes
|
|
572
|
-
|
|
573
|
-
**One-shot mode** — pass a requirement, get a plan:
|
|
574
|
-
|
|
575
|
-
```typescript
|
|
576
|
-
import { runPlanningAgent } from 'sweagent';
|
|
577
|
-
|
|
578
|
-
const result = await runPlanningAgent({
|
|
579
|
-
input: 'Fitness app with workouts, nutrition tracking, and social features',
|
|
580
|
-
model: { provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
|
|
581
|
-
});
|
|
582
|
-
console.log(result.output); // Full plan markdown
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
**With validation** — run the plan through an LLM judge that checks completeness:
|
|
873
|
+
### Level 2: Define tools
|
|
586
874
|
|
|
587
875
|
```typescript
|
|
588
|
-
import {
|
|
876
|
+
import { defineTool } from 'sweagent';
|
|
877
|
+
import { z } from 'zod';
|
|
589
878
|
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
879
|
+
const calculatorTool = defineTool({
|
|
880
|
+
name: 'calculator',
|
|
881
|
+
description: 'Perform math calculations',
|
|
882
|
+
input: z.object({
|
|
883
|
+
expression: z.string().describe('Math expression to evaluate'),
|
|
884
|
+
}),
|
|
885
|
+
handler: async ({ expression }) => {
|
|
886
|
+
const result = eval(expression); // Use a safe math parser in production
|
|
887
|
+
return { result };
|
|
888
|
+
},
|
|
593
889
|
});
|
|
594
|
-
// planning === true means the plan passed all validation criteria
|
|
595
890
|
```
|
|
596
891
|
|
|
597
|
-
|
|
892
|
+
### Level 3: Agent loop
|
|
598
893
|
|
|
599
894
|
```typescript
|
|
600
|
-
import {
|
|
601
|
-
import
|
|
602
|
-
|
|
603
|
-
let context: PlanningContext | null = null;
|
|
895
|
+
import { runAgent, createModel, defineTool, createToolSet } from 'sweagent';
|
|
896
|
+
import { z } from 'zod';
|
|
604
897
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
898
|
+
const calculatorTool = defineTool({
|
|
899
|
+
name: 'calculator',
|
|
900
|
+
description: 'Perform math calculations',
|
|
901
|
+
input: z.object({ expression: z.string() }),
|
|
902
|
+
handler: async ({ expression }) => ({ result: String(eval(expression)) }),
|
|
608
903
|
});
|
|
609
|
-
context = turn1.context;
|
|
610
|
-
console.log(turn1.message); // Assistant asks clarifying questions
|
|
611
|
-
console.log(turn1.pendingQuestions); // ["What auth provider?", ...]
|
|
612
904
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
905
|
+
const result = await runAgent({
|
|
906
|
+
model: createModel({ provider: 'openai', model: 'gpt-4o-mini' }),
|
|
907
|
+
tools: createToolSet({ calculator: calculatorTool }),
|
|
908
|
+
systemPrompt: 'You are a helpful assistant. Use the calculator when needed.',
|
|
909
|
+
input: 'What is 25 multiplied by 4?',
|
|
910
|
+
maxIterations: 10,
|
|
911
|
+
onStep: step => console.log(`Step ${step.iteration}:`, step.toolCalls ?? step.content),
|
|
616
912
|
});
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
// Continue until turn.planMarkdown is set (plan complete)
|
|
913
|
+
console.log(result.output);
|
|
620
914
|
```
|
|
621
915
|
|
|
622
|
-
###
|
|
623
|
-
|
|
624
|
-
The LLM validator (`validatePlanForCodingAgent`) checks that the plan includes:
|
|
625
|
-
|
|
626
|
-
1. Clear project overview and scope
|
|
627
|
-
2. Tech stack specified (languages, frameworks, database, auth)
|
|
628
|
-
3. Implementation order or phased steps
|
|
629
|
-
4. Concrete actionable steps (files, routes, APIs, or models)
|
|
630
|
-
5. Data model, authentication, and API surface addressed
|
|
631
|
-
|
|
632
|
-
---
|
|
633
|
-
|
|
634
|
-
## Full Pipeline
|
|
635
|
-
|
|
636
|
-
Chain multiple agents together to go from a vague idea to implementation-ready specs for every layer of your stack. Each agent's output feeds the next.
|
|
916
|
+
### Level 4: Subagents
|
|
637
917
|
|
|
638
918
|
```typescript
|
|
639
919
|
import {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
runFrontendArchitectAgent,
|
|
646
|
-
runExecutionPlannerAgent,
|
|
920
|
+
defineSubagent,
|
|
921
|
+
createSubagentToolSet,
|
|
922
|
+
runAgent,
|
|
923
|
+
createModel,
|
|
924
|
+
createToolSet,
|
|
647
925
|
} from 'sweagent';
|
|
648
|
-
import { writeFileSync } from 'fs';
|
|
649
926
|
|
|
650
|
-
const model = { provider: 'openai', model: 'gpt-4o-mini' }
|
|
927
|
+
const model = createModel({ provider: 'openai', model: 'gpt-4o-mini' });
|
|
651
928
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
maxIterations: 15,
|
|
929
|
+
const researcher = defineSubagent({
|
|
930
|
+
name: 'researcher',
|
|
931
|
+
description: 'Research a topic and return a short summary',
|
|
932
|
+
systemPrompt: 'You are a researcher. Answer concisely.',
|
|
657
933
|
});
|
|
934
|
+
const subagentTools = createSubagentToolSet([researcher], { parentModel: model });
|
|
935
|
+
const tools = createToolSet({ ...subagentTools });
|
|
658
936
|
|
|
659
|
-
|
|
660
|
-
const dataModel = await runDataModelerAgent({
|
|
661
|
-
input: `Design a data model based on these requirements:\n${requirements.output}`,
|
|
937
|
+
const result = await runAgent({
|
|
662
938
|
model,
|
|
663
|
-
|
|
939
|
+
tools,
|
|
940
|
+
systemPrompt: 'You can delegate research to subagent_researcher.',
|
|
941
|
+
input: 'Research the history of TypeScript and summarize in 2 sentences.',
|
|
942
|
+
maxIterations: 10,
|
|
664
943
|
});
|
|
944
|
+
```
|
|
665
945
|
|
|
666
|
-
|
|
667
|
-
const apiDesign = await runApiDesignerAgent({
|
|
668
|
-
input: `Design REST API for this data model:\n${dataModel.output}`,
|
|
669
|
-
model,
|
|
670
|
-
maxIterations: 15,
|
|
671
|
-
});
|
|
946
|
+
### Level 5: Planning pipeline
|
|
672
947
|
|
|
673
|
-
|
|
674
|
-
const authDesign = await runAuthDesignerAgent({
|
|
675
|
-
input: `Design auth for this project:\nRequirements: ${requirements.output}\nAPI: ${apiDesign.output}`,
|
|
676
|
-
model,
|
|
677
|
-
maxIterations: 15,
|
|
678
|
-
});
|
|
948
|
+
Generate an implementation plan for a coding agent:
|
|
679
949
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
input: `Design backend:\nData model: ${dataModel.output}\nAPI: ${apiDesign.output}\nAuth: ${authDesign.output}`,
|
|
683
|
-
model,
|
|
684
|
-
maxIterations: 15,
|
|
685
|
-
});
|
|
950
|
+
```typescript
|
|
951
|
+
import { runPlanningAgent } from 'sweagent';
|
|
686
952
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
model,
|
|
691
|
-
maxIterations: 15,
|
|
953
|
+
const result = await runPlanningAgent({
|
|
954
|
+
input: 'E-commerce site: users, products, cart, checkout, admin dashboard',
|
|
955
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
692
956
|
});
|
|
693
957
|
|
|
694
|
-
//
|
|
695
|
-
writeFileSync('specs/requirements.json', requirements.output);
|
|
696
|
-
writeFileSync('specs/data-model.json', dataModel.output);
|
|
697
|
-
writeFileSync('specs/api-design.json', apiDesign.output);
|
|
698
|
-
writeFileSync('specs/auth-design.json', authDesign.output);
|
|
699
|
-
writeFileSync('specs/backend-design.json', backendDesign.output);
|
|
700
|
-
writeFileSync('specs/frontend-design.json', frontendDesign.output);
|
|
701
|
-
|
|
702
|
-
// Now hand the specs/ directory to Cursor, Claude Code, or Codex
|
|
703
|
-
// "Implement the backend using specs/backend-design.json and specs/data-model.json"
|
|
958
|
+
console.log(result.output); // Full markdown blueprint
|
|
704
959
|
```
|
|
705
960
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
---
|
|
961
|
+
### Level 6: MCP integration
|
|
709
962
|
|
|
710
|
-
|
|
963
|
+
```typescript
|
|
964
|
+
import { BaseMcpClient } from 'sweagent';
|
|
711
965
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
| **Multi-Provider Models** | Unified API for OpenAI, Anthropic, and Google. One `createModel()` call, zero provider lock-in. |
|
|
720
|
-
| **Type-Safe Tools** | Define tools with Zod schemas; full type inference and validation before execution. Minimal, workflow-oriented tool sets. |
|
|
721
|
-
| **Agent Framework** | Iterative agent loop with tool calling, step callbacks, and configurable max iterations. |
|
|
722
|
-
| **MCP Protocol** | Connect to Model Context Protocol servers over HTTP or stdio. Lazy connection, typed tool invocation. |
|
|
723
|
-
| **Vision** | Image inputs via `model.generateVision()` for vision-capable models. |
|
|
724
|
-
| **Zero Extra Deps** | All provider SDKs (OpenAI, Anthropic, Google) included. Set API keys and run. |
|
|
966
|
+
const config = BaseMcpClient.resolveConfig(
|
|
967
|
+
{ url: 'https://your-mcp-server.example.com' },
|
|
968
|
+
{ envPrefix: 'MCP' }
|
|
969
|
+
);
|
|
970
|
+
const client = new BaseMcpClient({ name: 'my-app', version: '1.0.0' }, config);
|
|
971
|
+
const result = await client.callTool('tool_name', { arg: 'value' });
|
|
972
|
+
```
|
|
725
973
|
|
|
726
974
|
---
|
|
727
975
|
|
|
@@ -783,192 +1031,68 @@ npm run example -- examples/hello-world/01-hello-world.ts
|
|
|
783
1031
|
|
|
784
1032
|
---
|
|
785
1033
|
|
|
786
|
-
##
|
|
1034
|
+
## Architecture
|
|
787
1035
|
|
|
788
|
-
###
|
|
1036
|
+
### System overview
|
|
789
1037
|
|
|
790
|
-
```
|
|
791
|
-
|
|
1038
|
+
```mermaid
|
|
1039
|
+
graph TB
|
|
1040
|
+
subgraph Client[Client Application]
|
|
1041
|
+
App["Your App / Cursor / Claude Code / Codex"]
|
|
1042
|
+
end
|
|
792
1043
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1044
|
+
subgraph DomainAgents[Domain Agent Modules]
|
|
1045
|
+
Planning["Planning"]
|
|
1046
|
+
ReqGatherer["Requirement Gatherer"]
|
|
1047
|
+
DataModeler["Data Modeler"]
|
|
1048
|
+
ApiDesigner["API Designer"]
|
|
1049
|
+
AuthDesigner["Auth Designer"]
|
|
1050
|
+
BackendArch["Backend Architect"]
|
|
1051
|
+
ExpressBuilder["Express Builder"]
|
|
1052
|
+
ApolloBuilder["Apollo Builder"]
|
|
1053
|
+
FrontendArch["Frontend Architect"]
|
|
1054
|
+
ReactBuilder["React Builder"]
|
|
1055
|
+
NextjsBuilder["Next.js Builder"]
|
|
1056
|
+
ExecPlanner["Execution Planner"]
|
|
1057
|
+
end
|
|
798
1058
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
]
|
|
802
|
-
|
|
1059
|
+
subgraph Framework[Shared Framework]
|
|
1060
|
+
Models["Model Abstraction"]
|
|
1061
|
+
ToolFW["Tool Framework"]
|
|
1062
|
+
AgentLoop["Agent Loop"]
|
|
1063
|
+
SubAgentOrch["Sub-Agent Orchestration"]
|
|
1064
|
+
MCP["MCP Protocol"]
|
|
1065
|
+
end
|
|
1066
|
+
|
|
1067
|
+
subgraph Providers[AI Providers]
|
|
1068
|
+
OpenAI["OpenAI"]
|
|
1069
|
+
Anthropic["Anthropic"]
|
|
1070
|
+
Google["Google"]
|
|
1071
|
+
end
|
|
1072
|
+
|
|
1073
|
+
App --> DomainAgents
|
|
1074
|
+
DomainAgents --> Framework
|
|
1075
|
+
Framework --> Providers
|
|
803
1076
|
```
|
|
804
1077
|
|
|
805
|
-
###
|
|
1078
|
+
### Domain agent pipeline flow
|
|
806
1079
|
|
|
807
|
-
|
|
808
|
-
import { defineTool } from 'sweagent';
|
|
809
|
-
import { z } from 'zod';
|
|
1080
|
+
Each domain agent follows a structured pipeline. The Planning Agent is representative:
|
|
810
1081
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
},
|
|
821
|
-
});
|
|
1082
|
+
```mermaid
|
|
1083
|
+
flowchart LR
|
|
1084
|
+
Input["User Requirement"] --> Discovery["Discovery Stage"]
|
|
1085
|
+
Discovery --> Requirements["Requirements Stage"]
|
|
1086
|
+
Requirements --> Design["Design Stage"]
|
|
1087
|
+
Design --> Synthesis["Synthesis Stage"]
|
|
1088
|
+
Synthesis --> Plan["Structured Output"]
|
|
1089
|
+
Plan --> Validate["LLM Validator"]
|
|
1090
|
+
Validate --> Output["Validated Result"]
|
|
822
1091
|
```
|
|
823
1092
|
|
|
824
|
-
###
|
|
1093
|
+
### Orchestrator with sub-agents
|
|
825
1094
|
|
|
826
|
-
|
|
827
|
-
import { runAgent, createModel, defineTool, createToolSet } from 'sweagent';
|
|
828
|
-
import { z } from 'zod';
|
|
829
|
-
|
|
830
|
-
const calculatorTool = defineTool({
|
|
831
|
-
name: 'calculator',
|
|
832
|
-
description: 'Perform math calculations',
|
|
833
|
-
input: z.object({ expression: z.string() }),
|
|
834
|
-
handler: async ({ expression }) => ({ result: String(eval(expression)) }),
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
const result = await runAgent({
|
|
838
|
-
model: createModel({ provider: 'openai', model: 'gpt-4o-mini' }),
|
|
839
|
-
tools: createToolSet({ calculator: calculatorTool }),
|
|
840
|
-
systemPrompt: 'You are a helpful assistant. Use the calculator when needed.',
|
|
841
|
-
input: 'What is 25 multiplied by 4?',
|
|
842
|
-
maxIterations: 10,
|
|
843
|
-
onStep: step => console.log(`Step ${step.iteration}:`, step.toolCalls ?? step.content),
|
|
844
|
-
});
|
|
845
|
-
console.log(result.output);
|
|
846
|
-
```
|
|
847
|
-
|
|
848
|
-
### Level 4: Subagents
|
|
849
|
-
|
|
850
|
-
```typescript
|
|
851
|
-
import {
|
|
852
|
-
defineSubagent,
|
|
853
|
-
createSubagentToolSet,
|
|
854
|
-
runAgent,
|
|
855
|
-
createModel,
|
|
856
|
-
createToolSet,
|
|
857
|
-
} from 'sweagent';
|
|
858
|
-
|
|
859
|
-
const model = createModel({ provider: 'openai', model: 'gpt-4o-mini' });
|
|
860
|
-
|
|
861
|
-
const researcher = defineSubagent({
|
|
862
|
-
name: 'researcher',
|
|
863
|
-
description: 'Research a topic and return a short summary',
|
|
864
|
-
systemPrompt: 'You are a researcher. Answer concisely.',
|
|
865
|
-
});
|
|
866
|
-
const subagentTools = createSubagentToolSet([researcher], { parentModel: model });
|
|
867
|
-
const tools = createToolSet({ ...subagentTools });
|
|
868
|
-
|
|
869
|
-
const result = await runAgent({
|
|
870
|
-
model,
|
|
871
|
-
tools,
|
|
872
|
-
systemPrompt: 'You can delegate research to subagent_researcher.',
|
|
873
|
-
input: 'Research the history of TypeScript and summarize in 2 sentences.',
|
|
874
|
-
maxIterations: 10,
|
|
875
|
-
});
|
|
876
|
-
```
|
|
877
|
-
|
|
878
|
-
### Level 5: Planning pipeline
|
|
879
|
-
|
|
880
|
-
Generate an implementation plan for a coding agent:
|
|
881
|
-
|
|
882
|
-
```typescript
|
|
883
|
-
import { runPlanningWithResult } from 'sweagent';
|
|
884
|
-
|
|
885
|
-
const { planning, plan } = await runPlanningWithResult({
|
|
886
|
-
input: 'E-commerce site: users, products, cart, checkout, admin dashboard',
|
|
887
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
888
|
-
});
|
|
889
|
-
|
|
890
|
-
console.log('Ready for coding agent:', planning);
|
|
891
|
-
console.log(plan);
|
|
892
|
-
```
|
|
893
|
-
|
|
894
|
-
### Level 6: MCP integration
|
|
895
|
-
|
|
896
|
-
```typescript
|
|
897
|
-
import { BaseMcpClient } from 'sweagent';
|
|
898
|
-
|
|
899
|
-
const config = BaseMcpClient.resolveConfig(
|
|
900
|
-
{ url: 'https://your-mcp-server.example.com' },
|
|
901
|
-
{ envPrefix: 'MCP' }
|
|
902
|
-
);
|
|
903
|
-
const client = new BaseMcpClient({ name: 'my-app', version: '1.0.0' }, config);
|
|
904
|
-
const result = await client.callTool('tool_name', { arg: 'value' });
|
|
905
|
-
```
|
|
906
|
-
|
|
907
|
-
---
|
|
908
|
-
|
|
909
|
-
## Architecture
|
|
910
|
-
|
|
911
|
-
### System overview
|
|
912
|
-
|
|
913
|
-
```mermaid
|
|
914
|
-
graph TB
|
|
915
|
-
subgraph Client[Client Application]
|
|
916
|
-
App["Your App / Cursor / Claude Code / Codex"]
|
|
917
|
-
end
|
|
918
|
-
|
|
919
|
-
subgraph DomainAgents[Domain Agent Modules]
|
|
920
|
-
Planning["Planning"]
|
|
921
|
-
ReqGatherer["Requirement Gatherer"]
|
|
922
|
-
DataModeler["Data Modeler"]
|
|
923
|
-
DbDesigner["DB Designer"]
|
|
924
|
-
ApiDesigner["API Designer"]
|
|
925
|
-
AuthDesigner["Auth Designer"]
|
|
926
|
-
BackendArch["Backend Architect"]
|
|
927
|
-
ExpressBuilder["Express Builder"]
|
|
928
|
-
ApolloBuilder["Apollo Builder"]
|
|
929
|
-
FrontendArch["Frontend Architect"]
|
|
930
|
-
ReactBuilder["React Builder"]
|
|
931
|
-
NextjsBuilder["Next.js Builder"]
|
|
932
|
-
ExecPlanner["Execution Planner"]
|
|
933
|
-
end
|
|
934
|
-
|
|
935
|
-
subgraph Framework[Shared Framework]
|
|
936
|
-
Models["Model Abstraction"]
|
|
937
|
-
ToolFW["Tool Framework"]
|
|
938
|
-
AgentLoop["Agent Loop"]
|
|
939
|
-
SubAgentOrch["Sub-Agent Orchestration"]
|
|
940
|
-
MCP["MCP Protocol"]
|
|
941
|
-
end
|
|
942
|
-
|
|
943
|
-
subgraph Providers[AI Providers]
|
|
944
|
-
OpenAI["OpenAI"]
|
|
945
|
-
Anthropic["Anthropic"]
|
|
946
|
-
Google["Google"]
|
|
947
|
-
end
|
|
948
|
-
|
|
949
|
-
App --> DomainAgents
|
|
950
|
-
DomainAgents --> Framework
|
|
951
|
-
Framework --> Providers
|
|
952
|
-
```
|
|
953
|
-
|
|
954
|
-
### Domain agent pipeline flow
|
|
955
|
-
|
|
956
|
-
Each domain agent follows a structured pipeline. The Planning Agent is representative:
|
|
957
|
-
|
|
958
|
-
```mermaid
|
|
959
|
-
flowchart LR
|
|
960
|
-
Input["User Requirement"] --> Discovery["Discovery Stage"]
|
|
961
|
-
Discovery --> Requirements["Requirements Stage"]
|
|
962
|
-
Requirements --> Design["Design Stage"]
|
|
963
|
-
Design --> Synthesis["Synthesis Stage"]
|
|
964
|
-
Synthesis --> Plan["Structured Output"]
|
|
965
|
-
Plan --> Validate["LLM Validator"]
|
|
966
|
-
Validate --> Output["Validated Result"]
|
|
967
|
-
```
|
|
968
|
-
|
|
969
|
-
### Orchestrator with sub-agents
|
|
970
|
-
|
|
971
|
-
Domain agents like DB Designer and React Builder delegate to specialized sub-agents:
|
|
1095
|
+
Domain agents like Data Modeler and React Builder delegate to specialized sub-agents:
|
|
972
1096
|
|
|
973
1097
|
```mermaid
|
|
974
1098
|
sequenceDiagram
|
|
@@ -1016,620 +1140,246 @@ sequenceDiagram
|
|
|
1016
1140
|
end
|
|
1017
1141
|
```
|
|
1018
1142
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
## Engineering Deep Dive
|
|
1143
|
+
### Engineering Deep Dive
|
|
1022
1144
|
|
|
1023
|
-
|
|
1145
|
+
#### The problem: long-running coding agents
|
|
1024
1146
|
|
|
1025
1147
|
Coding agents that work across many steps or sessions fail in two ways: they try to do too much in one shot (leaving partial, undocumented work), or they declare the job done too early. Each new session starts with no memory of the last. To make progress across sessions, each run needs a way to get up to speed quickly and leave a clean state for the next run.
|
|
1026
1148
|
|
|
1027
|
-
|
|
1149
|
+
#### Incremental progress pattern
|
|
1028
1150
|
|
|
1029
1151
|
Each session does bounded work: one feature or one clear subtask. The agent updates a progress file and commits what it did. The next session reads progress and git history, chooses the next unfinished item, and continues. This avoids one-shotting the whole project and reduces premature completion.
|
|
1030
1152
|
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
A structured list of requirements (e.g. in JSON) with a status per item gives the agent a clear definition of "done." Agents only mark items passing after verification, keeping scope explicit and making it easy to resume across context windows.
|
|
1034
|
-
|
|
1035
|
-
### Clean state principle
|
|
1036
|
-
|
|
1037
|
-
Every session should end with code that is buildable, documented, and easy to continue from. No half-implemented features, no stray debug code, clear commit messages or progress notes. The orchestration prompts in production modules encode these expectations.
|
|
1038
|
-
|
|
1039
|
-
### Error hierarchy
|
|
1040
|
-
|
|
1041
|
-
| Class | When |
|
|
1042
|
-
| ------------------- | ------------------------------------------------ |
|
|
1043
|
-
| **LibraryError** | Base; all others extend it. |
|
|
1044
|
-
| **ModelError** | Model creation or invoke failed. |
|
|
1045
|
-
| **ToolError** | Tool not found or tool execution failed. |
|
|
1046
|
-
| **ValidationError** | Zod validation failed. |
|
|
1047
|
-
| **AgentError** | Agent reached max iterations without completing. |
|
|
1048
|
-
| **SubagentError** | Subagent config or run failed. |
|
|
1049
|
-
|
|
1050
|
-
All accept an optional `cause` for chaining.
|
|
1051
|
-
|
|
1052
|
-
### Provider adapter pattern
|
|
1053
|
-
|
|
1054
|
-
Models are created via `createModel({ provider, model, ... })`. A shared AI SDK adapter wraps the Vercel AI SDK's `generateText` and normalizes messages, tool schemas, and responses. Each provider has a thin factory that passes the correct `LanguageModel` into this adapter. Provider-specific logic stays in one place; everything else is provider-agnostic.
|
|
1055
|
-
|
|
1056
|
-
### Tool execution safety
|
|
1057
|
-
|
|
1058
|
-
Inputs are validated with Zod before any tool runs. Invalid input produces a **ToolError** with the parse error; the handler is never called with bad data. Handler errors are caught and rethrown as **ToolError** with the original error as cause. The agent loop receives structured tool results (including error payloads) so the model can see failures and retry or adjust.
|
|
1059
|
-
|
|
1060
|
-
---
|
|
1061
|
-
|
|
1062
|
-
## API Reference
|
|
1063
|
-
|
|
1064
|
-
All public APIs are exported from the main package: `import { ... } from 'sweagent'`.
|
|
1065
|
-
|
|
1066
|
-
### Models
|
|
1067
|
-
|
|
1068
|
-
**createModel(config)** — Create a model instance.
|
|
1069
|
-
|
|
1070
|
-
```typescript
|
|
1071
|
-
import { createModel } from 'sweagent';
|
|
1072
|
-
|
|
1073
|
-
const model = createModel({
|
|
1074
|
-
provider: 'openai' | 'anthropic' | 'google',
|
|
1075
|
-
model: string, // e.g. 'gpt-4o', 'claude-sonnet-4-20250514'
|
|
1076
|
-
apiKey?: string, // Uses env var by default
|
|
1077
|
-
temperature?: number,
|
|
1078
|
-
maxOutputTokens?: number,
|
|
1079
|
-
baseUrl?: string,
|
|
1080
|
-
});
|
|
1081
|
-
|
|
1082
|
-
const response = await model.invoke(messages, { tools });
|
|
1083
|
-
// response: { text, toolCalls, usage, finishReason }
|
|
1084
|
-
```
|
|
1085
|
-
|
|
1086
|
-
**Supported models (examples):**
|
|
1087
|
-
|
|
1088
|
-
| Provider | Models |
|
|
1089
|
-
| --------- | ---------------------------------------------------- |
|
|
1090
|
-
| OpenAI | `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo` |
|
|
1091
|
-
| Anthropic | `claude-sonnet-4-20250514`, `claude-3-opus-20240229` |
|
|
1092
|
-
| Google | `gemini-1.5-pro`, `gemini-1.5-flash` |
|
|
1093
|
-
|
|
1094
|
-
**Vision:** `model.generateVision(prompt, images, options)` for image inputs.
|
|
1095
|
-
|
|
1096
|
-
---
|
|
1097
|
-
|
|
1098
|
-
### Tools
|
|
1099
|
-
|
|
1100
|
-
**defineTool(config)** — Define a type-safe tool with Zod schema and handler.
|
|
1101
|
-
|
|
1102
|
-
```typescript
|
|
1103
|
-
import { defineTool } from 'sweagent';
|
|
1104
|
-
import { z } from 'zod';
|
|
1105
|
-
|
|
1106
|
-
const tool = defineTool({
|
|
1107
|
-
name: 'my_tool',
|
|
1108
|
-
description: 'What the tool does',
|
|
1109
|
-
input: z.object({ key: z.string() }),
|
|
1110
|
-
handler: async (parsed, context) => ({ result: parsed.key }),
|
|
1111
|
-
});
|
|
1112
|
-
```
|
|
1113
|
-
|
|
1114
|
-
**createToolSet(tools)** — Build a record of tools for the agent (key = tool name).
|
|
1115
|
-
|
|
1116
|
-
**getTool(toolSet, name)** / **getTools(toolSet)** — Look up one or all tools.
|
|
1117
|
-
|
|
1118
|
-
**executeTool(tool, input, options)** — Run a single tool with input.
|
|
1119
|
-
|
|
1120
|
-
**executeToolByName(toolSet, name, input, options)** — Run by name; throws if tool missing.
|
|
1121
|
-
|
|
1122
|
-
**zodToJsonSchema(schema)** — Convert a Zod schema to JSON Schema (e.g. for MCP).
|
|
1123
|
-
|
|
1124
|
-
---
|
|
1125
|
-
|
|
1126
|
-
### Agents
|
|
1127
|
-
|
|
1128
|
-
**runAgent(config)** — Run the agent loop until the model returns no tool calls or max iterations is reached.
|
|
1129
|
-
|
|
1130
|
-
```typescript
|
|
1131
|
-
import { runAgent } from 'sweagent';
|
|
1132
|
-
|
|
1133
|
-
const result = await runAgent({
|
|
1134
|
-
model,
|
|
1135
|
-
tools: createToolSet({ ... }),
|
|
1136
|
-
systemPrompt: string,
|
|
1137
|
-
input: string,
|
|
1138
|
-
maxIterations?: number, // default 10
|
|
1139
|
-
onStep?: (step: AgentStep) => void,
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
// result: { output, steps, totalUsage, messages }
|
|
1143
|
-
```
|
|
1144
|
-
|
|
1145
|
-
---
|
|
1146
|
-
|
|
1147
|
-
### Subagents
|
|
1148
|
-
|
|
1149
|
-
**defineSubagent(config)** — Define a subagent (name must be kebab-case).
|
|
1150
|
-
|
|
1151
|
-
```typescript
|
|
1152
|
-
import { defineSubagent } from 'sweagent';
|
|
1153
|
-
|
|
1154
|
-
const def = defineSubagent({
|
|
1155
|
-
name: 'my-subagent',
|
|
1156
|
-
description: 'What this subagent does',
|
|
1157
|
-
systemPrompt: '...',
|
|
1158
|
-
tools?: Record<string, Tool>,
|
|
1159
|
-
model?: ModelConfig,
|
|
1160
|
-
maxIterations?: number,
|
|
1161
|
-
disallowedTools?: string[],
|
|
1162
|
-
onStep?: (step) => void,
|
|
1163
|
-
});
|
|
1164
|
-
```
|
|
1165
|
-
|
|
1166
|
-
**runSubagent(definition, input, options)** — Run the subagent in isolation.
|
|
1167
|
-
|
|
1168
|
-
**createSubagentTool(definition, options)** — Expose one subagent as a tool.
|
|
1169
|
-
|
|
1170
|
-
**createSubagentToolSet(definitions, options)** — Build a record of subagent tools (`subagent_<name>`).
|
|
1171
|
-
|
|
1172
|
-
---
|
|
1173
|
-
|
|
1174
|
-
### Planning
|
|
1175
|
-
|
|
1176
|
-
**runPlanningAgent(config)** — One-shot mode: single input, auto-advances through all stages, returns plan markdown.
|
|
1177
|
-
|
|
1178
|
-
```typescript
|
|
1179
|
-
import { runPlanningAgent } from 'sweagent';
|
|
1180
|
-
|
|
1181
|
-
const result = await runPlanningAgent({
|
|
1182
|
-
input: string,
|
|
1183
|
-
model?: ModelConfig,
|
|
1184
|
-
maxIterations?: number,
|
|
1185
|
-
onStep?: (step: AgentStep) => void,
|
|
1186
|
-
logger?: Logger,
|
|
1187
|
-
});
|
|
1188
|
-
// result: AgentResult { output, steps, totalUsage, messages }
|
|
1189
|
-
```
|
|
1190
|
-
|
|
1191
|
-
**runPlanningWithResult(config)** — Runs the planning agent then validates the output with an LLM judge.
|
|
1192
|
-
|
|
1193
|
-
```typescript
|
|
1194
|
-
import { runPlanningWithResult } from 'sweagent';
|
|
1195
|
-
|
|
1196
|
-
const result = await runPlanningWithResult({
|
|
1197
|
-
input: string,
|
|
1198
|
-
model?: ModelConfig,
|
|
1199
|
-
logger?: Logger,
|
|
1200
|
-
});
|
|
1201
|
-
// result: { planning: boolean, plan: string }
|
|
1202
|
-
```
|
|
1203
|
-
|
|
1204
|
-
**processPlanningChat(userMessage, context, config)** — Multi-turn chat mode. Pass `null` context on the first turn.
|
|
1205
|
-
|
|
1206
|
-
```typescript
|
|
1207
|
-
import { processPlanningChat } from 'sweagent';
|
|
1208
|
-
|
|
1209
|
-
const result = await processPlanningChat(userMessage, context, {
|
|
1210
|
-
model?: ModelConfig,
|
|
1211
|
-
maxIterations?: number,
|
|
1212
|
-
onStep?: (step: AgentStep) => void,
|
|
1213
|
-
logger?: Logger,
|
|
1214
|
-
});
|
|
1215
|
-
// result: PlanChatTurnResult { message, context, pendingQuestions, planMarkdown }
|
|
1216
|
-
```
|
|
1217
|
-
|
|
1218
|
-
**validatePlanForCodingAgent(planMarkdown, model, logger)** — LLM-based validation. Returns `{ valid: boolean, feedback?: string }`.
|
|
1219
|
-
|
|
1220
|
-
**assemblePlan(projectName, sections)** — Assemble `PlanSections` into a single markdown string.
|
|
1221
|
-
|
|
1222
|
-
**writePlanToFile(markdown, outputPath)** — Write plan markdown to a file.
|
|
1223
|
-
|
|
1224
|
-
**PlanningContextBuilder** — Fluent builder for `PlanningContext`:
|
|
1225
|
-
|
|
1226
|
-
```typescript
|
|
1227
|
-
import { createPlanningContextBuilder } from 'sweagent';
|
|
1228
|
-
|
|
1229
|
-
const context = createPlanningContextBuilder()
|
|
1230
|
-
.withStage('requirements')
|
|
1231
|
-
.withProjectDescription('Task manager app')
|
|
1232
|
-
.withSections({ overview: '## Overview\n...' })
|
|
1233
|
-
.build();
|
|
1234
|
-
```
|
|
1235
|
-
|
|
1236
|
-
---
|
|
1237
|
-
|
|
1238
|
-
### MCP
|
|
1239
|
-
|
|
1240
|
-
**BaseMcpClient** — Base class for MCP clients. Lazy connection, `callTool(name, args)` for invocation.
|
|
1241
|
-
|
|
1242
|
-
**BaseMcpClient.resolveConfig(options, resolveOpts)** — Build config from options and env (e.g. `MCP_URL`, `MCP_COMMAND`, `MCP_ARGS`).
|
|
1243
|
-
|
|
1244
|
-
---
|
|
1245
|
-
|
|
1246
|
-
### Errors
|
|
1247
|
-
|
|
1248
|
-
| Class | When |
|
|
1249
|
-
| ------------------- | ------------------------------------------------ |
|
|
1250
|
-
| **LibraryError** | Base; all others extend it. |
|
|
1251
|
-
| **ModelError** | Model creation or invoke failed. |
|
|
1252
|
-
| **ToolError** | Tool not found or tool execution failed. |
|
|
1253
|
-
| **ValidationError** | Zod validation failed. |
|
|
1254
|
-
| **AgentError** | Agent reached max iterations without completing. |
|
|
1255
|
-
| **SubagentError** | Subagent config or run failed. |
|
|
1256
|
-
|
|
1257
|
-
All accept an optional `cause` for chaining.
|
|
1258
|
-
|
|
1259
|
-
---
|
|
1260
|
-
|
|
1261
|
-
## Domain Agent Modules
|
|
1262
|
-
|
|
1263
|
-
Each module is a self-contained domain agent with its own orchestrator, pipeline stages, tools, sub-agents, and output format. All are exported from the main package.
|
|
1264
|
-
|
|
1265
|
-
### Planning
|
|
1266
|
-
|
|
1267
|
-
The primary module for powering AI coding agents. Generates implementation-ready markdown plans from natural-language project descriptions.
|
|
1268
|
-
|
|
1269
|
-
| Attribute | Detail |
|
|
1270
|
-
| ----------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
1271
|
-
| **Stages** | Discovery, Requirements (4 LLM calls), Design (2 LLM calls), Synthesis |
|
|
1272
|
-
| **Sub-Agents** | -- |
|
|
1273
|
-
| **Tools** | -- (pipeline stages, not tool-based) |
|
|
1274
|
-
| **Output Format** | Markdown plan (11 sections) |
|
|
1275
|
-
| **Validation** | LLM judge checks completeness and actionability |
|
|
1276
|
-
| **Modes** | One-shot (`runPlanningAgent`), validated (`runPlanningWithResult`), interactive chat (`processPlanningChat`) |
|
|
1277
|
-
|
|
1278
|
-
**Output sections:** Overview, Tech Stack, Feature Decisions, Data Models, Pages and Routes, Authentication Flow, API Routes, Implementation Details, Execution Plan, Edge Cases, Testing Checklist.
|
|
1279
|
-
|
|
1280
|
-
```typescript
|
|
1281
|
-
import { runPlanningWithResult } from 'sweagent';
|
|
1282
|
-
|
|
1283
|
-
const { planning, plan } = await runPlanningWithResult({
|
|
1284
|
-
input: 'E-commerce: users, orders, products. Admins manage products.',
|
|
1285
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1286
|
-
});
|
|
1287
|
-
// planning: boolean -- did the plan pass validation?
|
|
1288
|
-
// plan: string -- full markdown blueprint
|
|
1289
|
-
```
|
|
1290
|
-
|
|
1291
|
-
See [Planning Pipeline](#planning-pipeline) for stage-by-stage details.
|
|
1292
|
-
|
|
1293
|
-
---
|
|
1294
|
-
|
|
1295
|
-
### Requirement Gatherer
|
|
1296
|
-
|
|
1297
|
-
Produces structured JSON requirements -- not prose. Unlike the Planning module (markdown output), the Requirement Gatherer extracts typed data that downstream systems can consume programmatically.
|
|
1298
|
-
|
|
1299
|
-
| Attribute | Detail |
|
|
1300
|
-
| ----------------- | ------------------------------------------------------------------------------------- |
|
|
1301
|
-
| **Stages** | Discovery, Requirements, Design, Synthesis |
|
|
1302
|
-
| **Sub-Agents** | -- |
|
|
1303
|
-
| **Tools** | Stage-specific tools |
|
|
1304
|
-
| **Output Format** | Structured JSON |
|
|
1305
|
-
| **Schemas** | Actors, User Flows, User Stories, Modules, Database Design, API Design |
|
|
1306
|
-
| **Modes** | One-shot (`runRequirementGathererAgent`), interactive chat (`processRequirementChat`) |
|
|
1307
|
-
|
|
1308
|
-
**Output structure:** Actors (with permissions), User Flows (step-by-step sequences), User Stories (with acceptance criteria), Modules (with CRUD operations), Database Design (schemas, relationships), API Design (REST/GraphQL endpoints).
|
|
1309
|
-
|
|
1310
|
-
```typescript
|
|
1311
|
-
import { runRequirementGathererAgent } from 'sweagent';
|
|
1312
|
-
|
|
1313
|
-
const result = await runRequirementGathererAgent({
|
|
1314
|
-
input: 'Project management tool with teams and Kanban boards',
|
|
1315
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1316
|
-
maxIterations: 15,
|
|
1317
|
-
});
|
|
1318
|
-
// result.output: structured JSON with actors, flows, stories, modules
|
|
1319
|
-
```
|
|
1320
|
-
|
|
1321
|
-
---
|
|
1322
|
-
|
|
1323
|
-
### DB Designer
|
|
1324
|
-
|
|
1325
|
-
An orchestrator agent that delegates to specialized sub-agents for entity analysis and schema refinement. Produces MongoDB-style project schemas with modules, fields, relationships, indexes, and validation rules.
|
|
1326
|
-
|
|
1327
|
-
| Attribute | Detail |
|
|
1328
|
-
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
1329
|
-
| **Pattern** | Orchestrator with sub-agents |
|
|
1330
|
-
| **Sub-Agents** | `entity-analyzer` (extracts entities and relationships), `schema-refiner` (normalizes and validates schemas) |
|
|
1331
|
-
| **Tools** | `design_database` (text requirements to schema), `design_database_pro` (structured requirements to schema), `redesign_database` (modify existing schemas), `validate_schema` (schema validation) |
|
|
1332
|
-
| **Output Format** | MongoDB schema JSON (modules, fields, relationships) |
|
|
1333
|
-
|
|
1334
|
-
```typescript
|
|
1335
|
-
import { runDbDesignerAgent } from 'sweagent';
|
|
1336
|
-
|
|
1337
|
-
const result = await runDbDesignerAgent({
|
|
1338
|
-
input: 'E-commerce: users, orders, products. Admins manage products.',
|
|
1339
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1340
|
-
maxIterations: 15,
|
|
1341
|
-
});
|
|
1342
|
-
// result.output: MongoDB schema with modules, fields, relationships
|
|
1343
|
-
```
|
|
1344
|
-
|
|
1345
|
-
---
|
|
1346
|
-
|
|
1347
|
-
### React Builder
|
|
1348
|
-
|
|
1349
|
-
An orchestrator agent that generates complete frontend application configuration from a GraphQL schema. Uses a `graphql-analyzer` sub-agent to parse schema structure and a `config-validator` to verify the output against frontend config schemas.
|
|
1350
|
-
|
|
1351
|
-
| Attribute | Detail |
|
|
1352
|
-
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1353
|
-
| **Pattern** | Orchestrator with sub-agents |
|
|
1354
|
-
| **Sub-Agents** | `graphql-analyzer` (parses GraphQL schema structure), `config-validator` (validates frontend config output) |
|
|
1355
|
-
| **Tools** | `generate_frontend` (GraphQL to frontend config), `generate_feature_breakdown` (module/operation breakdown), `validate_frontend_config` (config validation) |
|
|
1356
|
-
| **Output Format** | React app config JSON (app, modules, pages, fields, API hooks, branding) |
|
|
1357
|
-
| **Schemas** | App config, User config, Page config, Field config, Branding |
|
|
1358
|
-
|
|
1359
|
-
```typescript
|
|
1360
|
-
import { runReactBuilderAgent } from 'sweagent';
|
|
1361
|
-
|
|
1362
|
-
const result = await runReactBuilderAgent({
|
|
1363
|
-
input: 'GraphQL schema: type User { id: ID! name: String! } type Task { ... }',
|
|
1364
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1365
|
-
maxIterations: 15,
|
|
1366
|
-
});
|
|
1367
|
-
// result.output: frontend config JSON with pages, fields, hooks, branding
|
|
1368
|
-
```
|
|
1369
|
-
|
|
1370
|
-
---
|
|
1371
|
-
|
|
1372
|
-
### Data Modeler
|
|
1373
|
-
|
|
1374
|
-
Designs data models for MongoDB or PostgreSQL with entities, fields, indexes, and relationships. Three sub-agents handle entity analysis, relationship mapping, and schema refinement.
|
|
1375
|
-
|
|
1376
|
-
| Attribute | Detail |
|
|
1377
|
-
| ----------------- | ---------------------------------------------------------------------------- |
|
|
1378
|
-
| **Pattern** | Orchestrator with sub-agents |
|
|
1379
|
-
| **Sub-Agents** | `entity-analyzer`, `relationship-mapper`, `schema-refiner` |
|
|
1380
|
-
| **Tools** | `design_schema`, `design_schema_pro`, `refine_schema`, `validate_data_model` |
|
|
1381
|
-
| **Output Format** | Data model JSON (entities, fields, indexes, relationships) |
|
|
1382
|
-
| **Databases** | MongoDB, PostgreSQL |
|
|
1383
|
-
|
|
1384
|
-
```typescript
|
|
1385
|
-
import { runDataModelerAgent } from 'sweagent';
|
|
1386
|
-
|
|
1387
|
-
const result = await runDataModelerAgent({
|
|
1388
|
-
input: 'SaaS platform with organizations, users, projects, and billing',
|
|
1389
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1390
|
-
maxIterations: 15,
|
|
1391
|
-
});
|
|
1392
|
-
```
|
|
1393
|
-
|
|
1394
|
-
---
|
|
1395
|
-
|
|
1396
|
-
### API Designer
|
|
1153
|
+
#### Feature list approach
|
|
1397
1154
|
|
|
1398
|
-
|
|
1155
|
+
A structured list of requirements (e.g. in JSON) with a status per item gives the agent a clear definition of "done." Agents only mark items passing after verification, keeping scope explicit and making it easy to resume across context windows.
|
|
1399
1156
|
|
|
1400
|
-
|
|
1401
|
-
| ----------------- | ------------------------------------------------------------------------------------------------------- |
|
|
1402
|
-
| **Pattern** | Orchestrator with sub-agents |
|
|
1403
|
-
| **Sub-Agents** | `endpoint-analyzer` (derives endpoints from data model), `contract-designer` (designs request/response) |
|
|
1404
|
-
| **Tools** | `design_api`, `design_api_pro`, `validate_api` |
|
|
1405
|
-
| **Output Format** | API design JSON (REST endpoints and/or GraphQL operations) |
|
|
1157
|
+
#### Clean state principle
|
|
1406
1158
|
|
|
1407
|
-
|
|
1408
|
-
import { runApiDesignerAgent } from 'sweagent';
|
|
1159
|
+
Every session should end with code that is buildable, documented, and easy to continue from. No half-implemented features, no stray debug code, clear commit messages or progress notes. The orchestration prompts in production modules encode these expectations.
|
|
1409
1160
|
|
|
1410
|
-
|
|
1411
|
-
input: 'Design REST API for task manager with users, projects, tasks',
|
|
1412
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1413
|
-
maxIterations: 15,
|
|
1414
|
-
});
|
|
1415
|
-
```
|
|
1161
|
+
### Provider adapter pattern
|
|
1416
1162
|
|
|
1417
|
-
|
|
1163
|
+
Models are created via `createModel({ provider, model, ... })`. A shared AI SDK adapter wraps the Vercel AI SDK's `generateText` and normalizes messages, tool schemas, and responses. Each provider has a thin factory that passes the correct `LanguageModel` into this adapter. Provider-specific logic stays in one place; everything else is provider-agnostic.
|
|
1418
1164
|
|
|
1419
|
-
###
|
|
1165
|
+
### Tool execution safety
|
|
1420
1166
|
|
|
1421
|
-
|
|
1167
|
+
Inputs are validated with Zod before any tool runs. Invalid input produces a **ToolError** with the parse error; the handler is never called with bad data. Handler errors are caught and rethrown as **ToolError** with the original error as cause. The agent loop receives structured tool results (including error payloads) so the model can see failures and retry or adjust.
|
|
1422
1168
|
|
|
1423
|
-
|
|
1424
|
-
| ----------------- | ------------------------------------------------------------------------------------------ |
|
|
1425
|
-
| **Pattern** | Orchestrator with sub-agents |
|
|
1426
|
-
| **Sub-Agents** | `security-analyzer` (analyzes security requirements), `flow-designer` (designs auth flows) |
|
|
1427
|
-
| **Tools** | `design_auth`, `validate_auth` |
|
|
1428
|
-
| **Output Format** | Auth design JSON (strategy, flows, middleware, roles, policies) |
|
|
1169
|
+
### Error hierarchy
|
|
1429
1170
|
|
|
1430
|
-
|
|
1431
|
-
|
|
1171
|
+
| Class | When |
|
|
1172
|
+
| ------------------- | ------------------------------------------------ |
|
|
1173
|
+
| **LibraryError** | Base; all others extend it. |
|
|
1174
|
+
| **ModelError** | Model creation or invoke failed. |
|
|
1175
|
+
| **ToolError** | Tool not found or tool execution failed. |
|
|
1176
|
+
| **ValidationError** | Zod validation failed. |
|
|
1177
|
+
| **AgentError** | Agent reached max iterations without completing. |
|
|
1178
|
+
| **SubagentError** | Subagent config or run failed. |
|
|
1432
1179
|
|
|
1433
|
-
|
|
1434
|
-
input: 'JWT auth with email/password, Google OAuth, admin and member roles',
|
|
1435
|
-
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1436
|
-
maxIterations: 15,
|
|
1437
|
-
});
|
|
1438
|
-
```
|
|
1180
|
+
All accept an optional `cause` for chaining.
|
|
1439
1181
|
|
|
1440
1182
|
---
|
|
1441
1183
|
|
|
1442
|
-
|
|
1184
|
+
## API Reference
|
|
1443
1185
|
|
|
1444
|
-
|
|
1186
|
+
All public APIs are exported from the main package: `import { ... } from 'sweagent'`.
|
|
1445
1187
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
| **Sub-Agents** | `page-planner`, `component-analyzer`, `framework-selector` |
|
|
1450
|
-
| **Output Format** | Frontend design JSON (pages, components, state management, routing) |
|
|
1451
|
-
| **Frameworks** | React + Vite, Next.js |
|
|
1188
|
+
### Models
|
|
1189
|
+
|
|
1190
|
+
**createModel(config)** -- Create a model instance.
|
|
1452
1191
|
|
|
1453
1192
|
```typescript
|
|
1454
|
-
import {
|
|
1193
|
+
import { createModel } from 'sweagent';
|
|
1455
1194
|
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1458
|
-
model:
|
|
1459
|
-
|
|
1195
|
+
const model = createModel({
|
|
1196
|
+
provider: 'openai' | 'anthropic' | 'google',
|
|
1197
|
+
model: string, // e.g. 'gpt-4o', 'claude-sonnet-4-20250514'
|
|
1198
|
+
apiKey?: string, // Uses env var by default
|
|
1199
|
+
temperature?: number,
|
|
1200
|
+
maxOutputTokens?: number,
|
|
1201
|
+
baseUrl?: string,
|
|
1460
1202
|
});
|
|
1203
|
+
|
|
1204
|
+
const response = await model.invoke(messages, { tools });
|
|
1205
|
+
// response: { text, toolCalls, usage, finishReason }
|
|
1461
1206
|
```
|
|
1462
1207
|
|
|
1463
|
-
|
|
1208
|
+
**Supported models (examples):**
|
|
1464
1209
|
|
|
1465
|
-
|
|
1210
|
+
| Provider | Models |
|
|
1211
|
+
| --------- | ---------------------------------------------------- |
|
|
1212
|
+
| OpenAI | `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo` |
|
|
1213
|
+
| Anthropic | `claude-sonnet-4-20250514`, `claude-3-opus-20240229` |
|
|
1214
|
+
| Google | `gemini-1.5-pro`, `gemini-1.5-flash` |
|
|
1466
1215
|
|
|
1467
|
-
|
|
1216
|
+
**Vision:** `model.generateVision(prompt, images, options)` for image inputs.
|
|
1468
1217
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
| **Output Format** | Backend design JSON (framework, services, middleware, routes, folder structure) |
|
|
1475
|
-
| **Frameworks** | Express, Apollo, or both |
|
|
1218
|
+
---
|
|
1219
|
+
|
|
1220
|
+
### Tools
|
|
1221
|
+
|
|
1222
|
+
**defineTool(config)** -- Define a type-safe tool with Zod schema and handler.
|
|
1476
1223
|
|
|
1477
1224
|
```typescript
|
|
1478
|
-
import {
|
|
1225
|
+
import { defineTool } from 'sweagent';
|
|
1226
|
+
import { z } from 'zod';
|
|
1479
1227
|
|
|
1480
|
-
const
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1228
|
+
const tool = defineTool({
|
|
1229
|
+
name: 'my_tool',
|
|
1230
|
+
description: 'What the tool does',
|
|
1231
|
+
input: z.object({ key: z.string() }),
|
|
1232
|
+
handler: async (parsed, context) => ({ result: parsed.key }),
|
|
1484
1233
|
});
|
|
1485
1234
|
```
|
|
1486
1235
|
|
|
1487
|
-
|
|
1236
|
+
**createToolSet(tools)** -- Build a record of tools for the agent (key = tool name).
|
|
1488
1237
|
|
|
1489
|
-
|
|
1238
|
+
**getTool(toolSet, name)** / **getTools(toolSet)** -- Look up one or all tools.
|
|
1490
1239
|
|
|
1491
|
-
|
|
1240
|
+
**executeTool(tool, input, options)** -- Run a single tool with input.
|
|
1492
1241
|
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1242
|
+
**executeToolByName(toolSet, name, input, options)** -- Run by name; throws if tool missing.
|
|
1243
|
+
|
|
1244
|
+
**zodToJsonSchema(schema)** -- Convert a Zod schema to JSON Schema (e.g. for MCP).
|
|
1245
|
+
|
|
1246
|
+
---
|
|
1247
|
+
|
|
1248
|
+
### Agents
|
|
1249
|
+
|
|
1250
|
+
**runAgent(config)** -- Run the agent loop until the model returns no tool calls or max iterations is reached.
|
|
1499
1251
|
|
|
1500
1252
|
```typescript
|
|
1501
|
-
import {
|
|
1253
|
+
import { runAgent } from 'sweagent';
|
|
1502
1254
|
|
|
1503
|
-
const result = await
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1255
|
+
const result = await runAgent({
|
|
1256
|
+
model,
|
|
1257
|
+
tools: createToolSet({ ... }),
|
|
1258
|
+
systemPrompt: string,
|
|
1259
|
+
input: string,
|
|
1260
|
+
maxIterations?: number, // default 10
|
|
1261
|
+
onStep?: (step: AgentStep) => void,
|
|
1507
1262
|
});
|
|
1263
|
+
|
|
1264
|
+
// result: { output, steps, totalUsage, messages }
|
|
1508
1265
|
```
|
|
1509
1266
|
|
|
1510
1267
|
---
|
|
1511
1268
|
|
|
1512
|
-
###
|
|
1513
|
-
|
|
1514
|
-
Generates Apollo GraphQL subgraph configuration with modules, types, resolvers, datasources, and Federation v2 support.
|
|
1269
|
+
### Subagents
|
|
1515
1270
|
|
|
1516
|
-
|
|
1517
|
-
| ----------------- | --------------------------------------------------------------------- |
|
|
1518
|
-
| **Pattern** | Orchestrator with sub-agents |
|
|
1519
|
-
| **Sub-Agents** | `schema-generator`, `resolver-planner` |
|
|
1520
|
-
| **Tools** | `generate_subgraph`, `scaffold_subgraph`, `validate_subgraph` |
|
|
1521
|
-
| **Output Format** | Apollo subgraph config JSON (modules, types, operations, datasources) |
|
|
1271
|
+
**defineSubagent(config)** -- Define a subagent (name must be kebab-case).
|
|
1522
1272
|
|
|
1523
1273
|
```typescript
|
|
1524
|
-
import {
|
|
1274
|
+
import { defineSubagent } from 'sweagent';
|
|
1525
1275
|
|
|
1526
|
-
const
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1276
|
+
const def = defineSubagent({
|
|
1277
|
+
name: 'my-subagent',
|
|
1278
|
+
description: 'What this subagent does',
|
|
1279
|
+
systemPrompt: '...',
|
|
1280
|
+
tools?: Record<string, Tool>,
|
|
1281
|
+
model?: ModelConfig,
|
|
1282
|
+
maxIterations?: number,
|
|
1283
|
+
disallowedTools?: string[],
|
|
1284
|
+
onStep?: (step) => void,
|
|
1530
1285
|
});
|
|
1531
1286
|
```
|
|
1532
1287
|
|
|
1533
|
-
|
|
1288
|
+
**runSubagent(definition, input, options)** -- Run the subagent in isolation.
|
|
1534
1289
|
|
|
1535
|
-
|
|
1290
|
+
**createSubagentTool(definition, options)** -- Expose one subagent as a tool.
|
|
1536
1291
|
|
|
1537
|
-
|
|
1292
|
+
**createSubagentToolSet(definitions, options)** -- Build a record of subagent tools (`subagent_<name>`).
|
|
1538
1293
|
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
| **Output Format** | Next.js config JSON (pages, layouts, API routes, server actions, middleware) |
|
|
1294
|
+
---
|
|
1295
|
+
|
|
1296
|
+
### Planning
|
|
1297
|
+
|
|
1298
|
+
**runPlanningAgent(config)** -- One-shot mode: single input, auto-advances through all stages, returns plan markdown.
|
|
1545
1299
|
|
|
1546
1300
|
```typescript
|
|
1547
|
-
import {
|
|
1301
|
+
import { runPlanningAgent } from 'sweagent';
|
|
1548
1302
|
|
|
1549
|
-
const result = await
|
|
1550
|
-
input:
|
|
1551
|
-
model
|
|
1552
|
-
maxIterations
|
|
1303
|
+
const result = await runPlanningAgent({
|
|
1304
|
+
input: string,
|
|
1305
|
+
model?: ModelConfig,
|
|
1306
|
+
maxIterations?: number,
|
|
1307
|
+
onStep?: (step: AgentStep) => void,
|
|
1308
|
+
logger?: Logger,
|
|
1553
1309
|
});
|
|
1310
|
+
// result: AgentResult { output, steps, totalUsage, messages }
|
|
1554
1311
|
```
|
|
1555
1312
|
|
|
1556
|
-
|
|
1313
|
+
**processPlanningChat(userMessage, context, config)** -- Multi-turn chat mode. Pass `null` context on the first turn.
|
|
1557
1314
|
|
|
1558
|
-
|
|
1315
|
+
```typescript
|
|
1316
|
+
import { processPlanningChat } from 'sweagent';
|
|
1559
1317
|
|
|
1560
|
-
|
|
1318
|
+
const result = await processPlanningChat(userMessage, context, {
|
|
1319
|
+
model?: ModelConfig,
|
|
1320
|
+
maxIterations?: number,
|
|
1321
|
+
onStep?: (step: AgentStep) => void,
|
|
1322
|
+
logger?: Logger,
|
|
1323
|
+
});
|
|
1324
|
+
// result: PlanChatTurnResult { message, context, pendingQuestions, planMarkdown }
|
|
1325
|
+
```
|
|
1561
1326
|
|
|
1562
|
-
|
|
1563
|
-
| ----------------- | --------------------------------------------------------------------------------------- |
|
|
1564
|
-
| **Pattern** | Orchestrator with sub-agents |
|
|
1565
|
-
| **Sub-Agents** | `edge-case-analyzer`, `testing-strategist` |
|
|
1566
|
-
| **Tools** | `create_execution_plan`, `validate_execution_plan` |
|
|
1567
|
-
| **Output Format** | Execution plan JSON (phases, edge cases, testing checklist, security/performance notes) |
|
|
1327
|
+
**runPlanningFromRequirements(config)** -- Convert requirement-gatherer output to a plan, skipping redundant stages.
|
|
1568
1328
|
|
|
1569
1329
|
```typescript
|
|
1570
|
-
import {
|
|
1330
|
+
import { runPlanningFromRequirements } from 'sweagent';
|
|
1571
1331
|
|
|
1572
|
-
const result = await
|
|
1573
|
-
|
|
1574
|
-
model
|
|
1575
|
-
|
|
1332
|
+
const result = await runPlanningFromRequirements({
|
|
1333
|
+
requirement: FinalRequirement, // JSON from requirement-gatherer
|
|
1334
|
+
model?: ModelConfig,
|
|
1335
|
+
onStep?: (step: AgentStep) => void,
|
|
1336
|
+
logger?: Logger,
|
|
1576
1337
|
});
|
|
1338
|
+
// result: AgentResult { output (plan markdown), steps, totalUsage, messages }
|
|
1577
1339
|
```
|
|
1578
1340
|
|
|
1579
|
-
|
|
1341
|
+
**assemblePlan(projectName, sections)** -- Assemble `PlanSections` into a single markdown string.
|
|
1580
1342
|
|
|
1581
|
-
|
|
1343
|
+
**writePlanToFile(markdown, outputPath)** -- Write plan markdown to a file.
|
|
1582
1344
|
|
|
1583
|
-
|
|
1345
|
+
**PlanningContextBuilder** -- Fluent builder for `PlanningContext`:
|
|
1584
1346
|
|
|
1585
1347
|
```typescript
|
|
1586
|
-
import {
|
|
1348
|
+
import { createPlanningContextBuilder } from 'sweagent';
|
|
1587
1349
|
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
});
|
|
1350
|
+
const context = createPlanningContextBuilder()
|
|
1351
|
+
.withStage('requirements')
|
|
1352
|
+
.withProjectDescription('Task manager app')
|
|
1353
|
+
.withSections({ overview: '## Overview\n...' })
|
|
1354
|
+
.build();
|
|
1594
1355
|
```
|
|
1595
1356
|
|
|
1596
1357
|
---
|
|
1597
1358
|
|
|
1598
|
-
|
|
1359
|
+
### MCP
|
|
1599
1360
|
|
|
1600
|
-
|
|
1361
|
+
**BaseMcpClient** -- Base class for MCP clients. Lazy connection, `callTool(name, args)` for invocation.
|
|
1601
1362
|
|
|
1602
|
-
|
|
1603
|
-
# Interactive launcher -- pick a domain agent, then an example
|
|
1604
|
-
npm run example:interactive
|
|
1363
|
+
**BaseMcpClient.resolveConfig(options, resolveOpts)** -- Build config from options and env (e.g. `MCP_URL`, `MCP_COMMAND`, `MCP_ARGS`).
|
|
1605
1364
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1365
|
+
---
|
|
1366
|
+
|
|
1367
|
+
### Errors
|
|
1368
|
+
|
|
1369
|
+
| Class | When |
|
|
1370
|
+
| ------------------- | ------------------------------------------------ |
|
|
1371
|
+
| **LibraryError** | Base; all others extend it. |
|
|
1372
|
+
| **ModelError** | Model creation or invoke failed. |
|
|
1373
|
+
| **ToolError** | Tool not found or tool execution failed. |
|
|
1374
|
+
| **ValidationError** | Zod validation failed. |
|
|
1375
|
+
| **AgentError** | Agent reached max iterations without completing. |
|
|
1376
|
+
| **SubagentError** | Subagent config or run failed. |
|
|
1611
1377
|
|
|
1612
|
-
|
|
1613
|
-
| ------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
|
|
1614
|
-
| **Planning** | 01 Planning Agent | Implementation-ready markdown plan through 4-stage pipeline |
|
|
1615
|
-
| **Requirement Gatherer** | 01 Requirement Gatherer Agent | Structured JSON requirements (actors, flows, stories, modules) |
|
|
1616
|
-
| **Data Modeler** | 01 Data Modeler Agent | MongoDB/PostgreSQL data model with entities, fields, indexes |
|
|
1617
|
-
| **DB Designer** | 01 DB Designer Agent | MongoDB schemas via `entity-analyzer` and `schema-refiner` sub-agents |
|
|
1618
|
-
| **API Designer** | 01 API Designer Agent | REST/GraphQL API design with endpoints and contracts |
|
|
1619
|
-
| **Auth Designer** | 01 Auth Designer Agent | Auth strategy, flows, middleware, roles, and policies |
|
|
1620
|
-
| **Backend Architect** | 01 Backend Architect Agent | Backend architecture with framework selection and services |
|
|
1621
|
-
| **Express Builder** | 01 Express Builder Agent | Express.js config with routers, models, and middleware |
|
|
1622
|
-
| **Apollo Builder** | 01 Apollo Builder Agent | Apollo GraphQL subgraph config with types and resolvers |
|
|
1623
|
-
| **Frontend Architect** | 01 Frontend Architect Agent | Frontend architecture with pages, components, and routing |
|
|
1624
|
-
| **React Builder** | 01 React Builder Agent | Frontend config via `graphql-analyzer` and `config-validator` sub-agents |
|
|
1625
|
-
| **Next.js Builder** | 01 Next.js Builder Agent | Next.js App Router config with pages, layouts, and API routes |
|
|
1626
|
-
| **Execution Planner** | 01 Execution Planner Agent | Phased implementation plan with edge cases and testing checklist |
|
|
1627
|
-
| **Core Framework** | 01 Basic Model, 02 All Providers, 03 Tool Calling, 04 Multi-Tool Agent, 05 Subagents | Models, tools, agent loop, sub-agent delegation |
|
|
1628
|
-
| **Hello World** | 01 Hello World | Minimal agent with greeting tool (module template) |
|
|
1378
|
+
All accept an optional `cause` for chaining.
|
|
1629
1379
|
|
|
1630
1380
|
---
|
|
1631
1381
|
|
|
1632
|
-
##
|
|
1382
|
+
## Reference
|
|
1633
1383
|
|
|
1634
1384
|
### Environment variables
|
|
1635
1385
|
|
|
@@ -1644,21 +1394,14 @@ npm run example -- examples/react-builder/01-react-builder-agent.ts
|
|
|
1644
1394
|
| `REQUIREMENT` | Project requirement for planning/requirement-gatherer examples |
|
|
1645
1395
|
| `MAX_ITERATIONS` | Max agent iterations for examples |
|
|
1646
1396
|
|
|
1647
|
-
###
|
|
1648
|
-
|
|
1649
|
-
`provider`, `model`, `apiKey?`, `temperature?`, `maxOutputTokens?`, `baseUrl?`
|
|
1397
|
+
### Config types
|
|
1650
1398
|
|
|
1651
|
-
|
|
1399
|
+
- **ModelConfig** -- `provider`, `model`, `apiKey?`, `temperature?`, `maxOutputTokens?`, `baseUrl?`
|
|
1400
|
+
- **AgentConfig** -- `model`, `tools`, `systemPrompt`, `input`, `maxIterations?`, `onStep?`
|
|
1401
|
+
- **PlanningAgentConfig** -- `input`, `model?`, `maxIterations?`, `onStep?`, `logger?`
|
|
1402
|
+
- **PlanFromRequirementsConfig** -- `requirement`, `model?`, `onStep?`, `logger?`
|
|
1652
1403
|
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
### PlanningAgentConfig
|
|
1656
|
-
|
|
1657
|
-
`input`, `model?`, `maxIterations?`, `onStep?`, `logger?`
|
|
1658
|
-
|
|
1659
|
-
---
|
|
1660
|
-
|
|
1661
|
-
## FAQ
|
|
1404
|
+
### FAQ
|
|
1662
1405
|
|
|
1663
1406
|
**Which AI provider should I use?**
|
|
1664
1407
|
All work well. Choose by existing infrastructure and pricing. The API is the same regardless of provider.
|
|
@@ -1675,34 +1418,48 @@ Target is Node.js. For browsers, proxy API calls through your backend and keep k
|
|
|
1675
1418
|
**How do I add a new provider?**
|
|
1676
1419
|
Implement a factory that returns a model conforming to the internal `Model` interface (e.g. via `createAIModel` and the provider's AI SDK binding) and register it in `createModel`.
|
|
1677
1420
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
## Troubleshooting
|
|
1421
|
+
### Troubleshooting
|
|
1681
1422
|
|
|
1682
|
-
|
|
1423
|
+
**API key errors** -- Ensure the key is set: `echo $OPENAI_API_KEY` (or the relevant env var). If using `.env`, load it: `tsx --env-file=.env your-script.ts` or `node --env-file=.env your-script.js`.
|
|
1683
1424
|
|
|
1684
|
-
|
|
1685
|
-
- If using `.env`, load it: `tsx --env-file=.env your-script.ts` or `node --env-file=.env your-script.js`.
|
|
1425
|
+
**Model not found** -- Use the exact model id for the provider (e.g. `gpt-4o-mini`, `claude-sonnet-4-20250514`). Confirm your account has access to that model.
|
|
1686
1426
|
|
|
1687
|
-
|
|
1427
|
+
**Agent hits max iterations** -- Increase `maxIterations` or simplify the task. Check that tools return clear, parseable results so the model can decide the next step.
|
|
1688
1428
|
|
|
1689
|
-
|
|
1690
|
-
- Confirm your account has access to that model.
|
|
1429
|
+
**Tool not found** -- Tools must be in the same object passed to `runAgent` under the name the model uses (e.g. `createToolSet({ calculator: calculatorTool })` means the model calls `calculator`).
|
|
1691
1430
|
|
|
1692
|
-
|
|
1431
|
+
---
|
|
1693
1432
|
|
|
1694
|
-
|
|
1695
|
-
- Check that tools return clear, parseable results so the model can decide the next step.
|
|
1433
|
+
## Examples
|
|
1696
1434
|
|
|
1697
|
-
|
|
1435
|
+
The [examples directory](./examples/) contains runnable scripts organized by domain agent. Use the interactive launcher or run a file directly:
|
|
1698
1436
|
|
|
1699
|
-
|
|
1437
|
+
```bash
|
|
1438
|
+
# Interactive launcher -- pick a domain agent, then an example
|
|
1439
|
+
npm run example:interactive
|
|
1700
1440
|
|
|
1701
|
-
|
|
1441
|
+
# Run a specific domain agent example
|
|
1442
|
+
npm run example -- examples/planning/01-planning-agent.ts
|
|
1443
|
+
npm run example -- examples/data-modeler/01-data-modeler-agent.ts
|
|
1444
|
+
npm run example -- examples/react-builder/01-react-builder-agent.ts
|
|
1445
|
+
```
|
|
1702
1446
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1447
|
+
| Domain Agent | Examples | What it produces |
|
|
1448
|
+
| ------------------------ | ----------------------------------------------------- | ------------------------------------------------------------------------ |
|
|
1449
|
+
| **Planning** | 01 Planning Agent | Implementation-ready markdown plan through 4-stage pipeline |
|
|
1450
|
+
| **Requirement Gatherer** | 01 Requirement Gatherer Agent | Structured JSON requirements (actors, flows, stories, modules) |
|
|
1451
|
+
| **Data Modeler** | 01 Data Modeler Agent | MongoDB/PostgreSQL data model with entities, fields, indexes |
|
|
1452
|
+
| **API Designer** | 01 API Designer Agent | REST/GraphQL API design with endpoints and contracts |
|
|
1453
|
+
| **Auth Designer** | 01 Auth Designer Agent | Auth strategy, flows, middleware, roles, and policies |
|
|
1454
|
+
| **Backend Architect** | 01 Backend Architect Agent | Backend architecture with framework selection and services |
|
|
1455
|
+
| **Express Builder** | 01 Express Builder Agent | Express.js config with routers, models, and middleware |
|
|
1456
|
+
| **Apollo Builder** | 01 Apollo Builder Agent | Apollo GraphQL subgraph config with types and resolvers |
|
|
1457
|
+
| **Frontend Architect** | 01 Frontend Architect Agent | Frontend architecture with pages, components, and routing |
|
|
1458
|
+
| **React Builder** | 01 React Builder Agent | Frontend config via `graphql-analyzer` and `config-validator` sub-agents |
|
|
1459
|
+
| **Next.js Builder** | 01 Next.js Builder Agent | Next.js App Router config with pages, layouts, and API routes |
|
|
1460
|
+
| **Execution Planner** | 01 Execution Planner Agent | Phased implementation plan with edge cases and testing checklist |
|
|
1461
|
+
| **Core Framework** | 01-05: Model, Providers, Tools, Multi-Tool, Subagents | Models, tools, agent loop, sub-agent delegation |
|
|
1462
|
+
| **Hello World** | 01 Hello World | Minimal agent with greeting tool (module template) |
|
|
1706
1463
|
|
|
1707
1464
|
---
|
|
1708
1465
|
|
|
@@ -1735,11 +1492,11 @@ npm run build
|
|
|
1735
1492
|
|
|
1736
1493
|
**Support**
|
|
1737
1494
|
|
|
1738
|
-
- [GitHub Issues](https://github.com/sijeeshmiziha/sweagent/issues)
|
|
1739
|
-
- [GitHub Discussions](https://github.com/sijeeshmiziha/sweagent/discussions)
|
|
1495
|
+
- [GitHub Issues](https://github.com/sijeeshmiziha/sweagent/issues) -- Bugs and features
|
|
1496
|
+
- [GitHub Discussions](https://github.com/sijeeshmiziha/sweagent/discussions) -- Questions
|
|
1740
1497
|
|
|
1741
1498
|
---
|
|
1742
1499
|
|
|
1743
1500
|
## License
|
|
1744
1501
|
|
|
1745
|
-
MIT License
|
|
1502
|
+
MIT License -- see [LICENSE](LICENSE) for details.
|