Skip to main content

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โ€‹

AgentCore roleMain tools
CEO OrchestratorTask analysis, department routing, result integrationAll tools
MarketingContent creation, campaign analysis, SEORead, Write
HRRecruiting, onboarding, performance managementRead, Write
DevCode review, tech debt, PR analysisRead, Grep, Bash
FinanceBudget analysis, spend reporting, forecastingRead, Bash
SalesCRM updates, proposals, pipelineRead, Write
LegalContract review, complianceRead
CSTicket handling, FAQ, escalationRead, 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