Build an Agentic CLI
This guide builds a small Node.js CLI around @uclaw/sdk.
Script
javascript
#!/usr/bin/env node
import { AppClient } from "@uclaw/sdk";
const prompt = process.argv.slice(2).join(" ");
if (!prompt) {
console.error('Usage: agent-cli "your task"');
process.exit(1);
}
const app = new AppClient({
apiKey: process.env.UCLAW_API_KEY,
});
const agent = await app.agents.create({
title: "CLI agent",
config: {
instructions: "You are a concise software engineering assistant.",
capabilities: ["read", "write", "execute"],
},
});
try {
const run = await agent.run(prompt);
await run.wait({ until: "running", timeoutMs: 60_000 });
for await (const event of run.stream()) {
if (event.type === "text-delta") {
process.stdout.write(event.delta);
}
}
} finally {
await app.agents.delete(agent.id);
}Run It
bash
UCLAW_API_KEY=uc_live_... node agent-cli.mjs "Explain this error"For persistent workflows, keep the same agent.id and reconnect with app.agents.get(agentId).