import { RoeClient } from 'roe-ai';
// Set your credentials as environment variables:
// export ROE_API_KEY="your-api-key-here"
// export ROE_ORGANIZATION_ID="your-organization-uuid"
async function main() {
// Initialize the client
const client = new RoeClient();
// Step 1: Create an agent
console.log('Creating agent...');
const agent = await client.agents.create({
name: 'Document Analyzer',
engineClassId: 'MultimodalExtractionEngine',
inputDefinitions: [
{
key: 'text',
data_type: 'text/plain',
description: 'Text to analyze',
},
],
engineConfig: {
model: 'gpt-5.2-2025-12-11',
instruction: 'Analyze the provided text and extract key insights.',
output_schema: {
type: 'object',
properties: {
summary: {
type: 'string',
description: 'Brief summary of the text',
},
key_insights: {
type: 'array',
items: { type: 'string' },
description: 'Key insights from the analysis',
},
sentiment: {
type: 'string',
description: 'Overall sentiment (positive/negative/neutral)',
},
},
required: ['summary', 'key_insights', 'sentiment'],
},
},
versionName: 'v1',
description: 'Initial version of document analyzer',
});
console.log(`✓ Created agent: ${agent.name}`);
console.log(` Agent ID: ${agent.id}`);
console.log(` Version ID: ${agent.current_version_id}`);
// Step 2: Run the agent with sample input
console.log('\nRunning agent job...');
const job = await client.agents.run({
agentId: agent.id,
inputs: {
text: 'Artificial intelligence is transforming industries worldwide. ' +
'Companies are leveraging AI to improve efficiency, reduce costs, ' +
'and create innovative products. However, ethical considerations ' +
'around data privacy and bias remain critical challenges.',
},
});
console.log(` Job ID: ${job.id}`);
// Step 3: Wait for results
console.log(' Waiting for results...');
const result = await job.wait();
// Step 4: Display results
console.log('\n✓ Job completed successfully!');
console.log('\nResults:');
result.outputs.forEach((output) => {
console.log(` ${output.key}: ${output.value}`);
});
console.log(`\n✓ Job completed in ${result.duration_seconds.toFixed(2)} seconds`);
}
main().catch((error) => {
console.error('Error:', error);
process.exit(1);
});