ROE_API_KEY and ROE_ORGANIZATION_ID are set.
The first example provisions a policy and an agent from scratch; the later two
reuse an existing agent id so they stay focused on the run-and-fetch calls.
Create a policy and run a policy-aware agent
import { RoeClient } from "roe-typescript";
const client = new RoeClient();
const policy = await client.policies.create({
name: "AML Investigation Policy",
content: {
guidelines: {
categories: [
{
title: "Transaction Patterns",
rules: [
{
title: "Structuring below reporting thresholds",
flag: "RED_FLAG",
description: "Deposits just under CTR thresholds in a short window.",
},
],
},
],
},
dispositions: {
classifications: [
{ name: "SAR", description: "File a Suspicious Activity Report." },
{ name: "DISMISS", description: "Close as non-suspicious." },
],
},
},
});
const agent = await client.agents.create({
name: "AML Investigation Agent",
engineClassId: "AMLInvestigationEngine",
inputDefinitions: [
{ key: "alert_data", data_type: "text/plain", description: "Alert to investigate." },
],
engineConfig: {
policy_version_id: policy.current_version_id!,
alert_data: "${alert_data}",
},
});
const job = await client.agents.run({
agentId: agent.id,
inputs: { alert_data: "Customer made 9 cash deposits of $9,500 over three days." },
timeoutSeconds: 300,
});
const result = await job.wait({ intervalSeconds: 5, timeoutSeconds: 300 });
for (const output of result.outputs) {
console.log(`${output.key}: ${output.value}`);
}
Run an agent and download a saved reference
import { writeFile } from "node:fs/promises";
import { RoeClient } from "roe-typescript";
const client = new RoeClient();
const agentId = process.env.ROE_URL_AGENT_ID;
if (!agentId) throw new Error("Set ROE_URL_AGENT_ID");
const job = await client.agents.run({
agentId,
inputs: { url: "https://www.roe-ai.com/" },
metadata: { use_case: "website-scan" },
});
const result = await job.wait({ intervalSeconds: 5, timeoutSeconds: 300 });
for (const output of result.outputs) {
for (const ref of referencesFrom(output.value)) {
if (!ref.resource_id) continue;
const content = await client.agents.jobs.downloadReference(job.id, ref.resource_id);
await writeFile(`${ref.resource_id}.bin`, content);
}
}
function referencesFrom(value: string): Array<{ resource_id?: string }> {
try {
const payload = JSON.parse(value) as { references?: unknown };
return Array.isArray(payload.references)
? (payload.references as Array<{ resource_id?: string }>)
: [];
} catch {
return [];
}
}
Run a batch of inputs
import { RoeClient } from "roe-typescript";
const client = new RoeClient();
const agentId = process.env.ROE_TEXT_AGENT_ID;
if (!agentId) throw new Error("Set ROE_TEXT_AGENT_ID");
const batch = await client.agents.runMany({
agentId,
batchInputs: [
{ text: "Summarize the customer complaint." },
{ text: "Extract the requested follow-up action." },
],
timeoutSeconds: 300,
});
const results = await batch.wait({ intervalSeconds: 5, timeoutSeconds: 300 });
for (const result of results) {
for (const output of result.outputs) {
console.log(`${output.key}: ${output.value}`);
}
}