A multi-agent prompt chaining system built with LangGraph.js that demonstrates how to orchestrate multiple specialized AI agents to handle complex queries.
- Multi-Agent Architecture: Sequential chain of specialized agents
- LangGraph Framework: Production-ready agent orchestration
- Multi-Provider Support: OpenAI GPT-4o + Anthropic Claude
- State Management: Shared state flowing through all agents
- Interactive CLI: Chat with the system in your terminal
- Tool Integration: Extensible tool system for various capabilities
- Debug Logging: Beautiful colored console output
The system chains five specialized agents in sequence:
User Query → 📝 Summarizer → 🔍 Pain Identifier → 📋 Plan Creator → 🤖 AI Spawner → 📢 Responder
- Summarizer - Condenses user query into a clear summary
- Pain Identifier - Extracts pain points and challenges
- Plan Creator - Generates step-by-step execution plan
- AI Spawner - Dynamically spawns specialized agents for each plan step
- Responder - Aggregates all results into final response
The state flows through all agents, with each agent reading from and writing to shared state:
messages: Conversation historysummary: Summarized querypainPoints: Identified challengesplan: Execution plan with stepsspawnedResults: Results from specialized agentsfinalResponse: Final aggregated answer
- Node.js 18+ or Bun
- OpenAI API key
- Anthropic API key (optional, for web search)
# Install dependencies
npm install
# or with bun
bun installCreate a .env file in the root directory:
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
AWESOME_DEBUG=trueStart the interactive chat interface:
npm run dev
# or
npm startRun the example demo:
npm run demo/help- Show help message/clear- Clear the screen/reset- Reset conversation history/history- Show conversation history/exit- Exit the program
The system includes the following tools:
- search - Web search using AI providers
- calculate - Mathematical calculations
- analyzeData - Data analysis and insights
- format - Text formatting and transformation
- validate - Data validation
- dateTime - Current date and time information
src/
├── graph/
│ ├── state.ts # LangGraph state definition
│ ├── workflow.ts # Main workflow graph
│ └── nodes/
│ ├── summarizer.ts # Summarizer agent
│ ├── pain-identifier.ts # Pain identifier agent
│ ├── plan-creator.ts # Plan creator agent
│ ├── ai-spawner.ts # AI spawner agent
│ └── responder.ts # Responder agent
├── tools/
│ ├── registry.ts # Tool registry
│ └── *.ts # Individual tool definitions
├── types/
│ └── index.ts # TypeScript type definitions
├── utils/
│ └── debug.ts # Awesome debugger utilities
├── cli.ts # Interactive CLI interface
└── index.ts # Demo entry point
The system uses awesomeDebugger for beautiful console output. Enable it with:
AWESOME_DEBUG=trueColors indicate different stages:
- 🔵 Blue - Agent processing steps
- 🟢 Green - Successful completions
- 🔴 Red - Errors
- 🟡 Yellow - Warnings
- 🟣 Magenta - Web search operations
- 🔷 Cyan - Headers and summaries
- User submits a query through the CLI
- Summarizer creates a concise summary
- Pain Identifier extracts challenges from the summary
- Plan Creator generates a step-by-step plan with required tools
- AI Spawner executes each plan step:
- Uses Anthropic Claude for web search tasks
- Uses OpenAI GPT-4o for standard tasks
- Executes required tools for each step
- Responder aggregates all results into a comprehensive answer
- Final response is displayed to the user
This LangGraph version offers:
- ✅ Production-ready framework
- ✅ Built-in state management
- ✅ Type-safe graph construction
- ✅ Easier debugging and visualization
- ✅ Extensible architecture
MIT