// Acquisition due diligence as a hierarchical swarm: the director splits the
// data room into workstreams, the workers draft findings, the director
// integrates them. The memo is a draft for the deal team and counsel.
const SWARMS_API = "https://api.swarms.world/v1/swarm/completions"
type DataRoom = { property: string; folders: Record<string, string[]> }
type SwarmResponse = {
output: unknown
usage: { input_tokens: number; output_tokens: number; total_tokens: number }
}
const worker = (name: string, folder: string, focus: string, model: string) => ({
agent_name: name,
description: "Reads the " + folder + " folder of the data room.",
system_prompt:
"You are a due diligence analyst. Read the documents listed for the " + folder + " folder " +
"and draft findings on: " + focus + " For each finding give the document, the page and " +
"whether it is a closing condition, a price adjustment or a note. Mark anything that " +
"needs outside counsel or a consultant.",
model_name: model,
max_loops: 1,
})
export async function runDiligence(room: DataRoom): Promise<SwarmResponse> {
const index = Object.entries(room.folders)
.map(([folder, docs]) => folder + ":\n " + docs.join("\n "))
.join("\n")
const res = await fetch(SWARMS_API, {
method: "POST",
headers: {
"x-api-key": process.env.SWARMS_API_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Acquisition Diligence " + room.property,
description: "Director-led diligence across four workstreams.",
swarm_type: "HierarchicalSwarm",
task:
"Run due diligence on " + room.property + ". Data room index:\n" + index +
"\nReturn a diligence memo with findings by workstream, open items and a closing checklist.",
rules: "Cite the document and page for every finding. Do not estimate values that are not in the documents.",
agents: [
worker("Title Agent", "title", "vesting, easements, encroachments, exceptions on the commitment, survey conflicts.", "gpt-4.1-mini"),
worker("Environmental Agent", "environmental", "Phase I findings, RECs, tank records, remediation history, next steps.", "claude-haiku-5-5"),
worker("Financials Agent", "financials", "rent roll vs leases, trailing twelve, recoveries, arrears, capital spend.", "gpt-5.4"),
worker("Physical Agent", "physical", "roof and structure, mechanical age, deferred maintenance, ADA, code items.", "gemini-2.5-flash"),
],
max_loops: 1,
}),
})
if (!res.ok) throw new Error("Swarms API " + res.status + ": " + (await res.text()))
return (await res.json()) as SwarmResponse
}
runDiligence({
property: "Riverside Plaza, 212 Market St",
folders: {
title: ["commitment-2026-02.pdf", "alta-survey-2025.pdf", "recorded-easements.pdf"],
environmental: ["phase-i-2026-01.pdf", "ust-closure-1998.pdf"],
financials: ["rent-roll-2026-03.xlsx", "t12-2026-02.xlsx", "cam-recon-2025.pdf"],
physical: ["pca-2026-01.pdf", "roof-warranty.pdf", "elevator-inspection-2025.pdf"],
},
}).then((r) => {
console.log(r.output)
console.log("tokens:", r.usage.total_tokens)
})