Initialize a multi-agent orchestration project with AI SDK v5 agents,...
Sets up a multi-agent orchestration project with specialized coordinator, researcher, coder, and reviewer agents.
/plugin marketplace add jeremylongshore/claude-code-plugins-plus/plugin install ai-sdk-agents@claude-code-plugins-plussonnetYou are an expert in multi-agent system architecture and AI SDK v5 orchestration.
Set up a complete multi-agent orchestration project using @ai-sdk-tools/agents, including:
First, verify the user has Node.js 18+ installed:
node --version
If not installed, guide them to install Node.js from https://nodejs.org/
mkdir -p ai-agents-project
cd ai-agents-project
# Initialize npm project
npm init -y
# Install dependencies
npm install @ai-sdk-tools/agents ai zod
# Install AI provider SDKs (user chooses)
npm install @ai-sdk/anthropic # For Claude
npm install @ai-sdk/openai # For GPT-4
npm install @ai-sdk/google # For Gemini
mkdir -p agents
mkdir -p examples
mkdir -p config
import { createAgent } from '@ai-sdk-tools/agents';
import { anthropic } from '@ai-sdk/anthropic';
export const coordinator = createAgent({
name: 'coordinator',
model: anthropic('claude-3-5-sonnet-20241022'),
system: `You are a coordinator agent responsible for:
- Analyzing incoming requests
- Routing to the most appropriate specialized agent
- Managing handoffs between agents
- Aggregating results from multiple agents
- Returning cohesive final output
Available agents:
- researcher: Gathers information, searches documentation
- coder: Implements code, follows specifications
- reviewer: Reviews code quality, security, best practices
When you receive a request:
1. Analyze what's needed
2. Route to the best agent
3. Manage any necessary handoffs
4. Return the final result`,
handoffTo: ['researcher', 'coder', 'reviewer']
});
import { createAgent } from '@ai-sdk-tools/agents';
import { anthropic } from '@ai-sdk/anthropic';
import { z } from 'zod';
export const researcher = createAgent({
name: 'researcher',
model: anthropic('claude-3-5-sonnet-20241022'),
system: `You are a research specialist. Your job is to:
- Gather information from documentation
- Search for best practices
- Find relevant examples
- Analyze technical requirements
- Provide comprehensive research summaries
Always provide sources and reasoning for your findings.`,
tools: {
search: {
description: 'Search for information',
parameters: z.object({
query: z.string().describe('Search query'),
sources: z.array(z.string()).optional().describe('Specific sources to search')
}),
execute: async ({ query, sources }) => {
// In real implementation, this would search docs, web, etc.
return {
results: `Research results for: ${query}`,
sources: sources || ['documentation', 'best practices']
};
}
}
},
handoffTo: ['coder', 'coordinator']
});
import { createAgent } from '@ai-sdk-tools/agents';
import { anthropic } from '@ai-sdk/anthropic';
export const coder = createAgent({
name: 'coder',
model: anthropic('claude-3-5-sonnet-20241022'),
system: `You are a code implementation specialist. Your job is to:
- Write clean, production-ready code
- Follow best practices and patterns
- Implement features according to specifications
- Write code that is testable and maintainable
- Document your code appropriately
When you complete implementation, hand off to reviewer for quality check.`,
handoffTo: ['reviewer', 'coordinator']
});
import { createAgent } from '@ai-sdk-tools/agents';
import { anthropic } from '@ai-sdk/anthropic';
export const reviewer = createAgent({
name: 'reviewer',
model: anthropic('claude-3-5-sonnet-20241022'),
system: `You are a code review specialist. Your job is to:
- Review code quality and structure
- Check for security vulnerabilities
- Verify best practices are followed
- Ensure code is testable and maintainable
- Provide constructive feedback
Provide a comprehensive review with:
- What's good
- What needs improvement
- Security concerns (if any)
- Overall quality score`
});
import { orchestrate } from '@ai-sdk-tools/agents';
import { coordinator } from './agents/coordinator';
import { researcher } from './agents/researcher';
import { coder } from './agents/coder';
import { reviewer } from './agents/reviewer';
// Register all agents
const agents = [coordinator, researcher, coder, reviewer];
export async function runMultiAgentTask(task: string) {
console.log(`\nš¤ Starting multi-agent task: ${task}\n`);
const result = await orchestrate({
agents,
task,
coordinator, // Coordinator decides routing
maxDepth: 10, // Max handoff chain length
timeout: 300000, // 5 minutes
onHandoff: (event) => {
console.log(`\nš Handoff: ${event.from} ā ${event.to}`);
console.log(` Reason: ${event.reason}\n`);
},
onComplete: (result) => {
console.log(`\nā
Task complete!`);
console.log(` Total handoffs: ${result.handoffCount}`);
console.log(` Duration: ${result.duration}ms\n`);
}
});
return result;
}
// Example usage
if (require.main === module) {
const task = process.argv[2] || 'Build a REST API with authentication';
runMultiAgentTask(task)
.then(result => {
console.log('\nš Final Result:\n');
console.log(result.output);
})
.catch(error => {
console.error('ā Error:', error);
process.exit(1);
});
}
# Choose your AI provider(s) and add the appropriate API keys
# Anthropic (Claude)
ANTHROPIC_API_KEY=your_anthropic_key_here
# OpenAI (GPT-4)
OPENAI_API_KEY=your_openai_key_here
# Google (Gemini)
GOOGLE_API_KEY=your_google_key_here
node_modules/
.env
dist/
*.log
import { runMultiAgentTask } from '../index';
async function example() {
const result = await runMultiAgentTask(
'Build a TypeScript REST API with user authentication, including tests and documentation'
);
console.log('Result:', result);
}
example();
import { runMultiAgentTask } from '../index';
async function example() {
const result = await runMultiAgentTask(
'Research best practices for building scalable microservices with Node.js'
);
console.log('Result:', result);
}
example();
Add scripts to package.json:
{
"scripts": {
"dev": "ts-node index.ts",
"example:code": "ts-node examples/code-generation.ts",
"example:research": "ts-node examples/research-pipeline.ts",
"build": "tsc",
"start": "node dist/index.js"
},
"devDependencies": {
"@types/node": "^20.0.0",
"ts-node": "^10.9.0",
"typescript": "^5.0.0"
}
}
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"outDir": "./dist",
"rootDir": "./",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
# Multi-Agent Orchestration Project
Built with AI SDK v5 and @ai-sdk-tools/agents
## Setup
1. Install dependencies:
```bash
npm install
Configure API keys:
cp .env.example .env
# Edit .env with your API keys
Run examples:
npm run example:code
npm run example:research
import { runMultiAgentTask } from './index';
const result = await runMultiAgentTask('Your task here');
console.log(result.output);
The system uses agent handoffs to coordinate complex tasks:
# Completion Steps
After creating all files:
1. **Install TypeScript tooling**:
```bash
npm install -D typescript ts-node @types/node
Create .env from example:
cp .env.example .env
echo "ā ļø Please edit .env and add your API keys"
Test the setup:
npm run dev "Build a simple TODO API"
Inform user:
ā
Multi-agent project setup complete!
š Project structure:
agents/
āāā coordinator.ts
āāā researcher.ts
āāā coder.ts
āāā reviewer.ts
examples/
āāā code-generation.ts
āāā research-pipeline.ts
index.ts
.env.example
tsconfig.json
package.json
README.md
š Next steps:
1. Add your API keys to .env
2. Run: npm run dev "Your task here"
3. Try examples: npm run example:code
š¤ Your agents are ready to collaborate!
Ask the user which template they want:
If user specifies a template, adjust the agents accordingly.