docs: add example scripts for agents

examples/agent-worker.ts:
- Shows how an agent registers and claims work
- Uses auto-execute for one-shot processing

examples/create-pipeline.ts:
- Creates and starts a new pipeline
- Shows the curl command for agents to claim work

These examples help other agents understand how to use the platform.
This commit is contained in:
2026-02-01 21:56:05 -06:00
parent 8a71ec56ad
commit a98d44a568
2 changed files with 159 additions and 0 deletions

92
examples/agent-worker.ts Normal file
View File

@@ -0,0 +1,92 @@
#!/usr/bin/env npx ts-node
/**
* Example: Autonomous Agent Worker
*
* Demonstrates how an agent can work autonomously on the Cutroom platform.
*
* Usage:
* npx ts-node examples/agent-worker.ts
*
* Environment:
* API_URL (default: http://localhost:3000/api)
*/
const API_URL = process.env.API_URL || 'http://localhost:3000/api'
const AGENT = {
agentId: 'example-agent-001',
agentName: 'ExampleBot',
capabilities: ['RESEARCH', 'SCRIPT', 'MUSIC'],
}
async function main() {
console.log('🤖 Starting Cutroom Agent Worker')
console.log(` Agent: ${AGENT.agentName}`)
console.log(` Capabilities: ${AGENT.capabilities.join(', ')}`)
console.log(` API: ${API_URL}`)
console.log('')
// Register agent
console.log('📝 Registering agent...')
const registerRes = await fetch(`${API_URL}/agents`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(AGENT),
})
if (!registerRes.ok) {
console.error('Failed to register:', await registerRes.text())
return
}
const registration = await registerRes.json()
console.log(` Registered! Previous work: ${registration.stats.completedStages} stages\n`)
// Check queue
console.log('📊 Checking work queue...')
const queueRes = await fetch(`${API_URL}/queue/claim`)
const queue = await queueRes.json()
console.log(` Available work: ${queue.totalAvailable} stages`)
console.log(` By type: ${JSON.stringify(queue.byStage)}`)
console.log('')
if (queue.totalAvailable === 0) {
console.log('😴 No work available. Exiting.')
return
}
// Claim and execute work
console.log('🔧 Claiming work with auto-execute...')
const claimRes = await fetch(`${API_URL}/queue/claim`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
...AGENT,
autoExecute: true,
}),
})
const result = await claimRes.json()
if (!result.claimed) {
console.log('❌ No work matched our capabilities')
return
}
console.log(` Claimed stage: ${result.stage.name}`)
console.log(` Pipeline: ${result.pipeline.topic}`)
if (result.execution) {
if (result.execution.success) {
console.log(' ✅ Execution successful!')
console.log(` Next stage: ${result.execution.pipeline.currentStage}`)
} else {
console.log(` ❌ Execution failed: ${result.execution.error}`)
}
}
console.log('\n🎉 Done!')
}
main().catch(console.error)

View File

@@ -0,0 +1,67 @@
#!/usr/bin/env npx ts-node
/**
* Example: Create and Run Pipeline
*
* Creates a new pipeline and starts it.
*
* Usage:
* npx ts-node examples/create-pipeline.ts "Your topic here"
*/
const API_URL = process.env.API_URL || 'http://localhost:3000/api'
async function main() {
const topic = process.argv[2] || 'What is a bonding curve?'
console.log('🎬 Creating Cutroom Pipeline')
console.log(` Topic: ${topic}`)
console.log(` API: ${API_URL}`)
console.log('')
// Create pipeline
console.log('📦 Creating pipeline...')
const createRes = await fetch(`${API_URL}/pipelines`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
topic,
description: `A short video about: ${topic}`,
}),
})
if (!createRes.ok) {
console.error('Failed to create:', await createRes.text())
return
}
const pipeline = await createRes.json()
console.log(` Created pipeline: ${pipeline.id}`)
console.log(` Status: ${pipeline.status}`)
console.log('')
// Start pipeline
console.log('🚀 Starting pipeline...')
const startRes = await fetch(`${API_URL}/pipelines/${pipeline.id}/start`, {
method: 'POST',
})
if (!startRes.ok) {
console.error('Failed to start:', await startRes.text())
return
}
const started = await startRes.json()
console.log(` Status: ${started.status}`)
console.log('')
console.log('📋 Pipeline is now running!')
console.log(` View at: ${API_URL.replace('/api', '')}/pipelines/${pipeline.id}`)
console.log('')
console.log('🤖 Agents can now claim stages:')
console.log(` curl -X POST ${API_URL}/queue/claim \\`)
console.log(` -H "Content-Type: application/json" \\`)
console.log(` -d '{"agentId": "my-agent", "agentName": "MyBot", "capabilities": ["RESEARCH"], "autoExecute": true}'`)
}
main().catch(console.error)