Architecture Design
The enterprise AI team you will build in this capstone consists of a CEO orchestrator plus seven department agents. This chapter designs the overall system architecture and how the agents communicate with each other.
Overall Architectureโ
[Users / Executives]
โ
[CEO Orchestrator Agent]
task analysis โ routing โ integration
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
[Marketing] [HR] [Dev] [Finance] [Sales] [Legal] [CS]โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
[Result integration & report]
Defining Agent Rolesโ
| Agent | Core role | Main tools |
|---|---|---|
| CEO Orchestrator | Task analysis, department routing, result integration | All tools |
| Marketing | Content creation, campaign analysis, SEO | Read, Write |
| HR | Recruiting, onboarding, performance management | Read, Write |
| Dev | Code review, tech debt, PR analysis | Read, Grep, Bash |
| Finance | Budget analysis, spend reporting, forecasting | Read, Bash |
| Sales | CRM updates, proposals, pipeline | Read, Write |
| Legal | Contract review, compliance | Read |
| CS | Ticket handling, FAQ, escalation | Read, Write |
Project Structureโ
enterprise-ai-team/
โโโ src/
โ โโโ orchestrator/
โ โ โโโ ceo.ts โ CEO orchestrator
โ โ โโโ router.ts โ department routing logic
โ โโโ agents/
โ โ โโโ marketing.ts
โ โ โโโ hr.ts
โ โ โโโ dev.ts
โ โ โโโ finance.ts
โ โ โโโ sales.ts
โ โ โโโ legal.ts
โ โ โโโ cs.ts
โ โโโ shared/
โ โ โโโ types.ts โ shared type definitions
โ โ โโโ utils.ts โ utilities such as extractText
โ โ โโโ config.ts โ agent configuration
โ โโโ index.ts โ entry point
โโโ prompts/
โ โโโ ceo-system.md
โ โโโ ... โ system prompt for each agent
โโโ package.json
โโโ .env
Shared Type Definitionsโ
// src/shared/types.ts
export type Department =
| "marketing" | "hr" | "dev"
| "finance" | "sales" | "legal" | "cs";
export interface AgentRequest {
task: string;
context?: string;
priority?: "urgent" | "normal" | "low";
requestedBy?: string;
}
export interface AgentResponse {
department: Department;
result: string;
confidence: "high" | "medium" | "low";
actionItems?: string[];
escalationNeeded?: boolean;
}
export interface OrchestratorResult {
summary: string;
departmentResults: AgentResponse[];
actionItems: string[];
executiveReport: string;
}
Shared Utilitiesโ
// src/shared/utils.ts
import { SDKMessage } from "@anthropic-ai/claude-agent-sdk";
export function extractText(messages: SDKMessage[]): string {
return messages
.filter(m => m.type === "assistant")
.flatMap(m => m.content)
.filter(c => c.type === "text")
.map(c => c.text)
.join("\n");
}
export function parseJSON<T>(text: string, fallback: T): T {
try {
const match = text.match(/\{[\s\S]*\}|\[[\s\S]*\]/);
return match ? JSON.parse(match[0]) : fallback;
} catch {
return fallback;
}
}
export function log(agent: string, message: string) {
const ts = new Date().toISOString().slice(11, 19);
console.log(`[${ts}] [${agent.toUpperCase()}] ${message}`);
}
Default Agent Configurationโ
// src/shared/config.ts
import { Department } from "./types";
export interface AgentConfig {
systemPrompt: string;
maxTurns: number;
tools: string[];
}
export const AGENT_CONFIGS: Record<Department, AgentConfig> = {
marketing: {
systemPrompt: `You are a marketing strategist and content creator.
You build data-driven marketing strategies and produce high-quality content.`,
maxTurns: 12,
tools: ["Read", "Write", "Glob"]
},
hr: {
systemPrompt: `You are an HR specialist.
You have expertise in recruiting, onboarding, performance management, and strengthening organizational culture.`,
maxTurns: 10,
tools: ["Read", "Write"]
},
dev: {
systemPrompt: `You are a senior software engineer.
You specialize in reviewing code quality, architecture, security, and performance.`,
maxTurns: 15,
tools: ["Read", "Glob", "Grep", "Bash"]
},
finance: {
systemPrompt: `You are a financial analyst.
You handle budget planning, cost analysis, and financial forecasting.`,
maxTurns: 8,
tools: ["Read", "Bash"]
},
sales: {
systemPrompt: `You are a sales strategist.
You specialize in CRM management, writing proposals, and pipeline optimization.`,
maxTurns: 10,
tools: ["Read", "Write"]
},
legal: {
systemPrompt: `You are a corporate legal specialist.
You perform contract review, risk analysis, and compliance checks.
Legal advice is for reference only, and actual legal decisions require confirmation from an attorney.`,
maxTurns: 10,
tools: ["Read"]
},
cs: {
systemPrompt: `You are a customer success specialist.
You resolve customer issues quickly and courteously and raise customer satisfaction.`,
maxTurns: 8,
tools: ["Read", "Write"]
}
};
Data Flowโ
1. User request comes in
โ
2. CEO orchestrator analyzes the request
โ Which departments are needed?
โ Sequential or parallel processing?
โ
3. Run the relevant department agents
โ Single department: run directly
โ Multiple departments: run in parallel with Promise.all()
โ
4. CEO integrates the results
โ Summarize each department's result
โ Extract action items
โ Write the executive report
โ
5. Return the final result
Architecture design principles
- Single entry point: users only ever deal with the CEO agent
- Loose coupling: each department agent can be replaced or upgraded independently
- Failure isolation: one department's failure does not affect the whole system
- Extensibility: new department agents can be added easily
Found an issue on this page? Report it โ