Skip to content

MayankBansal12/ai-writing-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wavmo - AI Writing Agent

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.

Demo


Overview

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.

Architecture

The system consists of four main agents working in sequence:

1. Plan Agent (Model: GPT-OSS-Safeguard-20B)

  • 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

2. Writing Agent (Model: Groq Compound)

  • 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

3. Review Agent (Model: GPT-OSS-20B)

  • 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

4. Improvement Agent (Model: MoonshotAI Kimi-K2-Instruct)

  • Generates the final writing after fixing all issues identified by the Review Agent
  • Makes targeted improvements without major structural changes

Workflow

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

Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • Bun.js
  • pnpm (v10.10.0 or higher)

Installation

First, install the dependencies:

pnpm install

Environment Variables

  • For Server Create a .env file in the apps/server directory 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 .env file in the apps/web directory with the following variables:
NEXT_PUBLIC_API_URL=http://localhost:8000

Running the Application

Start all applications in development mode:

pnpm run dev

This will start:

Running Individual Services

  • Web only: pnpm run dev:web
  • Server only: pnpm run dev:server
  • Inngest Dev Server: pnpm run inngest:dev

Project Structure

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

Available Scripts

  • pnpm run dev: Start all applications in development mode
  • pnpm run build: Build all applications for production
  • pnpm run build:web: Build only the web application
  • pnpm run build:server: Build only the server
  • pnpm run dev:web: Start only the web application
  • pnpm run dev:server: Start only the server
  • pnpm run inngest:dev: Start Inngest development server
  • pnpm run check-types: Check TypeScript types across all apps
  • pnpm run check: Run Biome formatting and linting

Technology Stack

  • 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

API Endpoints

POST /api/chat

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": "..."
  }
}

GET /health

Health check endpoint.

How It Works

  1. User submits a prompt describing the document requirements, style, and preferences
  2. 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
  3. Writing Agent creates the document content following the plan
  4. Review Agent evaluates the draft for:
    • Grammatical errors
    • Tone consistency
    • Structural issues
    • Missing elements
  5. Improvement Agent refines the document based on review feedback
  6. Final document is returned to the user

Contributing

This project uses Biome for code formatting and linting. Before committing, run:

pnpm run check

This will automatically format and lint your code.

About

Multi step AI agent to help you write quality documents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors