Build a Multi-Agent System
Use app.agents.create to create multiple specialized agents, then coordinate their runs from your server.
ts
import { AppClient } from "@uclaw/sdk";
const app = new AppClient({ apiKey: process.env.UCLAW_API_KEY });
const researcher = await app.agents.create({
title: "Researcher",
config: {
instructions: "Research the user's request and produce concise notes.",
modelTier: "fast",
},
});
const writer = await app.agents.create({
title: "Writer",
config: {
instructions: "Turn research notes into a polished answer.",
modelTier: "capable",
},
});Run Agents in Sequence
ts
async function collectText(agent: typeof researcher, input: string) {
const run = await agent.run(input);
await run.wait({ until: "running", timeoutMs: 60_000 });
let text = "";
for await (const event of run.stream()) {
if (event.type === "text-delta") text += event.delta;
}
return text;
}
const notes = await collectText(researcher, "Research durable agent runtimes.");
const answer = await collectText(writer, `Write an answer from these notes:\n${notes}`);
console.log(answer);Clean Up
ts
await app.agents.delete(researcher.id);
await app.agents.delete(writer.id);For agent-to-agent delegation inside a single run, UClaw's runtime also includes sub-agent capabilities. Use explicit server orchestration first; introduce sub-agents when you need nested autonomous work.