An AI Writing Agent that helps you write better documents. The system uses a network of agents to plan, write, review, and improve documents based on your requirements.
The Agent orchestrates multiple agents that work together to create high-quality documents. Each agent has a specific role in the writing process, ensuring planning, writing, review, and improvement.
The system consists of four main agents working in sequence:
- Generates a comprehensive plan for the document
- Determines tone, writing style, and preferences
- Provides a structured outline for the document
- Extracts intent, requirements, and constraints from user prompts
- Optionally suggests search queries for research
- Writes the actual document content based on the plan
- Generates MDX-compatible content with proper structure
- Follows the tone and style specified in the plan
- Reviews the writing generated by the Writing Agent
- Identifies grammatical and tone issues
- Checks for structural problems and missing elements
- Provides minor points for improvement
- Ensures alignment with the original plan
- Generates the final writing after fixing all issues identified by the Review Agent
- Makes targeted improvements without major structural changes
User Prompt
↓
Plan Agent (generates plan, outline, tone, style)
↓
Writing Agent (writes document content)
↓
Review Agent (reviews and identifies issues)
↓
Improvement Agent (fixes issues, produces final document)
↓
Final Document
- Node.js (v18 or higher)
- Bun.js
- pnpm (v10.10.0 or higher)
First, install the dependencies:
pnpm install- For Server
Create a
.envfile in theapps/serverdirectory with the following variables:
GROQ_API_KEY=your_groq_api_key
GROQ_BASE_URL=https://api.groq.com/openai/v1/
PORT=8000
CORS_ORIGIN=http://localhost:3001- For Client
Create a
.envfile in theapps/webdirectory with the following variables:
NEXT_PUBLIC_API_URL=http://localhost:8000Start all applications in development mode:
pnpm run devThis will start:
- Web Application: http://localhost:3001 - Frontend UI
- Server: http://localhost:8000 - Backend API
- Web only:
pnpm run dev:web - Server only:
pnpm run dev:server - Inngest Dev Server:
pnpm run inngest:dev
ai-writing-agent/
├── apps/
│ ├── web/ # Frontend application (Next.js)
│ │ ├── src/
│ │ │ ├── app/ # Next.js app router pages
│ │ │ ├── components/ # React components
│ │ │ │ ├── ui/ # UI component library
│ │ │ │ ├── chat-panel.tsx
│ │ │ │ ├── document-panel.tsx
│ │ │ │ └── ...
│ │ │ └── lib/ # Utility libraries
│ │ └── package.json
│ └── server/ # Backend Server (Bun.js/Fastify)
│ ├── src/
│ │ ├── helpers/
│ │ │ └── prompts/ # Agent prompt templates
│ │ │ ├── planning.ts
│ │ │ ├── writing.ts
│ │ │ ├── review.ts
│ │ │ └── improvement.ts
│ │ ├── index.ts # Fastify server setup
│ │ ├── inngest.ts # Inngest function definitions
│ │ ├── network.ts # Agent network orchestration
│ │ └── types.ts # TypeScript type definitions
│ └── package.json
├── packages/
│ └── config/ # Shared configuration
└── package.json
pnpm run dev: Start all applications in development modepnpm run build: Build all applications for productionpnpm run build:web: Build only the web applicationpnpm run build:server: Build only the serverpnpm run dev:web: Start only the web applicationpnpm run dev:server: Start only the serverpnpm run inngest:dev: Start Inngest development serverpnpm run check-types: Check TypeScript types across all appspnpm run check: Run Biome formatting and linting
- Frontend: Next.js, React, TypeScript, Tailwind CSS
- Backend: Bun.js, Fastify, Inngest Agent Kit
- AI Models: Groq API (various models via OpenAI-compatible interface)
- Orchestration: Inngest for workflow management
- Code Quality: Biome for linting and formatting
Submit a writing prompt and receive a generated document.
Request Body:
{
"userPrompt": "Write a blog post about AI agents"
}Response:
{
"success": true,
"finalDocument": "# Generated Document...",
"state": {
"userPrompt": "...",
"plan": { ... },
"draft": "...",
"review": { ... },
"finalDocument": "..."
}
}Health check endpoint.
- User submits a prompt describing the document requirements, style, and preferences
- Plan Agent analyzes the prompt and generates:
- Document intent and requirements
- Structured outline with MDX-compatible sections
- Tone and writing style
- Constraints and optional search queries
- Writing Agent creates the document content following the plan
- Review Agent evaluates the draft for:
- Grammatical errors
- Tone consistency
- Structural issues
- Missing elements
- Improvement Agent refines the document based on review feedback
- Final document is returned to the user
This project uses Biome for code formatting and linting. Before committing, run:
pnpm run checkThis will automatically format and lint your code.