sweagent 0.0.1 → 0.0.2
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 +1255 -265
- package/dist/index.cjs +1436 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3353 -85
- package/dist/index.d.ts +3353 -85
- package/dist/index.js +1436 -46
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
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>
|
|
4
|
+
<strong>The planning layer that makes Cursor, Claude Code, and Codex 10x more effective.</strong>
|
|
5
5
|
</p>
|
|
6
6
|
<p align="center">
|
|
7
|
-
|
|
7
|
+
14 domain-specialized AI agent pipelines — Planning, Requirements, Data Modeling, API Design, Auth, Backend, Frontend, and more — each with dedicated orchestrators, sub-agents, and structured outputs. Generate implementation-ready blueprints, then hand them to your coding agent.
|
|
8
8
|
</p>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
@@ -17,12 +17,14 @@
|
|
|
17
17
|
|
|
18
18
|
<p align="center">
|
|
19
19
|
<a href="#what-is-sweagent">What is sweagent?</a> •
|
|
20
|
-
<a href="#
|
|
20
|
+
<a href="#use-with-cursor-claude-code-and-codex">Use with Coding Agents</a> •
|
|
21
|
+
<a href="#domain-agents">Domain Agents</a> •
|
|
22
|
+
<a href="#full-pipeline">Full Pipeline</a> •
|
|
21
23
|
<a href="#installation">Installation</a> •
|
|
22
|
-
<a href="#getting-started
|
|
24
|
+
<a href="#getting-started">Getting Started</a> •
|
|
23
25
|
<a href="#architecture">Architecture</a> •
|
|
24
26
|
<a href="#api-reference">API Reference</a> •
|
|
25
|
-
<a href="#
|
|
27
|
+
<a href="#domain-agent-modules">Modules</a> •
|
|
26
28
|
<a href="#examples">Examples</a> •
|
|
27
29
|
<a href="#contributing">Contributing</a>
|
|
28
30
|
</p>
|
|
@@ -32,14 +34,17 @@
|
|
|
32
34
|
## Table of Contents
|
|
33
35
|
|
|
34
36
|
- [What is sweagent?](#what-is-sweagent)
|
|
37
|
+
- [Use with Cursor, Claude Code, and Codex](#use-with-cursor-claude-code-and-codex)
|
|
35
38
|
- [Why sweagent?](#why-sweagent)
|
|
39
|
+
- [Domain Agents](#domain-agents)
|
|
40
|
+
- [Full Pipeline](#full-pipeline)
|
|
41
|
+
- [Planning Pipeline](#planning-pipeline)
|
|
36
42
|
- [Features](#features)
|
|
37
43
|
- [Installation](#installation)
|
|
38
|
-
- [Getting Started
|
|
44
|
+
- [Getting Started](#getting-started)
|
|
39
45
|
- [Architecture](#architecture)
|
|
40
|
-
- [Engineering Deep Dive](#engineering-deep-dive)
|
|
41
46
|
- [API Reference](#api-reference)
|
|
42
|
-
- [
|
|
47
|
+
- [Domain Agent Modules](#domain-agent-modules)
|
|
43
48
|
- [Examples](#examples)
|
|
44
49
|
- [Configuration Reference](#configuration-reference)
|
|
45
50
|
- [FAQ](#faq)
|
|
@@ -51,145 +56,742 @@
|
|
|
51
56
|
|
|
52
57
|
## What is sweagent?
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
AI coding agents -- Claude Code, Codex, Cursor -- 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
|
+
|
|
61
|
+
**sweagent** is a library of **14 domain-specialized AI agent pipelines** that handle every stage of software planning at professional quality. Each domain -- planning, requirements, data modeling, API design, auth, backend, frontend -- gets its own **orchestrator agent** with dedicated **sub-agents**, **tools**, and **multi-stage pipelines** that produce structured, reviewable outputs.
|
|
62
|
+
|
|
63
|
+
| Stage | Agent | Sub-Agents | Output |
|
|
64
|
+
| ------------------- | ----------------------------- | ---------------------------------------------------------- | ------------------------------------------------- |
|
|
65
|
+
| **Planning** | `runPlanningAgent` | -- | Implementation-ready markdown plan (11 sections) |
|
|
66
|
+
| **Requirements** | `runRequirementGathererAgent` | -- | Structured JSON (actors, flows, stories, modules) |
|
|
67
|
+
| **Data Modeling** | `runDataModelerAgent` | `entity-analyzer`, `relationship-mapper`, `schema-refiner` | MongoDB/PostgreSQL schemas |
|
|
68
|
+
| **DB Design** | `runDbDesignerAgent` | `entity-analyzer`, `schema-refiner` | MongoDB schemas with RBAC permissions |
|
|
69
|
+
| **API Design** | `runApiDesignerAgent` | `endpoint-analyzer`, `contract-designer` | REST and/or GraphQL API design |
|
|
70
|
+
| **Auth Design** | `runAuthDesignerAgent` | `security-analyzer`, `flow-designer` | Auth strategy, flows, middleware, RBAC |
|
|
71
|
+
| **Backend Arch.** | `runBackendArchitectAgent` | `framework-selector`, `service-planner` | Backend architecture (Express/Apollo) |
|
|
72
|
+
| **Express Builder** | `runExpressBuilderAgent` | `route-generator`, `middleware-configurator` | Express.js REST API config |
|
|
73
|
+
| **Apollo Builder** | `runApolloBuilderAgent` | `schema-generator`, `resolver-planner` | Apollo GraphQL subgraph config |
|
|
74
|
+
| **Frontend Arch.** | `runFrontendArchitectAgent` | `page-planner`, `component-analyzer` | Frontend architecture (React/Next.js) |
|
|
75
|
+
| **React Builder** | `runReactBuilderAgent` | `graphql-analyzer`, `config-validator` | React + Vite app config from GraphQL |
|
|
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 |
|
|
79
|
+
|
|
80
|
+
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.
|
|
55
81
|
|
|
56
|
-
|
|
82
|
+
```typescript
|
|
83
|
+
import { runPlanningWithResult } from 'sweagent';
|
|
84
|
+
|
|
85
|
+
// Generate an implementation-ready plan -- validated by an LLM judge
|
|
86
|
+
const { planning, plan } = await runPlanningWithResult({
|
|
87
|
+
input: 'Task manager app with user auth, task CRUD, assignments, and a dashboard',
|
|
88
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (planning) {
|
|
92
|
+
console.log('Plan is implementation-ready. Hand it to your coding agent.');
|
|
93
|
+
console.log(plan); // Full markdown blueprint
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
TypeScript-first, built on the Vercel AI SDK, ships with all provider SDKs (OpenAI, Anthropic, Google). Set your API keys and go.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Use with Cursor, Claude Code, and Codex
|
|
102
|
+
|
|
103
|
+
Coding agents are powerful executors -- but they build faster and better when they start from a structured plan instead of a vague prompt. sweagent generates the blueprints; your coding agent implements them.
|
|
57
104
|
|
|
58
|
-
|
|
105
|
+
```mermaid
|
|
106
|
+
flowchart LR
|
|
107
|
+
Requirement["Your idea"] --> sweagent["sweagent"]
|
|
108
|
+
sweagent --> Plan["plan.md / JSON spec"]
|
|
109
|
+
Plan --> Cursor["Cursor"]
|
|
110
|
+
Plan --> ClaudeCode["Claude Code"]
|
|
111
|
+
Plan --> Codex["Codex"]
|
|
112
|
+
Cursor --> Code["Production code"]
|
|
113
|
+
ClaudeCode --> Code
|
|
114
|
+
Codex --> Code
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### With Cursor
|
|
118
|
+
|
|
119
|
+
Generate a plan, save it to your project, and reference it in Cursor chat or `.cursor/rules/`:
|
|
59
120
|
|
|
60
121
|
```typescript
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
122
|
+
import { runPlanningWithResult } from 'sweagent';
|
|
123
|
+
import { writeFileSync } from 'fs';
|
|
63
124
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
description: 'Greet someone',
|
|
68
|
-
input: z.object({ name: z.string() }),
|
|
69
|
-
handler: async ({ name }) => ({ message: `Hello, ${name}!` }),
|
|
125
|
+
const { planning, plan } = await runPlanningWithResult({
|
|
126
|
+
input: 'E-commerce with users, products, cart, checkout, admin dashboard',
|
|
127
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
70
128
|
});
|
|
71
129
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
130
|
+
writeFileSync('plan.md', plan);
|
|
131
|
+
// Open plan.md in Cursor and say: "Implement this plan step by step"
|
|
132
|
+
// Or copy plan.md to .cursor/rules/ so every agent session uses it as context
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### With Claude Code
|
|
136
|
+
|
|
137
|
+
Generate a plan and save it as `CLAUDE.md` or a reference file. Claude Code automatically reads `CLAUDE.md` for project context:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { runPlanningWithResult } from 'sweagent';
|
|
141
|
+
import { writeFileSync } from 'fs';
|
|
142
|
+
|
|
143
|
+
const { plan } = await runPlanningWithResult({
|
|
144
|
+
input: 'SaaS dashboard with multi-tenancy, billing, and analytics',
|
|
145
|
+
model: { provider: 'anthropic', model: 'claude-sonnet-4-20250514' },
|
|
77
146
|
});
|
|
78
|
-
|
|
147
|
+
|
|
148
|
+
// Option 1: Save as CLAUDE.md for automatic context
|
|
149
|
+
writeFileSync('CLAUDE.md', `# Implementation Plan\n\n${plan}`);
|
|
150
|
+
|
|
151
|
+
// Option 2: Save as plan.md and reference it
|
|
152
|
+
writeFileSync('plan.md', plan);
|
|
153
|
+
// Then tell Claude Code: "Read plan.md and implement phase 1"
|
|
79
154
|
```
|
|
80
155
|
|
|
156
|
+
### With Codex
|
|
157
|
+
|
|
158
|
+
Codex works best with structured, machine-readable specs. Use the Requirement Gatherer or Data Modeler for JSON output:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { runRequirementGathererAgent } from 'sweagent';
|
|
162
|
+
import { writeFileSync } from 'fs';
|
|
163
|
+
|
|
164
|
+
const result = await runRequirementGathererAgent({
|
|
165
|
+
input: 'Task manager with teams, Kanban boards, and time tracking',
|
|
166
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
167
|
+
maxIterations: 15,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Structured JSON with actors, flows, stories, modules, DB schema, API design
|
|
171
|
+
writeFileSync('requirements.json', result.output);
|
|
172
|
+
// Feed requirements.json to Codex as context for implementation
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Why this works
|
|
176
|
+
|
|
177
|
+
Without sweagent, a coding agent receives "build a task manager" and immediately starts guessing. With sweagent, it receives:
|
|
178
|
+
|
|
179
|
+
- **11-section markdown plan** with tech stack, data models, API routes, auth flow, implementation order, edge cases, and testing checklist
|
|
180
|
+
- **Structured JSON requirements** with actors, user flows, stories, and module breakdowns
|
|
181
|
+
- **Database schemas** with exact field types, relationships, indexes, and validation rules
|
|
182
|
+
- **API contracts** with endpoints, methods, request/response shapes, and auth requirements
|
|
183
|
+
- **Frontend architecture** with pages, components, routing, and state management
|
|
184
|
+
|
|
185
|
+
The coding agent stops guessing and starts executing a professional-grade blueprint.
|
|
186
|
+
|
|
81
187
|
---
|
|
82
188
|
|
|
83
189
|
## Why sweagent?
|
|
84
190
|
|
|
85
|
-
|
|
191
|
+
### 1. Domain-specialized agents, not generic wrappers
|
|
192
|
+
|
|
193
|
+
Each module is a self-contained agent pipeline purpose-built for its domain. The DB Designer doesn't reuse the Planning Agent's prompts -- it has its own `entity-analyzer` and `schema-refiner` sub-agents, its own tools (`design_database`, `validate_schema`), and its own output schema. The React Builder has a `graphql-analyzer` and `config-validator`. Every domain gets the specialized treatment it deserves.
|
|
194
|
+
|
|
195
|
+
### 2. Multi-stage pipelines with structured outputs
|
|
196
|
+
|
|
197
|
+
Every domain agent progresses through deliberate stages -- discovery, requirements, design, synthesis -- with dedicated LLM calls at each step. The Planning pipeline makes 8+ sequential LLM calls across 4 stages. The Requirement Gatherer produces structured JSON with actors, user flows, stories, and module breakdowns. No single-shot prompt engineering; each stage builds on the last and produces traceable, reviewable intermediate results.
|
|
198
|
+
|
|
199
|
+
### 3. Sub-agent orchestration for complex domains
|
|
200
|
+
|
|
201
|
+
When a domain is too complex for a single agent, sweagent delegates to specialized sub-agents. The DB Designer 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.
|
|
86
202
|
|
|
87
|
-
|
|
203
|
+
### 4. Enterprise-quality output, not bullet points
|
|
88
204
|
|
|
89
|
-
|
|
205
|
+
Plans include tech stack decisions, data models with field-level detail, API routes with request/response shapes, phased implementation order, edge cases, and testing checklists. Requirement documents include actors with permissions, user flows with steps, user stories with acceptance criteria, and module breakdowns with CRUD operations. DB schemas include field types, relationships, indexes, and validation rules. These are blueprints, not summaries.
|
|
206
|
+
|
|
207
|
+
### 5. Provider-agnostic model layer
|
|
208
|
+
|
|
209
|
+
Your agent code stays the same whether you're using GPT-4o, Claude, or Gemini. One `createModel()` call, one interface, zero provider lock-in. Switch models in config, not in code.
|
|
210
|
+
|
|
211
|
+
### 6. Incremental progress across sessions
|
|
212
|
+
|
|
213
|
+
Long-running agents fail when they lose context. sweagent encodes patterns for structured progress tracking: feature lists with pass/fail status, progress files, and clean-state principles so each session picks up exactly where the last one left off.
|
|
90
214
|
|
|
91
215
|
---
|
|
92
216
|
|
|
93
|
-
##
|
|
217
|
+
## Domain Agents
|
|
94
218
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
219
|
+
sweagent ships with 14 domain agent modules organized across the full software planning pipeline. Each is a complete pipeline with its own orchestrator, tools, sub-agents, and output format.
|
|
220
|
+
|
|
221
|
+
```mermaid
|
|
222
|
+
flowchart LR
|
|
223
|
+
subgraph discovery [Discovery and Planning]
|
|
224
|
+
Planning["Planning"]
|
|
225
|
+
ReqGatherer["Requirement Gatherer"]
|
|
226
|
+
ExecPlanner["Execution Planner"]
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
subgraph data [Data Layer]
|
|
230
|
+
DataModeler["Data Modeler"]
|
|
231
|
+
DbDesigner["DB Designer"]
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
subgraph api [API Layer]
|
|
235
|
+
ApiDesigner["API Designer"]
|
|
236
|
+
AuthDesigner["Auth Designer"]
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
subgraph backend [Backend]
|
|
240
|
+
BackendArch["Backend Architect"]
|
|
241
|
+
ExpressBuilder["Express Builder"]
|
|
242
|
+
ApolloBuilder["Apollo Builder"]
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
subgraph frontend [Frontend]
|
|
246
|
+
FrontendArch["Frontend Architect"]
|
|
247
|
+
ReactBuilder["React Builder"]
|
|
248
|
+
NextjsBuilder["Next.js Builder"]
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
ReqGatherer --> DataModeler
|
|
252
|
+
ReqGatherer --> DbDesigner
|
|
253
|
+
DataModeler --> ApiDesigner
|
|
254
|
+
DbDesigner --> ApiDesigner
|
|
255
|
+
ApiDesigner --> AuthDesigner
|
|
256
|
+
AuthDesigner --> BackendArch
|
|
257
|
+
BackendArch --> ExpressBuilder
|
|
258
|
+
BackendArch --> ApolloBuilder
|
|
259
|
+
ApiDesigner --> FrontendArch
|
|
260
|
+
FrontendArch --> ReactBuilder
|
|
261
|
+
FrontendArch --> NextjsBuilder
|
|
262
|
+
Planning --> ExecPlanner
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Planning Agent
|
|
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.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { runPlanningWithResult } from 'sweagent';
|
|
271
|
+
|
|
272
|
+
const { planning, plan } = await runPlanningWithResult({
|
|
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
|
+
```
|
|
279
|
+
|
|
280
|
+
**Stages:** Discovery, Requirements (4 LLM calls), Design (2 LLM calls), Synthesis | **Output:** Markdown | **Modes:** One-shot, validated, interactive chat
|
|
105
281
|
|
|
106
282
|
---
|
|
107
283
|
|
|
108
|
-
|
|
284
|
+
### Requirement Gatherer Agent
|
|
109
285
|
|
|
110
|
-
|
|
286
|
+
Produces structured JSON requirements -- not prose. Extracts actors with permissions, user flows with step-by-step sequences, user stories with acceptance criteria, and module breakdowns with CRUD operations, database schemas, and API designs.
|
|
111
287
|
|
|
112
|
-
|
|
113
|
-
|
|
288
|
+
```typescript
|
|
289
|
+
import { runRequirementGathererAgent } from 'sweagent';
|
|
114
290
|
|
|
115
|
-
|
|
291
|
+
const result = await runRequirementGathererAgent({
|
|
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
|
+
```
|
|
116
298
|
|
|
117
|
-
**
|
|
299
|
+
**Stages:** Discovery, Requirements, Design, Synthesis | **Output:** Structured JSON | **Schemas:** Actors, Flows, Stories, Modules, Database, API
|
|
118
300
|
|
|
119
|
-
|
|
120
|
-
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
### DB Designer Agent
|
|
304
|
+
|
|
305
|
+
An orchestrator agent that delegates to specialized sub-agents for entity analysis and schema refinement. Produces MongoDB-style schemas with modules, fields, relationships, indexes, and validation rules.
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { runDbDesignerAgent } from 'sweagent';
|
|
309
|
+
|
|
310
|
+
const result = await runDbDesignerAgent({
|
|
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
|
|
121
316
|
```
|
|
122
317
|
|
|
123
|
-
|
|
318
|
+
**Sub-agents:** `entity-analyzer` (extracts entities and relationships), `schema-refiner` (normalizes and validates) | **Tools:** `design_database`, `design_database_pro`, `redesign_database`, `validate_schema` | **Output:** MongoDB schema JSON
|
|
124
319
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
### React Builder Agent
|
|
323
|
+
|
|
324
|
+
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.
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import { runReactBuilderAgent } from 'sweagent';
|
|
328
|
+
|
|
329
|
+
const result = await runReactBuilderAgent({
|
|
330
|
+
input: 'GraphQL schema: type User { id: ID! name: String! } type Task { ... }',
|
|
331
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
332
|
+
maxIterations: 15,
|
|
333
|
+
});
|
|
334
|
+
// result.output contains frontend config JSON
|
|
129
335
|
```
|
|
130
336
|
|
|
131
|
-
|
|
337
|
+
**Sub-agents:** `graphql-analyzer` (schema parsing), `config-validator` (output verification) | **Tools:** `generate_frontend`, `generate_feature_breakdown`, `validate_frontend_config` | **Output:** React app config JSON
|
|
132
338
|
|
|
133
|
-
|
|
339
|
+
---
|
|
134
340
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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.
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
import { runDataModelerAgent } from 'sweagent';
|
|
347
|
+
|
|
348
|
+
const result = await runDataModelerAgent({
|
|
349
|
+
input: 'SaaS platform with organizations, users, projects, and billing',
|
|
350
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
351
|
+
maxIterations: 15,
|
|
352
|
+
});
|
|
353
|
+
// result.output: DataModelDesign JSON with entities, fields, indexes, relationships
|
|
139
354
|
```
|
|
140
355
|
|
|
141
|
-
|
|
356
|
+
**Sub-agents:** `entity-analyzer`, `relationship-mapper`, `schema-refiner` | **Tools:** `design_schema`, `design_schema_pro`, `refine_schema`, `validate_data_model` | **Output:** Data model JSON (MongoDB or PostgreSQL)
|
|
142
357
|
|
|
143
|
-
|
|
358
|
+
---
|
|
144
359
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
360
|
+
### API Designer Agent
|
|
361
|
+
|
|
362
|
+
Designs REST and/or GraphQL APIs from data models, producing endpoint definitions with request/response contracts, auth requirements, and operation details.
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
import { runApiDesignerAgent } from 'sweagent';
|
|
366
|
+
|
|
367
|
+
const result = await runApiDesignerAgent({
|
|
368
|
+
input: 'Design REST API for a task manager with users, projects, and tasks',
|
|
369
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
370
|
+
maxIterations: 15,
|
|
371
|
+
});
|
|
372
|
+
// result.output: ApiDesign JSON with REST endpoints and/or GraphQL operations
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**Sub-agents:** `endpoint-analyzer`, `contract-designer` | **Tools:** `design_api`, `design_api_pro`, `validate_api` | **Output:** API design JSON (REST/GraphQL)
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
### Auth Designer Agent
|
|
380
|
+
|
|
381
|
+
Designs authentication and authorization systems with strategies, flows, middleware, roles, and security policies.
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
import { runAuthDesignerAgent } from 'sweagent';
|
|
385
|
+
|
|
386
|
+
const result = await runAuthDesignerAgent({
|
|
387
|
+
input: 'JWT auth with email/password, Google OAuth, role-based access (admin, member)',
|
|
388
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
389
|
+
maxIterations: 15,
|
|
390
|
+
});
|
|
391
|
+
// result.output: AuthDesign JSON with strategy, flows, middleware, roles, policies
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Sub-agents:** `security-analyzer`, `flow-designer` | **Tools:** `design_auth`, `validate_auth` | **Output:** Auth design JSON
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
### Frontend Architect Agent
|
|
399
|
+
|
|
400
|
+
Plans frontend architecture including pages, components, routing, and state management. Routes to React Builder or Next.js Builder based on framework selection.
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
import { runFrontendArchitectAgent } from 'sweagent';
|
|
404
|
+
|
|
405
|
+
const result = await runFrontendArchitectAgent({
|
|
406
|
+
input: 'Dashboard app with analytics, settings, and user management pages',
|
|
407
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
408
|
+
maxIterations: 15,
|
|
409
|
+
});
|
|
410
|
+
// result.output: FrontendDesign JSON with pages, components, state management, routing
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
**Sub-agents:** `page-planner`, `component-analyzer`, `framework-selector` | **Output:** Frontend design JSON
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
### Backend Architect Agent
|
|
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.
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
import { runBackendArchitectAgent } from 'sweagent';
|
|
423
|
+
|
|
424
|
+
const result = await runBackendArchitectAgent({
|
|
425
|
+
input: 'REST API backend with user auth, CRUD operations, and file uploads',
|
|
426
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
427
|
+
maxIterations: 15,
|
|
428
|
+
});
|
|
429
|
+
// result.output: BackendDesign JSON with framework, services, middleware, routes
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Sub-agents:** `framework-selector`, `service-planner` | **Tools:** `design_backend`, `validate_backend` | **Output:** Backend design JSON
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
### Express Builder Agent
|
|
437
|
+
|
|
438
|
+
Generates Express.js REST API configuration with routers, models, middleware, and environment variables.
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
import { runExpressBuilderAgent } from 'sweagent';
|
|
442
|
+
|
|
443
|
+
const result = await runExpressBuilderAgent({
|
|
444
|
+
input: 'Express API for e-commerce with products, orders, and user auth',
|
|
445
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
446
|
+
maxIterations: 15,
|
|
447
|
+
});
|
|
448
|
+
// result.output: ExpressConfig JSON with routers, models, middleware, env vars
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**Sub-agents:** `route-generator`, `middleware-configurator` | **Tools:** `generate_express`, `scaffold_express`, `validate_express` | **Output:** Express config JSON
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
### Apollo Builder Agent
|
|
456
|
+
|
|
457
|
+
Generates Apollo GraphQL subgraph configuration with modules, types, resolvers, datasources, and Federation v2 support.
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
import { runApolloBuilderAgent } from 'sweagent';
|
|
461
|
+
|
|
462
|
+
const result = await runApolloBuilderAgent({
|
|
463
|
+
input: 'Apollo subgraph for a task manager with users, projects, and tasks',
|
|
464
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
465
|
+
maxIterations: 15,
|
|
466
|
+
});
|
|
467
|
+
// result.output: SubgraphConfig JSON with modules, types, operations, datasources
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**Sub-agents:** `schema-generator`, `resolver-planner` | **Tools:** `generate_subgraph`, `scaffold_subgraph`, `validate_subgraph` | **Output:** Apollo subgraph config JSON
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
### Next.js Builder Agent
|
|
475
|
+
|
|
476
|
+
Generates Next.js App Router configuration with pages, layouts, API routes, server actions, and middleware.
|
|
477
|
+
|
|
478
|
+
```typescript
|
|
479
|
+
import { runNextjsBuilderAgent } from 'sweagent';
|
|
480
|
+
|
|
481
|
+
const result = await runNextjsBuilderAgent({
|
|
482
|
+
input: 'Next.js app for project management with teams, tasks, and dashboards',
|
|
483
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
484
|
+
maxIterations: 15,
|
|
485
|
+
});
|
|
486
|
+
// result.output: NextjsConfig JSON with pages, layouts, API routes, server actions
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**Sub-agents:** `route-planner`, `api-route-generator` | **Tools:** `generate_nextjs`, `validate_nextjs` | **Output:** Next.js config JSON
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
### Execution Planner Agent
|
|
494
|
+
|
|
495
|
+
Creates phased implementation execution plans from plan sections, with edge case analysis and testing checklists.
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
import { runExecutionPlannerAgent } from 'sweagent';
|
|
499
|
+
|
|
500
|
+
const result = await runExecutionPlannerAgent({
|
|
501
|
+
input: 'Create execution plan for the task manager project',
|
|
502
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
503
|
+
maxIterations: 15,
|
|
504
|
+
});
|
|
505
|
+
// result.output: ExecutionPlan JSON with phases, edge cases, testing checklist
|
|
150
506
|
```
|
|
151
507
|
|
|
152
|
-
|
|
508
|
+
**Sub-agents:** `edge-case-analyzer`, `testing-strategist` | **Tools:** `create_execution_plan`, `validate_execution_plan` | **Output:** Execution plan JSON
|
|
509
|
+
|
|
510
|
+
---
|
|
153
511
|
|
|
154
|
-
|
|
512
|
+
### Hello World (Template)
|
|
155
513
|
|
|
156
|
-
|
|
514
|
+
Minimal example module with a single greeting tool. Use as a starting point when building your own domain agent module.
|
|
157
515
|
|
|
158
|
-
```
|
|
516
|
+
```typescript
|
|
159
517
|
import { createModel, runAgent, helloWorldTool } from 'sweagent';
|
|
160
|
-
|
|
518
|
+
|
|
161
519
|
const result = await runAgent({
|
|
162
|
-
model,
|
|
520
|
+
model: createModel({ provider: 'openai', model: 'gpt-4o-mini' }),
|
|
163
521
|
tools: [helloWorldTool],
|
|
164
522
|
systemPrompt: 'You are helpful.',
|
|
165
523
|
input: 'Say hello',
|
|
166
524
|
});
|
|
167
|
-
console.log(result.output);
|
|
168
525
|
```
|
|
169
526
|
|
|
170
|
-
|
|
527
|
+
---
|
|
528
|
+
|
|
529
|
+
## Planning Pipeline
|
|
530
|
+
|
|
531
|
+
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.
|
|
532
|
+
|
|
533
|
+
### How it works
|
|
534
|
+
|
|
535
|
+
```mermaid
|
|
536
|
+
flowchart LR
|
|
537
|
+
Input["User Requirement"] --> Discovery["Discovery"]
|
|
538
|
+
Discovery --> Requirements["Requirements"]
|
|
539
|
+
Requirements --> Design["Design"]
|
|
540
|
+
Design --> Synthesis["Synthesis"]
|
|
541
|
+
Synthesis --> Plan["plan.md"]
|
|
542
|
+
Plan --> Validate["LLM Validator"]
|
|
543
|
+
Validate --> Output["planning: bool, plan: string"]
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### Stages
|
|
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:
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
import { runPlanningWithResult } from 'sweagent';
|
|
589
|
+
|
|
590
|
+
const { planning, plan } = await runPlanningWithResult({
|
|
591
|
+
input: 'Fitness app with workouts, nutrition tracking, and social features',
|
|
592
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
593
|
+
});
|
|
594
|
+
// planning === true means the plan passed all validation criteria
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
**Interactive chat mode** — multi-turn conversation where you refine the plan:
|
|
598
|
+
|
|
599
|
+
```typescript
|
|
600
|
+
import { processPlanningChat } from 'sweagent';
|
|
601
|
+
import type { PlanningContext } from 'sweagent';
|
|
602
|
+
|
|
603
|
+
let context: PlanningContext | null = null;
|
|
604
|
+
|
|
605
|
+
// Turn 1: describe the project
|
|
606
|
+
const turn1 = await processPlanningChat('Build a task manager with teams', context, {
|
|
607
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
608
|
+
});
|
|
609
|
+
context = turn1.context;
|
|
610
|
+
console.log(turn1.message); // Assistant asks clarifying questions
|
|
611
|
+
console.log(turn1.pendingQuestions); // ["What auth provider?", ...]
|
|
612
|
+
|
|
613
|
+
// Turn 2: answer and advance
|
|
614
|
+
const turn2 = await processPlanningChat('Use NextAuth with GitHub OAuth', context, {
|
|
615
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
616
|
+
});
|
|
617
|
+
context = turn2.context;
|
|
618
|
+
|
|
619
|
+
// Continue until turn.planMarkdown is set (plan complete)
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### Validation criteria
|
|
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.
|
|
637
|
+
|
|
638
|
+
```typescript
|
|
639
|
+
import {
|
|
640
|
+
runRequirementGathererAgent,
|
|
641
|
+
runDataModelerAgent,
|
|
642
|
+
runApiDesignerAgent,
|
|
643
|
+
runAuthDesignerAgent,
|
|
644
|
+
runBackendArchitectAgent,
|
|
645
|
+
runFrontendArchitectAgent,
|
|
646
|
+
runExecutionPlannerAgent,
|
|
647
|
+
} from 'sweagent';
|
|
648
|
+
import { writeFileSync } from 'fs';
|
|
649
|
+
|
|
650
|
+
const model = { provider: 'openai', model: 'gpt-4o-mini' } as const;
|
|
651
|
+
|
|
652
|
+
// Step 1: Gather structured requirements
|
|
653
|
+
const requirements = await runRequirementGathererAgent({
|
|
654
|
+
input: 'Project management SaaS with teams, Kanban boards, time tracking, and billing',
|
|
655
|
+
model,
|
|
656
|
+
maxIterations: 15,
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
// Step 2: Design the data model from requirements
|
|
660
|
+
const dataModel = await runDataModelerAgent({
|
|
661
|
+
input: `Design a data model based on these requirements:\n${requirements.output}`,
|
|
662
|
+
model,
|
|
663
|
+
maxIterations: 15,
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
// Step 3: Design the API from the data model
|
|
667
|
+
const apiDesign = await runApiDesignerAgent({
|
|
668
|
+
input: `Design REST API for this data model:\n${dataModel.output}`,
|
|
669
|
+
model,
|
|
670
|
+
maxIterations: 15,
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
// Step 4: Design auth from the requirements and API
|
|
674
|
+
const authDesign = await runAuthDesignerAgent({
|
|
675
|
+
input: `Design auth for this project:\nRequirements: ${requirements.output}\nAPI: ${apiDesign.output}`,
|
|
676
|
+
model,
|
|
677
|
+
maxIterations: 15,
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
// Step 5: Plan backend architecture
|
|
681
|
+
const backendDesign = await runBackendArchitectAgent({
|
|
682
|
+
input: `Design backend:\nData model: ${dataModel.output}\nAPI: ${apiDesign.output}\nAuth: ${authDesign.output}`,
|
|
683
|
+
model,
|
|
684
|
+
maxIterations: 15,
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
// Step 6: Plan frontend architecture
|
|
688
|
+
const frontendDesign = await runFrontendArchitectAgent({
|
|
689
|
+
input: `Design frontend:\nAPI: ${apiDesign.output}\nRequirements: ${requirements.output}`,
|
|
690
|
+
model,
|
|
691
|
+
maxIterations: 15,
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
// Save all specs for your coding agent
|
|
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"
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
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.
|
|
707
|
+
|
|
708
|
+
---
|
|
709
|
+
|
|
710
|
+
## Features
|
|
711
|
+
|
|
712
|
+
| Feature | Description |
|
|
713
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
714
|
+
| **14 Domain Agent Modules** | Planning, Requirement Gatherer, Data Modeler, DB Designer, 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. |
|
|
715
|
+
| **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. |
|
|
716
|
+
| **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. |
|
|
717
|
+
| **Plan Validation** | LLM-based judge validates that planning output meets all criteria for a coding agent to start implementing. |
|
|
718
|
+
| **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. |
|
|
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. |
|
|
725
|
+
|
|
726
|
+
---
|
|
727
|
+
|
|
728
|
+
## Installation
|
|
729
|
+
|
|
730
|
+
### Prerequisites
|
|
731
|
+
|
|
732
|
+
- **Node.js** >= 18.0.0
|
|
733
|
+
- **npm** >= 8.0.0 (or yarn, pnpm, bun)
|
|
734
|
+
|
|
735
|
+
### Install
|
|
736
|
+
|
|
737
|
+
```bash
|
|
738
|
+
npm install sweagent
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
Or with yarn, pnpm, or bun:
|
|
742
|
+
|
|
743
|
+
```bash
|
|
744
|
+
yarn add sweagent
|
|
745
|
+
pnpm add sweagent
|
|
746
|
+
bun add sweagent
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
All AI provider SDKs (OpenAI, Anthropic, Google) are included; no extra packages needed.
|
|
750
|
+
|
|
751
|
+
### From source
|
|
752
|
+
|
|
753
|
+
```bash
|
|
754
|
+
git clone https://github.com/sijeeshmiziha/sweagent.git
|
|
755
|
+
cd sweagent
|
|
756
|
+
npm install
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
### Environment setup
|
|
760
|
+
|
|
761
|
+
Create a `.env` file in your project root:
|
|
762
|
+
|
|
763
|
+
```bash
|
|
764
|
+
# At least one provider API key is required
|
|
765
|
+
OPENAI_API_KEY=sk-...
|
|
766
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
767
|
+
GOOGLE_GENERATIVE_AI_API_KEY=...
|
|
768
|
+
```
|
|
171
769
|
|
|
172
|
-
|
|
770
|
+
### Verify
|
|
173
771
|
|
|
174
772
|
```bash
|
|
773
|
+
# If installed as a package
|
|
774
|
+
echo 'import { createModel, runAgent, helloWorldTool } from "sweagent";
|
|
775
|
+
const model = createModel({ provider: "openai", model: "gpt-4o-mini" });
|
|
776
|
+
const result = await runAgent({ model, tools: [helloWorldTool], systemPrompt: "You are helpful.", input: "Say hello" });
|
|
777
|
+
console.log(result.output);' > test.mjs
|
|
778
|
+
node --env-file=.env test.mjs
|
|
779
|
+
|
|
780
|
+
# If cloned from source
|
|
175
781
|
npm run example -- examples/hello-world/01-hello-world.ts
|
|
176
782
|
```
|
|
177
783
|
|
|
178
784
|
---
|
|
179
785
|
|
|
180
|
-
## Getting Started
|
|
181
|
-
|
|
182
|
-
Progress from a simple model call to a full agent with tools and subagents.
|
|
786
|
+
## Getting Started
|
|
183
787
|
|
|
184
788
|
### Level 1: Model invocation
|
|
185
789
|
|
|
186
|
-
Create a model and get a completion:
|
|
187
|
-
|
|
188
790
|
```typescript
|
|
189
791
|
import { createModel } from 'sweagent';
|
|
190
792
|
|
|
191
793
|
const model = createModel({
|
|
192
|
-
provider: 'openai',
|
|
794
|
+
provider: 'openai', // 'openai' | 'anthropic' | 'google'
|
|
193
795
|
model: 'gpt-4o-mini',
|
|
194
796
|
temperature: 0.7,
|
|
195
797
|
});
|
|
@@ -200,9 +802,7 @@ const response = await model.invoke([
|
|
|
200
802
|
console.log(response.text);
|
|
201
803
|
```
|
|
202
804
|
|
|
203
|
-
### Level 2:
|
|
204
|
-
|
|
205
|
-
Define a type-safe tool with Zod:
|
|
805
|
+
### Level 2: Define tools
|
|
206
806
|
|
|
207
807
|
```typescript
|
|
208
808
|
import { defineTool } from 'sweagent';
|
|
@@ -223,8 +823,6 @@ const calculatorTool = defineTool({
|
|
|
223
823
|
|
|
224
824
|
### Level 3: Agent loop
|
|
225
825
|
|
|
226
|
-
Run an agent that can call your tools:
|
|
227
|
-
|
|
228
826
|
```typescript
|
|
229
827
|
import { runAgent, createModel, defineTool, createToolSet } from 'sweagent';
|
|
230
828
|
import { z } from 'zod';
|
|
@@ -249,10 +847,16 @@ console.log(result.output);
|
|
|
249
847
|
|
|
250
848
|
### Level 4: Subagents
|
|
251
849
|
|
|
252
|
-
Define subagents and expose them as tools to a parent agent:
|
|
253
|
-
|
|
254
850
|
```typescript
|
|
255
|
-
import {
|
|
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' });
|
|
256
860
|
|
|
257
861
|
const researcher = defineSubagent({
|
|
258
862
|
name: 'researcher',
|
|
@@ -260,7 +864,7 @@ const researcher = defineSubagent({
|
|
|
260
864
|
systemPrompt: 'You are a researcher. Answer concisely.',
|
|
261
865
|
});
|
|
262
866
|
const subagentTools = createSubagentToolSet([researcher], { parentModel: model });
|
|
263
|
-
const tools = createToolSet({ ...
|
|
867
|
+
const tools = createToolSet({ ...subagentTools });
|
|
264
868
|
|
|
265
869
|
const result = await runAgent({
|
|
266
870
|
model,
|
|
@@ -271,25 +875,24 @@ const result = await runAgent({
|
|
|
271
875
|
});
|
|
272
876
|
```
|
|
273
877
|
|
|
274
|
-
### Level 5:
|
|
878
|
+
### Level 5: Planning pipeline
|
|
275
879
|
|
|
276
|
-
|
|
880
|
+
Generate an implementation plan for a coding agent:
|
|
277
881
|
|
|
278
882
|
```typescript
|
|
279
|
-
import {
|
|
883
|
+
import { runPlanningWithResult } from 'sweagent';
|
|
280
884
|
|
|
281
|
-
const
|
|
282
|
-
input: 'E-commerce: users,
|
|
885
|
+
const { planning, plan } = await runPlanningWithResult({
|
|
886
|
+
input: 'E-commerce site: users, products, cart, checkout, admin dashboard',
|
|
283
887
|
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
284
|
-
maxIterations: 15,
|
|
285
888
|
});
|
|
286
|
-
|
|
889
|
+
|
|
890
|
+
console.log('Ready for coding agent:', planning);
|
|
891
|
+
console.log(plan);
|
|
287
892
|
```
|
|
288
893
|
|
|
289
894
|
### Level 6: MCP integration
|
|
290
895
|
|
|
291
|
-
Extend `BaseMcpClient` to call MCP tools (e.g. HTTP or stdio server):
|
|
292
|
-
|
|
293
896
|
```typescript
|
|
294
897
|
import { BaseMcpClient } from 'sweagent';
|
|
295
898
|
|
|
@@ -310,37 +913,87 @@ const result = await client.callTool('tool_name', { arg: 'value' });
|
|
|
310
913
|
```mermaid
|
|
311
914
|
graph TB
|
|
312
915
|
subgraph Client[Client Application]
|
|
313
|
-
App[Your App]
|
|
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"]
|
|
314
933
|
end
|
|
315
934
|
|
|
316
|
-
subgraph
|
|
317
|
-
Models[
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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"]
|
|
322
941
|
end
|
|
323
942
|
|
|
324
943
|
subgraph Providers[AI Providers]
|
|
325
|
-
OpenAI[OpenAI]
|
|
326
|
-
Anthropic[Anthropic]
|
|
327
|
-
Google[Google]
|
|
944
|
+
OpenAI["OpenAI"]
|
|
945
|
+
Anthropic["Anthropic"]
|
|
946
|
+
Google["Google"]
|
|
328
947
|
end
|
|
329
948
|
|
|
330
|
-
App -->
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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:
|
|
972
|
+
|
|
973
|
+
```mermaid
|
|
974
|
+
sequenceDiagram
|
|
975
|
+
participant User
|
|
976
|
+
participant Orchestrator
|
|
977
|
+
participant Model
|
|
978
|
+
participant Tools
|
|
979
|
+
participant SubAgent1 as entity-analyzer
|
|
980
|
+
participant SubAgent2 as schema-refiner
|
|
981
|
+
|
|
982
|
+
User->>Orchestrator: Natural-language requirement
|
|
983
|
+
Orchestrator->>Model: Messages + Domain Tools
|
|
984
|
+
Model-->>Orchestrator: Tool call design_database
|
|
985
|
+
Orchestrator->>Tools: Execute design_database
|
|
986
|
+
Tools-->>Orchestrator: Initial schema
|
|
987
|
+
Orchestrator->>SubAgent1: Analyze entities and relationships
|
|
988
|
+
SubAgent1-->>Orchestrator: Structured entity analysis
|
|
989
|
+
Orchestrator->>SubAgent2: Refine and validate schema
|
|
990
|
+
SubAgent2-->>Orchestrator: Validated schema
|
|
991
|
+
Orchestrator->>Model: Compile final output
|
|
992
|
+
Model-->>Orchestrator: Final result
|
|
993
|
+
Orchestrator-->>User: Production-grade schema
|
|
341
994
|
```
|
|
342
995
|
|
|
343
|
-
### Agent execution
|
|
996
|
+
### Agent execution loop
|
|
344
997
|
|
|
345
998
|
```mermaid
|
|
346
999
|
sequenceDiagram
|
|
@@ -363,80 +1016,46 @@ sequenceDiagram
|
|
|
363
1016
|
end
|
|
364
1017
|
```
|
|
365
1018
|
|
|
366
|
-
### Subagent delegation
|
|
367
|
-
|
|
368
|
-
```mermaid
|
|
369
|
-
sequenceDiagram
|
|
370
|
-
participant User
|
|
371
|
-
participant ParentAgent
|
|
372
|
-
participant ParentModel
|
|
373
|
-
participant SubagentTool
|
|
374
|
-
participant ChildAgent
|
|
375
|
-
participant ChildModel
|
|
376
|
-
|
|
377
|
-
User->>ParentAgent: Input
|
|
378
|
-
ParentAgent->>ParentModel: Messages + Tools (incl. subagent_*)
|
|
379
|
-
ParentModel-->>ParentAgent: Tool call subagent_researcher
|
|
380
|
-
ParentAgent->>SubagentTool: Execute prompt
|
|
381
|
-
SubagentTool->>ChildAgent: runAgent(systemPrompt, prompt)
|
|
382
|
-
ChildAgent->>ChildModel: Messages
|
|
383
|
-
ChildModel-->>ChildAgent: Response
|
|
384
|
-
ChildAgent-->>SubagentTool: output
|
|
385
|
-
SubagentTool-->>ParentAgent: Tool result
|
|
386
|
-
ParentAgent->>ParentModel: Append tool result, continue
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
### Module orchestrator (DB Designer)
|
|
390
|
-
|
|
391
|
-
```mermaid
|
|
392
|
-
flowchart LR
|
|
393
|
-
Input[User Requirement] --> Analyze[entity-analyzer subagent]
|
|
394
|
-
Analyze --> Design[design_database tool]
|
|
395
|
-
Design --> Refine[schema-refiner subagent]
|
|
396
|
-
Refine --> Validate[validate_schema tool]
|
|
397
|
-
Validate --> Output[Schema JSON]
|
|
398
|
-
```
|
|
399
|
-
|
|
400
1019
|
---
|
|
401
1020
|
|
|
402
1021
|
## Engineering Deep Dive
|
|
403
1022
|
|
|
404
|
-
###
|
|
1023
|
+
### The problem: long-running coding agents
|
|
405
1024
|
|
|
406
|
-
|
|
1025
|
+
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.
|
|
407
1026
|
|
|
408
1027
|
### Incremental progress pattern
|
|
409
1028
|
|
|
410
|
-
|
|
1029
|
+
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.
|
|
411
1030
|
|
|
412
1031
|
### Feature list approach
|
|
413
1032
|
|
|
414
|
-
A structured list of requirements (e.g. in JSON) with a status per item gives the agent a clear definition of
|
|
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.
|
|
415
1034
|
|
|
416
1035
|
### Clean state principle
|
|
417
1036
|
|
|
418
|
-
Every session should end with code that is buildable, documented, and easy to continue from.
|
|
419
|
-
|
|
420
|
-
### Error hierarchy design
|
|
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.
|
|
421
1038
|
|
|
422
|
-
|
|
1039
|
+
### Error hierarchy
|
|
423
1040
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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. |
|
|
430
1049
|
|
|
431
|
-
|
|
1050
|
+
All accept an optional `cause` for chaining.
|
|
432
1051
|
|
|
433
1052
|
### Provider adapter pattern
|
|
434
1053
|
|
|
435
|
-
Models are created via `createModel({ provider, model, ... })`.
|
|
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.
|
|
436
1055
|
|
|
437
1056
|
### Tool execution safety
|
|
438
1057
|
|
|
439
|
-
|
|
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.
|
|
440
1059
|
|
|
441
1060
|
---
|
|
442
1061
|
|
|
@@ -446,16 +1065,16 @@ All public APIs are exported from the main package: `import { ... } from 'sweage
|
|
|
446
1065
|
|
|
447
1066
|
### Models
|
|
448
1067
|
|
|
449
|
-
**createModel(config)**
|
|
1068
|
+
**createModel(config)** — Create a model instance.
|
|
450
1069
|
|
|
451
1070
|
```typescript
|
|
452
1071
|
import { createModel } from 'sweagent';
|
|
453
1072
|
|
|
454
1073
|
const model = createModel({
|
|
455
1074
|
provider: 'openai' | 'anthropic' | 'google',
|
|
456
|
-
model: string, // e.g. 'gpt-4o', '
|
|
457
|
-
apiKey?: string, // Uses env var by default
|
|
458
|
-
temperature?: number,
|
|
1075
|
+
model: string, // e.g. 'gpt-4o', 'claude-sonnet-4-20250514'
|
|
1076
|
+
apiKey?: string, // Uses env var by default
|
|
1077
|
+
temperature?: number,
|
|
459
1078
|
maxOutputTokens?: number,
|
|
460
1079
|
baseUrl?: string,
|
|
461
1080
|
});
|
|
@@ -466,11 +1085,11 @@ const response = await model.invoke(messages, { tools });
|
|
|
466
1085
|
|
|
467
1086
|
**Supported models (examples):**
|
|
468
1087
|
|
|
469
|
-
| Provider | Models
|
|
470
|
-
| --------- |
|
|
471
|
-
| OpenAI | `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo`
|
|
472
|
-
| Anthropic | `claude-
|
|
473
|
-
| Google | `gemini-1.5-pro`, `gemini-1.5-flash`
|
|
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` |
|
|
474
1093
|
|
|
475
1094
|
**Vision:** `model.generateVision(prompt, images, options)` for image inputs.
|
|
476
1095
|
|
|
@@ -478,7 +1097,7 @@ const response = await model.invoke(messages, { tools });
|
|
|
478
1097
|
|
|
479
1098
|
### Tools
|
|
480
1099
|
|
|
481
|
-
**defineTool(config)**
|
|
1100
|
+
**defineTool(config)** — Define a type-safe tool with Zod schema and handler.
|
|
482
1101
|
|
|
483
1102
|
```typescript
|
|
484
1103
|
import { defineTool } from 'sweagent';
|
|
@@ -492,21 +1111,21 @@ const tool = defineTool({
|
|
|
492
1111
|
});
|
|
493
1112
|
```
|
|
494
1113
|
|
|
495
|
-
**createToolSet(tools)**
|
|
1114
|
+
**createToolSet(tools)** — Build a record of tools for the agent (key = tool name).
|
|
496
1115
|
|
|
497
|
-
**getTool(toolSet, name)** / **getTools(toolSet)**
|
|
1116
|
+
**getTool(toolSet, name)** / **getTools(toolSet)** — Look up one or all tools.
|
|
498
1117
|
|
|
499
|
-
**executeTool(tool, input, options)**
|
|
1118
|
+
**executeTool(tool, input, options)** — Run a single tool with input.
|
|
500
1119
|
|
|
501
|
-
**executeToolByName(toolSet, name, input, options)**
|
|
1120
|
+
**executeToolByName(toolSet, name, input, options)** — Run by name; throws if tool missing.
|
|
502
1121
|
|
|
503
|
-
**zodToJsonSchema(schema)**
|
|
1122
|
+
**zodToJsonSchema(schema)** — Convert a Zod schema to JSON Schema (e.g. for MCP).
|
|
504
1123
|
|
|
505
1124
|
---
|
|
506
1125
|
|
|
507
1126
|
### Agents
|
|
508
1127
|
|
|
509
|
-
**runAgent(config)**
|
|
1128
|
+
**runAgent(config)** — Run the agent loop until the model returns no tool calls or max iterations is reached.
|
|
510
1129
|
|
|
511
1130
|
```typescript
|
|
512
1131
|
import { runAgent } from 'sweagent';
|
|
@@ -523,15 +1142,11 @@ const result = await runAgent({
|
|
|
523
1142
|
// result: { output, steps, totalUsage, messages }
|
|
524
1143
|
```
|
|
525
1144
|
|
|
526
|
-
**AgentStep** – `{ iteration, content?, toolCalls?, toolResults?, usage? }`.
|
|
527
|
-
|
|
528
|
-
**AgentResult** – `{ output, steps, totalUsage?, messages }`.
|
|
529
|
-
|
|
530
1145
|
---
|
|
531
1146
|
|
|
532
1147
|
### Subagents
|
|
533
1148
|
|
|
534
|
-
**defineSubagent(config)**
|
|
1149
|
+
**defineSubagent(config)** — Define a subagent (name must be kebab-case).
|
|
535
1150
|
|
|
536
1151
|
```typescript
|
|
537
1152
|
import { defineSubagent } from 'sweagent';
|
|
@@ -548,47 +1163,173 @@ const def = defineSubagent({
|
|
|
548
1163
|
});
|
|
549
1164
|
```
|
|
550
1165
|
|
|
551
|
-
**runSubagent(definition, input, options)**
|
|
1166
|
+
**runSubagent(definition, input, options)** — Run the subagent in isolation.
|
|
552
1167
|
|
|
553
|
-
**createSubagentTool(definition, options)**
|
|
1168
|
+
**createSubagentTool(definition, options)** — Expose one subagent as a tool.
|
|
554
1169
|
|
|
555
|
-
**createSubagentToolSet(definitions, options)**
|
|
1170
|
+
**createSubagentToolSet(definitions, options)** — Build a record of subagent tools (`subagent_<name>`).
|
|
556
1171
|
|
|
557
1172
|
---
|
|
558
1173
|
|
|
559
|
-
###
|
|
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.
|
|
560
1223
|
|
|
561
|
-
**
|
|
1224
|
+
**PlanningContextBuilder** — Fluent builder for `PlanningContext`:
|
|
562
1225
|
|
|
563
|
-
|
|
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.
|
|
564
1241
|
|
|
565
|
-
**
|
|
1242
|
+
**BaseMcpClient.resolveConfig(options, resolveOpts)** — Build config from options and env (e.g. `MCP_URL`, `MCP_COMMAND`, `MCP_ARGS`).
|
|
566
1243
|
|
|
567
1244
|
---
|
|
568
1245
|
|
|
569
1246
|
### Errors
|
|
570
1247
|
|
|
571
|
-
| Class
|
|
572
|
-
|
|
|
573
|
-
| **LibraryError**
|
|
574
|
-
| **ModelError**
|
|
575
|
-
| **ToolError**
|
|
576
|
-
| **ValidationError** | Zod validation failed.
|
|
577
|
-
| **AgentError**
|
|
578
|
-
| **SubagentError**
|
|
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. |
|
|
579
1256
|
|
|
580
1257
|
All accept an optional `cause` for chaining.
|
|
581
1258
|
|
|
582
1259
|
---
|
|
583
1260
|
|
|
584
|
-
##
|
|
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
|
+
---
|
|
585
1322
|
|
|
586
1323
|
### DB Designer
|
|
587
1324
|
|
|
588
|
-
|
|
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.
|
|
589
1326
|
|
|
590
|
-
|
|
591
|
-
|
|
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) |
|
|
592
1333
|
|
|
593
1334
|
```typescript
|
|
594
1335
|
import { runDbDesignerAgent } from 'sweagent';
|
|
@@ -597,52 +1338,294 @@ const result = await runDbDesignerAgent({
|
|
|
597
1338
|
input: 'E-commerce: users, orders, products. Admins manage products.',
|
|
598
1339
|
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
599
1340
|
maxIterations: 15,
|
|
600
|
-
onStep: step => console.log(step),
|
|
601
1341
|
});
|
|
602
|
-
|
|
1342
|
+
// result.output: MongoDB schema with modules, fields, relationships
|
|
603
1343
|
```
|
|
604
1344
|
|
|
1345
|
+
---
|
|
1346
|
+
|
|
605
1347
|
### React Builder
|
|
606
1348
|
|
|
607
|
-
|
|
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.
|
|
608
1350
|
|
|
609
|
-
|
|
610
|
-
|
|
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 |
|
|
611
1358
|
|
|
612
1359
|
```typescript
|
|
613
1360
|
import { runReactBuilderAgent } from 'sweagent';
|
|
614
1361
|
|
|
615
1362
|
const result = await runReactBuilderAgent({
|
|
616
|
-
input: 'GraphQL schema: type User { id: ID! name: String } ...',
|
|
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
|
|
1397
|
+
|
|
1398
|
+
Designs REST and/or GraphQL APIs from data models. Produces endpoint definitions with request/response contracts and auth requirements.
|
|
1399
|
+
|
|
1400
|
+
| Attribute | Detail |
|
|
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) |
|
|
1406
|
+
|
|
1407
|
+
```typescript
|
|
1408
|
+
import { runApiDesignerAgent } from 'sweagent';
|
|
1409
|
+
|
|
1410
|
+
const result = await runApiDesignerAgent({
|
|
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
|
+
```
|
|
1416
|
+
|
|
1417
|
+
---
|
|
1418
|
+
|
|
1419
|
+
### Auth Designer
|
|
1420
|
+
|
|
1421
|
+
Designs authentication and authorization systems with strategies, flows, middleware, roles, and security policies.
|
|
1422
|
+
|
|
1423
|
+
| Attribute | Detail |
|
|
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) |
|
|
1429
|
+
|
|
1430
|
+
```typescript
|
|
1431
|
+
import { runAuthDesignerAgent } from 'sweagent';
|
|
1432
|
+
|
|
1433
|
+
const result = await runAuthDesignerAgent({
|
|
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
|
+
```
|
|
1439
|
+
|
|
1440
|
+
---
|
|
1441
|
+
|
|
1442
|
+
### Frontend Architect
|
|
1443
|
+
|
|
1444
|
+
Plans frontend architecture including pages, components, routing, and state management. Routes to React Builder or Next.js Builder based on framework selection.
|
|
1445
|
+
|
|
1446
|
+
| Attribute | Detail |
|
|
1447
|
+
| ----------------- | ------------------------------------------------------------------- |
|
|
1448
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
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 |
|
|
1452
|
+
|
|
1453
|
+
```typescript
|
|
1454
|
+
import { runFrontendArchitectAgent } from 'sweagent';
|
|
1455
|
+
|
|
1456
|
+
const result = await runFrontendArchitectAgent({
|
|
1457
|
+
input: 'Dashboard with analytics, settings, and user management',
|
|
1458
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1459
|
+
maxIterations: 15,
|
|
1460
|
+
});
|
|
1461
|
+
```
|
|
1462
|
+
|
|
1463
|
+
---
|
|
1464
|
+
|
|
1465
|
+
### Backend Architect
|
|
1466
|
+
|
|
1467
|
+
Plans backend architecture including framework selection, services, middleware, routes, and folder structure. Routes to Express Builder or Apollo Builder.
|
|
1468
|
+
|
|
1469
|
+
| Attribute | Detail |
|
|
1470
|
+
| ----------------- | ------------------------------------------------------------------------------- |
|
|
1471
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
1472
|
+
| **Sub-Agents** | `framework-selector`, `service-planner` |
|
|
1473
|
+
| **Tools** | `design_backend`, `validate_backend` |
|
|
1474
|
+
| **Output Format** | Backend design JSON (framework, services, middleware, routes, folder structure) |
|
|
1475
|
+
| **Frameworks** | Express, Apollo, or both |
|
|
1476
|
+
|
|
1477
|
+
```typescript
|
|
1478
|
+
import { runBackendArchitectAgent } from 'sweagent';
|
|
1479
|
+
|
|
1480
|
+
const result = await runBackendArchitectAgent({
|
|
1481
|
+
input: 'REST API with user auth, CRUD operations, and file uploads',
|
|
1482
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1483
|
+
maxIterations: 15,
|
|
1484
|
+
});
|
|
1485
|
+
```
|
|
1486
|
+
|
|
1487
|
+
---
|
|
1488
|
+
|
|
1489
|
+
### Express Builder
|
|
1490
|
+
|
|
1491
|
+
Generates Express.js REST API configuration with routers, models, middleware, and environment variables.
|
|
1492
|
+
|
|
1493
|
+
| Attribute | Detail |
|
|
1494
|
+
| ----------------- | ----------------------------------------------------------- |
|
|
1495
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
1496
|
+
| **Sub-Agents** | `route-generator`, `middleware-configurator` |
|
|
1497
|
+
| **Tools** | `generate_express`, `scaffold_express`, `validate_express` |
|
|
1498
|
+
| **Output Format** | Express config JSON (routers, models, middleware, env vars) |
|
|
1499
|
+
|
|
1500
|
+
```typescript
|
|
1501
|
+
import { runExpressBuilderAgent } from 'sweagent';
|
|
1502
|
+
|
|
1503
|
+
const result = await runExpressBuilderAgent({
|
|
1504
|
+
input: 'Express API for e-commerce with products, orders, and user auth',
|
|
617
1505
|
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
618
1506
|
maxIterations: 15,
|
|
619
1507
|
});
|
|
620
|
-
|
|
1508
|
+
```
|
|
1509
|
+
|
|
1510
|
+
---
|
|
1511
|
+
|
|
1512
|
+
### Apollo Builder
|
|
1513
|
+
|
|
1514
|
+
Generates Apollo GraphQL subgraph configuration with modules, types, resolvers, datasources, and Federation v2 support.
|
|
1515
|
+
|
|
1516
|
+
| Attribute | Detail |
|
|
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) |
|
|
1522
|
+
|
|
1523
|
+
```typescript
|
|
1524
|
+
import { runApolloBuilderAgent } from 'sweagent';
|
|
1525
|
+
|
|
1526
|
+
const result = await runApolloBuilderAgent({
|
|
1527
|
+
input: 'Apollo subgraph for task manager with users, projects, tasks',
|
|
1528
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1529
|
+
maxIterations: 15,
|
|
1530
|
+
});
|
|
1531
|
+
```
|
|
1532
|
+
|
|
1533
|
+
---
|
|
1534
|
+
|
|
1535
|
+
### Next.js Builder
|
|
1536
|
+
|
|
1537
|
+
Generates Next.js App Router configuration with pages, layouts, API routes, server actions, and middleware.
|
|
1538
|
+
|
|
1539
|
+
| Attribute | Detail |
|
|
1540
|
+
| ----------------- | ---------------------------------------------------------------------------- |
|
|
1541
|
+
| **Pattern** | Orchestrator with sub-agents |
|
|
1542
|
+
| **Sub-Agents** | `route-planner`, `api-route-generator` |
|
|
1543
|
+
| **Tools** | `generate_nextjs`, `validate_nextjs` |
|
|
1544
|
+
| **Output Format** | Next.js config JSON (pages, layouts, API routes, server actions, middleware) |
|
|
1545
|
+
|
|
1546
|
+
```typescript
|
|
1547
|
+
import { runNextjsBuilderAgent } from 'sweagent';
|
|
1548
|
+
|
|
1549
|
+
const result = await runNextjsBuilderAgent({
|
|
1550
|
+
input: 'Next.js app for project management with teams and dashboards',
|
|
1551
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1552
|
+
maxIterations: 15,
|
|
1553
|
+
});
|
|
1554
|
+
```
|
|
1555
|
+
|
|
1556
|
+
---
|
|
1557
|
+
|
|
1558
|
+
### Execution Planner
|
|
1559
|
+
|
|
1560
|
+
Creates phased implementation execution plans with edge case analysis and testing checklists.
|
|
1561
|
+
|
|
1562
|
+
| Attribute | Detail |
|
|
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) |
|
|
1568
|
+
|
|
1569
|
+
```typescript
|
|
1570
|
+
import { runExecutionPlannerAgent } from 'sweagent';
|
|
1571
|
+
|
|
1572
|
+
const result = await runExecutionPlannerAgent({
|
|
1573
|
+
input: 'Create execution plan for the task manager project',
|
|
1574
|
+
model: { provider: 'openai', model: 'gpt-4o-mini' },
|
|
1575
|
+
maxIterations: 15,
|
|
1576
|
+
});
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
---
|
|
1580
|
+
|
|
1581
|
+
### Hello World (Template)
|
|
1582
|
+
|
|
1583
|
+
Minimal example module with a single greeting tool. Use as a starting point when building your own domain agent module.
|
|
1584
|
+
|
|
1585
|
+
```typescript
|
|
1586
|
+
import { createModel, runAgent, helloWorldTool } from 'sweagent';
|
|
1587
|
+
|
|
1588
|
+
const result = await runAgent({
|
|
1589
|
+
model: createModel({ provider: 'openai', model: 'gpt-4o-mini' }),
|
|
1590
|
+
tools: [helloWorldTool],
|
|
1591
|
+
systemPrompt: 'You are helpful.',
|
|
1592
|
+
input: 'Say hello',
|
|
1593
|
+
});
|
|
621
1594
|
```
|
|
622
1595
|
|
|
623
1596
|
---
|
|
624
1597
|
|
|
625
1598
|
## Examples
|
|
626
1599
|
|
|
627
|
-
The [examples directory](./examples/README.md) contains runnable scripts. Use the interactive launcher or run a file directly:
|
|
1600
|
+
The [examples directory](./examples/README.md) contains runnable scripts organized by domain agent. Use the interactive launcher or run a file directly:
|
|
628
1601
|
|
|
629
1602
|
```bash
|
|
630
|
-
# Interactive launcher
|
|
1603
|
+
# Interactive launcher -- pick a domain agent, then an example
|
|
631
1604
|
npm run example:interactive
|
|
632
1605
|
|
|
633
|
-
# Run a specific
|
|
634
|
-
npm run example -- examples/
|
|
635
|
-
npm run example -- examples/hello-world/01-hello-world.ts
|
|
1606
|
+
# Run a specific domain agent example
|
|
1607
|
+
npm run example -- examples/planning/01-planning-agent.ts
|
|
636
1608
|
npm run example -- examples/db-designer/01-db-designer-agent.ts
|
|
637
1609
|
npm run example -- examples/react-builder/01-react-builder-agent.ts
|
|
638
1610
|
```
|
|
639
1611
|
|
|
640
|
-
|
|
|
641
|
-
|
|
|
642
|
-
| **
|
|
643
|
-
| **
|
|
644
|
-
| **
|
|
645
|
-
| **
|
|
1612
|
+
| Domain Agent | Examples | What it produces |
|
|
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) |
|
|
646
1629
|
|
|
647
1630
|
---
|
|
648
1631
|
|
|
@@ -650,14 +1633,16 @@ npm run example -- examples/react-builder/01-react-builder-agent.ts
|
|
|
650
1633
|
|
|
651
1634
|
### Environment variables
|
|
652
1635
|
|
|
653
|
-
| Variable
|
|
654
|
-
|
|
|
655
|
-
| `OPENAI_API_KEY`
|
|
656
|
-
| `ANTHROPIC_API_KEY`
|
|
657
|
-
| `GOOGLE_GENERATIVE_AI_API_KEY`
|
|
658
|
-
| `MCP_URL` / `MCP_COMMAND` / `MCP_ARGS` | MCP client (when using `resolveConfig`)
|
|
659
|
-
|
|
660
|
-
|
|
1636
|
+
| Variable | Purpose |
|
|
1637
|
+
| -------------------------------------- | -------------------------------------------------------------- |
|
|
1638
|
+
| `OPENAI_API_KEY` | OpenAI API key |
|
|
1639
|
+
| `ANTHROPIC_API_KEY` | Anthropic API key |
|
|
1640
|
+
| `GOOGLE_GENERATIVE_AI_API_KEY` | Google AI API key |
|
|
1641
|
+
| `MCP_URL` / `MCP_COMMAND` / `MCP_ARGS` | MCP client (when using `resolveConfig`) |
|
|
1642
|
+
| `PROVIDER` | Default provider for examples |
|
|
1643
|
+
| `MODEL` | Default model for examples |
|
|
1644
|
+
| `REQUIREMENT` | Project requirement for planning/requirement-gatherer examples |
|
|
1645
|
+
| `MAX_ITERATIONS` | Max agent iterations for examples |
|
|
661
1646
|
|
|
662
1647
|
### ModelConfig
|
|
663
1648
|
|
|
@@ -667,21 +1652,28 @@ For examples: `PROVIDER`, `MODEL`, `AGENT_INPUT`, `REQUIREMENT`, `MAX_ITERATIONS
|
|
|
667
1652
|
|
|
668
1653
|
`model`, `tools`, `systemPrompt`, `input`, `maxIterations?`, `onStep?`
|
|
669
1654
|
|
|
1655
|
+
### PlanningAgentConfig
|
|
1656
|
+
|
|
1657
|
+
`input`, `model?`, `maxIterations?`, `onStep?`, `logger?`
|
|
1658
|
+
|
|
670
1659
|
---
|
|
671
1660
|
|
|
672
1661
|
## FAQ
|
|
673
1662
|
|
|
674
|
-
**Which AI provider should I use?**
|
|
675
|
-
All work well. Choose by existing
|
|
1663
|
+
**Which AI provider should I use?**
|
|
1664
|
+
All work well. Choose by existing infrastructure and pricing. The API is the same regardless of provider.
|
|
1665
|
+
|
|
1666
|
+
**Can I use this with Claude Code / Codex / Cursor?**
|
|
1667
|
+
Yes -- this is the primary use case. See [Use with Cursor, Claude Code, and Codex](#use-with-cursor-claude-code-and-codex) for detailed integration guides with code examples. In short: generate a plan or structured spec with sweagent, save it to a file, and reference it in your coding agent. For Cursor, save to `.cursor/rules/` or paste into chat. For Claude Code, save as `CLAUDE.md` or reference with `@plan.md`. For Codex, feed the structured JSON as context.
|
|
676
1668
|
|
|
677
|
-
**How do I handle rate limits?**
|
|
1669
|
+
**How do I handle rate limits?**
|
|
678
1670
|
sweagent has no built-in rate limiting. Use a retry library (e.g. `p-retry`) around `model.invoke` or `runAgent` if needed.
|
|
679
1671
|
|
|
680
|
-
**Can I use sweagent in the browser?**
|
|
1672
|
+
**Can I use sweagent in the browser?**
|
|
681
1673
|
Target is Node.js. For browsers, proxy API calls through your backend and keep keys server-side.
|
|
682
1674
|
|
|
683
|
-
**How do I add a new provider?**
|
|
684
|
-
Implement a factory that returns a model conforming to the internal `Model` interface (e.g. via `createAIModel` and the provider
|
|
1675
|
+
**How do I add a new provider?**
|
|
1676
|
+
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`.
|
|
685
1677
|
|
|
686
1678
|
---
|
|
687
1679
|
|
|
@@ -689,14 +1681,12 @@ Implement a factory that returns a model conforming to the internal `Model` inte
|
|
|
689
1681
|
|
|
690
1682
|
### API key errors
|
|
691
1683
|
|
|
692
|
-
**Invalid API key / Authentication failed**
|
|
693
|
-
|
|
694
1684
|
- Ensure the key is set: `echo $OPENAI_API_KEY` (or the relevant env var).
|
|
695
1685
|
- If using `.env`, load it: `tsx --env-file=.env your-script.ts` or `node --env-file=.env your-script.js`.
|
|
696
1686
|
|
|
697
1687
|
### Model not found
|
|
698
1688
|
|
|
699
|
-
- Use the exact model id for the provider (e.g. `gpt-4o-mini`, `claude-
|
|
1689
|
+
- Use the exact model id for the provider (e.g. `gpt-4o-mini`, `claude-sonnet-4-20250514`).
|
|
700
1690
|
- Confirm your account has access to that model.
|
|
701
1691
|
|
|
702
1692
|
### Agent hits max iterations
|
|
@@ -706,7 +1696,13 @@ Implement a factory that returns a model conforming to the internal `Model` inte
|
|
|
706
1696
|
|
|
707
1697
|
### Tool not found
|
|
708
1698
|
|
|
709
|
-
- Tools must be in the same object passed to `runAgent` under the name the model uses (e.g. `createToolSet({ calculator: calculatorTool })`
|
|
1699
|
+
- 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`).
|
|
1700
|
+
|
|
1701
|
+
### Planning module returns `planning: false`
|
|
1702
|
+
|
|
1703
|
+
- The LLM validator found missing sections. Check the `plan` string for gaps (no tech stack? no implementation order?).
|
|
1704
|
+
- Try a more capable model (e.g. `gpt-4o` instead of `gpt-4o-mini`).
|
|
1705
|
+
- Provide a more detailed project description as input.
|
|
710
1706
|
|
|
711
1707
|
---
|
|
712
1708
|
|
|
@@ -727,29 +1723,23 @@ npm run lint
|
|
|
727
1723
|
npm run build
|
|
728
1724
|
```
|
|
729
1725
|
|
|
730
|
-
| Command
|
|
731
|
-
|
|
|
732
|
-
| `npm run dev`
|
|
733
|
-
| `npm test`
|
|
734
|
-
| `npm run test:integration`
|
|
735
|
-
| `npm run test:all`
|
|
736
|
-
| `npm run lint` / `npm run lint:fix` | ESLint
|
|
737
|
-
| `npm run typecheck`
|
|
738
|
-
| `npm run build`
|
|
1726
|
+
| Command | Description |
|
|
1727
|
+
| ----------------------------------- | ----------------- |
|
|
1728
|
+
| `npm run dev` | Watch build |
|
|
1729
|
+
| `npm test` | Unit tests |
|
|
1730
|
+
| `npm run test:integration` | Integration tests |
|
|
1731
|
+
| `npm run test:all` | All tests |
|
|
1732
|
+
| `npm run lint` / `npm run lint:fix` | ESLint |
|
|
1733
|
+
| `npm run typecheck` | TypeScript |
|
|
1734
|
+
| `npm run build` | Production build |
|
|
739
1735
|
|
|
740
1736
|
**Support**
|
|
741
1737
|
|
|
742
|
-
- [GitHub Issues](https://github.com/sijeeshmiziha/sweagent/issues)
|
|
743
|
-
- [GitHub Discussions](https://github.com/sijeeshmiziha/sweagent/discussions)
|
|
1738
|
+
- [GitHub Issues](https://github.com/sijeeshmiziha/sweagent/issues) — Bugs and features
|
|
1739
|
+
- [GitHub Discussions](https://github.com/sijeeshmiziha/sweagent/discussions) — Questions
|
|
744
1740
|
|
|
745
1741
|
---
|
|
746
1742
|
|
|
747
1743
|
## License
|
|
748
1744
|
|
|
749
|
-
MIT License
|
|
750
|
-
|
|
751
|
-
---
|
|
752
|
-
|
|
753
|
-
<p align="center">
|
|
754
|
-
Made with ❤️ by the CompilersLab team!
|
|
755
|
-
</p>
|
|
1745
|
+
MIT License — see [LICENSE](LICENSE) for details.
|