// RFI handling as a MultiAgentRouter: a router agent reads the question and
// hands it to one discipline specialist, which drafts the response the
// superintendent reviews before it goes to the design team.
const SWARMS_API = "https://api.swarms.world/v1/swarm/completions"
type Rfi = { number: string; subject: string; question: string; sheets: string[] }
const specialist = (name: string, model: string, scope: string) => ({
agent_name: name,
description: scope,
system_prompt:
"You are the " + name.toLowerCase() + " reviewer on a general contractor's project team. " +
"Draft a response to the RFI below. Cite every sheet, detail and spec section you rely on. " +
"Mark the draft FOR SUPERINTENDENT REVIEW at the top and list any question the design team must answer.",
model_name: model,
max_loops: 1,
})
export async function draftRfiResponse(rfi: Rfi) {
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: "RFI Desk",
description: "Route each RFI to one discipline and draft a response for review.",
swarm_type: "MultiAgentRouter",
task:
"RFI " + rfi.number + ": " + rfi.subject + "\n" +
"Referenced sheets: " + rfi.sheets.join(", ") + "\n\n" +
rfi.question,
agents: [
specialist("Structural", "claude-sonnet-5-5", "Foundations, steel, concrete, connections and load paths."),
specialist("MEP", "gpt-5.4", "Mechanical, electrical, plumbing and fire protection coordination."),
specialist("Architectural", "claude-haiku-5-5", "Finishes, partitions, doors, hardware and envelope details."),
specialist("Civil", "gemini-2.5-flash", "Grading, utilities, paving and stormwater."),
],
max_loops: 1,
}),
})
if (!res.ok) throw new Error("Swarms API " + res.status + ": " + (await res.text()))
const data = await res.json()
return { draft: data.output as string, usage: data.usage }
}
draftRfiResponse({
number: "RFI-087",
subject: "Beam penetration for 10 inch supply duct at grid C-4",
sheets: ["S-201", "S-501", "M-301"],
question:
"M-301 routes a 10 inch supply duct through W18x35 beam B-12 at grid C-4. " +
"S-501 detail 6 limits web penetrations to 6 inches. Please confirm whether a " +
"reinforced penetration is acceptable or the duct must be rerouted below the beam.",
}).then((r) => {
console.log(r.draft)
console.log(r.usage)
})