CEO Orchestrator
The CEO orchestrator is the brain and coordinator of an enterprise AI team. It analyzes user requests, decides which departments are needed, delegates to the corresponding agents, and then integrates the results into a report.
The CEO's Responsibilitiesโ
- Request analysis: Determine which department capabilities the incoming task requires
- Routing: Delegate work to a single department agent or several
- Parallel coordination: Run independent department tasks concurrently
- Result integration: Combine each department's output into a meaningful report
- Escalation: Detect complex issues and hand them off to a human
Implementing the CEO Routerโ
// src/orchestrator/router.ts
import { query } from "@anthropic-ai/claude-agent-sdk";
import { Department, AgentRequest } from "../shared/types";
import { extractText, parseJSON, log } from "../shared/utils";
interface RoutingDecision {
departments: Department[];
parallel: boolean;
reasoning: string;
}
export async function routeRequest(
request: AgentRequest
): Promise<RoutingDecision> {
const routingResponse = await query({
prompt: `As the router for an enterprise AI team, analyze the following request.
Request: ${request.task}
${request.context ? `Context: ${request.context}` : ""}
Available departments:
- marketing: marketing, content, branding, SEO, campaigns
- hr: hiring, HR, training, performance management, org culture
- dev: code, development, engineering, systems, infrastructure
- finance: finance, budgeting, accounting, cost, investment
- sales: sales, customer acquisition, proposals, CRM, pipeline
- legal: contracts, legal, compliance, regulations, patents
- cs: customer support, complaint handling, satisfaction, feedback
Output only the following JSON:
{
"departments": ["dept1", "dept2"],
"parallel": true,
"reasoning": "explanation"
}`,
options: { maxTurns: 3 }
});
const text = extractText(routingResponse);
return parseJSON<RoutingDecision>(text, {
departments: ["cs"],
parallel: false,
reasoning: "Default CS routing"
});
}
Implementing the Main CEO Orchestratorโ
// src/orchestrator/ceo.ts
import { query } from "@anthropic-ai/claude-agent-sdk";
import { routeRequest } from "./router";
import { runMarketingAgent } from "../agents/marketing";
import { runHRAgent } from "../agents/hr";
import { runDevAgent } from "../agents/dev";
import { runFinanceAgent } from "../agents/finance";
import { runSalesAgent } from "../agents/sales";
import { runLegalAgent } from "../agents/legal";
import { runCSAgent } from "../agents/cs";
import {
Department, AgentRequest, AgentResponse, OrchestratorResult
} from "../shared/types";
import { extractText, log } from "../shared/utils";
const AGENT_RUNNERS: Record<
Department,
(task: string) => Promise<AgentResponse>
> = {
marketing: runMarketingAgent,
hr: runHRAgent,
dev: runDevAgent,
finance: runFinanceAgent,
sales: runSalesAgent,
legal: runLegalAgent,
cs: runCSAgent
};
export async function runCEO(
request: AgentRequest
): Promise<OrchestratorResult> {
log("CEO", `Request received: ${request.task.slice(0, 50)}...`);
// Step 1: Routing decision
const routing = await routeRequest(request);
log("CEO", `Routing: ${routing.departments.join(", ")} (${routing.parallel ? "parallel" : "sequential"})`);
// Step 2: Run department agents
let departmentResults: AgentResponse[];
if (routing.parallel) {
const results = await Promise.allSettled(
routing.departments.map(dept => {
log("CEO", `Starting ${dept} agent`);
return AGENT_RUNNERS[dept](request.task);
})
);
departmentResults = results
.filter(r => r.status === "fulfilled")
.map(r => (r as PromiseFulfilledResult<AgentResponse>).value);
const failedCount = results.filter(r => r.status === "rejected").length;
if (failedCount > 0) log("CEO", `Warning: ${failedCount} department(s) failed`);
} else {
departmentResults = [];
for (const dept of routing.departments) {
log("CEO", `Running ${dept} agent...`);
const prevContext = departmentResults
.map(r => `[${r.department}]: ${r.result.slice(0, 200)}`)
.join("\n");
const taskWithContext = prevContext
? `${request.task}\n\nPrevious department results:\n${prevContext}`
: request.task;
const result = await AGENT_RUNNERS[dept](taskWithContext);
departmentResults.push(result);
}
}
// Step 3: Integrate results and produce an executive report
log("CEO", "Integrating results...");
const summaryResponse = await query({
prompt: `As the CEO, synthesize the following department reports into an executive report.
Original request: ${request.task}
Results by department:
${departmentResults.map(r =>
`## ${r.department.toUpperCase()} team\n${r.result}`
).join("\n\n")}
Report format:
1. Executive summary (3 lines max)
2. Key findings by department
3. Immediately actionable items
4. Risks and cautions`,
options: { maxTurns: 5 }
});
const executiveReport = extractText(summaryResponse);
const actionItems = departmentResults
.flatMap(r => r.actionItems || [])
.filter(Boolean);
log("CEO", "Done");
return {
summary: executiveReport.slice(0, 500),
departmentResults,
actionItems,
executiveReport
};
}
Entry Pointโ
// src/index.ts
import { runCEO } from "./orchestrator/ceo";
async function main() {
const result = await runCEO({
task: "Plan the Q1 marketing campaign, analyze the budget, and identify the engineering resources we'll need",
priority: "urgent",
requestedBy: "CFO"
});
console.log("\n===== Executive Report =====");
console.log(result.executiveReport);
console.log("\n===== Action Items =====");
result.actionItems.forEach((item, i) => {
console.log(`${i + 1}. ${item}`);
});
}
main().catch(console.error);
Example Runโ
Input: "Review company-wide readiness for launching our new SaaS product"
โ CEO routing: marketing, dev, sales, legal (parallel)
Running departments concurrently (~2-3 minutes)...
Executive report:
"Marketing has the social campaign ready. Engineering is preparing the beta
deployment and needs to resolve 2 security issues. Sales has secured a
50-deal pipeline. Legal flagged 1 recommended change to the privacy policy."
Action items:
1. Engineering: apply the security patches immediately
2. Legal: revise clause 3 of the privacy policy
3. Marketing: confirm the scheduled launch D-7 social posts
Optimizing the CEO Agent
- Use a low-cost model (Haiku) for routing decisions to cut costs
- Always run independent department tasks in parallel
- Keep the executive report to one page for readability
Found an issue on this page? Report it โ