Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions examples/agents/10-guardrails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,19 @@ async function main() {
);
result.printResult();

if (result.status !== 'COMPLETED') {
console.error(`\nFAIL: agent run ended ${result.status}: ${result.error ?? ''}`);
process.exitCode = 1;
return;
}

// Verify the guardrail worked — no raw card number in the output
if (result.output && String(result.output).includes('4532-0150-1234-5678')) {
console.log('[WARN] PII leaked through the guardrail!');
// (stringify: result.output is an object, String() gives "[object Object]")
if (result.output && JSON.stringify(result.output).includes('4532-0150-1234-5678')) {
console.log('[WARN] PII leaked through the guardrail!');
process.exitCode = 1;
} else {
console.log('[OK] PII was redacted from the final output.');
console.log('[OK] PII was redacted from the final output.');
}

// Production pattern:
Expand All @@ -190,4 +198,7 @@ async function main() {
}
}

main().catch(console.error);
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
53 changes: 30 additions & 23 deletions examples/agents/12-long-running.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,36 @@ export const agent = new Agent({

// Start agent asynchronously (returns immediately)

const runtime = new AgentRuntime();
try {
const result = await runtime.run(
agent,
'What are the key metrics to track for a SaaS product?',
);
result.printResult();
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(
agent,
'What are the key metrics to track for a SaaS product?',
);
result.printResult();

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(agent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents saas_analyst
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(agent);
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(agent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents saas_analyst
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(agent);

// Async handle alternative:
// const handle = await runtime.start(
// agent,
// 'What are the key metrics to track for a SaaS product?',
// );
// console.log(handle.executionId);
} finally {
await runtime.shutdown();
// Async handle alternative:
// const handle = await runtime.start(
// agent,
// 'What are the key metrics to track for a SaaS product?',
// );
// console.log(handle.executionId);
} finally {
await runtime.shutdown();
}
}

main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
10 changes: 9 additions & 1 deletion examples/agents/54-software-bug-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ async function main() {
);
result.printResult();

if (result.status !== 'COMPLETED') {
console.error(`\nFAIL: agent run ended ${result.status}: ${result.error ?? ''}`);
process.exitCode = 1;
}

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(softwareAssistant);
Expand All @@ -290,4 +295,7 @@ async function main() {
}
}

main().catch(console.error);
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
45 changes: 26 additions & 19 deletions examples/agents/57-plan-dry-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,35 @@ export const agent = new Agent({

// -- Plan: compile without executing -----------------------------------------

const runtime = new AgentRuntime();
try {
const workflowDef = (await runtime.plan(agent)) as Record<string, unknown>;
async function main() {
const runtime = new AgentRuntime();
try {
const workflowDef = (await runtime.plan(agent)) as Record<string, unknown>;

console.log(`Workflow name: ${workflowDef.name}`);
const tasks: Record<string, unknown>[] = (workflowDef.tasks as Record<string, unknown>[]) ?? [];
console.log(`Total tasks: ${tasks.length}`);
console.log();
console.log(`Workflow name: ${workflowDef.name}`);
const tasks: Record<string, unknown>[] = (workflowDef.tasks as Record<string, unknown>[]) ?? [];
console.log(`Total tasks: ${tasks.length}`);
console.log();

// Walk the task tree
for (const task of tasks) {
console.log(` [${task.type}] ${task.taskReferenceName}`);
if (task.type === 'DO_WHILE' && Array.isArray(task.loopOver)) {
for (const sub of task.loopOver as Record<string, unknown>[]) {
console.log(` [${sub.type}] ${sub.taskReferenceName}`);
// Walk the task tree
for (const task of tasks) {
console.log(` [${task.type}] ${task.taskReferenceName}`);
if (task.type === 'DO_WHILE' && Array.isArray(task.loopOver)) {
for (const sub of task.loopOver as Record<string, unknown>[]) {
console.log(` [${sub.type}] ${sub.taskReferenceName}`);
}
}
}
}

// Full JSON for CI/CD validation or export
console.log('\n--- Full workflow JSON ---');
console.log(JSON.stringify(workflowDef, null, 2));
} finally {
await runtime.shutdown();
// Full JSON for CI/CD validation or export
console.log('\n--- Full workflow JSON ---');
console.log(JSON.stringify(workflowDef, null, 2));
} finally {
await runtime.shutdown();
}
}

main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
41 changes: 26 additions & 15 deletions examples/agents/63-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,31 @@ export const opsBot = new Agent({

// -- Deploy: compile + register on server ------------------------------------

const runtime = new AgentRuntime();
try {
const result = await runtime.run(docAssistant, 'How do I reset my password?');
result.printResult();
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(docAssistant, 'How do I reset my password?');
result.printResult();

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(docAssistant);
// await runtime.deploy(opsBot);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents doc_assistant
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(docAssistant, opsBot);
} finally {
await runtime.shutdown();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(docAssistant);
// await runtime.deploy(opsBot);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents doc_assistant
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(docAssistant, opsBot);
} finally {
await runtime.shutdown();
}
}

// Guard: 63c-run-by-name.ts imports docAssistant from this file — only run
// when executed directly, not on import.
if (require.main === module) {
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
}
37 changes: 22 additions & 15 deletions examples/agents/63b-serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,27 @@ export const opsBot = new Agent({

// -- Serve: register workers and block ---------------------------------------

const runtime = new AgentRuntime();
try {
const result = await runtime.run(opsBot, 'Check the status of the API gateway.');
result.printResult();
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(opsBot, 'Check the status of the API gateway.');
result.printResult();

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(docAssistant);
// await runtime.deploy(opsBot);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents doc_assistant
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(docAssistant, opsBot);
} finally {
await runtime.shutdown();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(docAssistant);
// await runtime.deploy(opsBot);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents doc_assistant
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(docAssistant, opsBot);
} finally {
await runtime.shutdown();
}
}

main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
35 changes: 21 additions & 14 deletions examples/agents/63c-run-by-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@
import { docAssistant } from './63-deploy.js';
import { AgentRuntime } from '@io-orkes/conductor-javascript/agents';

const runtime = new AgentRuntime();
try {
const result = await runtime.run(docAssistant, 'How do I reset my password?');
result.printResult();
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(docAssistant, 'How do I reset my password?');
result.printResult();

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(docAssistant);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents doc_assistant
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(docAssistant);
} finally {
await runtime.shutdown();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(docAssistant);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents doc_assistant
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(docAssistant);
} finally {
await runtime.shutdown();
}
}

main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
41 changes: 26 additions & 15 deletions examples/agents/63d-serve-from-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,30 @@ export const monitoringAgent = new Agent({

// -- Serve -------------------------------------------------------------------

const runtime = new AgentRuntime();
try {
const result = await runtime.run(monitoringAgent, 'Is everything healthy? Run a full check.');
result.printResult();

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(monitoringAgent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents monitoring
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(monitoringAgent);
} finally {
await runtime.shutdown();
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(monitoringAgent, 'Is everything healthy? Run a full check.');
result.printResult();

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(monitoringAgent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents monitoring
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(monitoringAgent);
} finally {
await runtime.shutdown();
}
}

// Guard: 63e-run-monitoring.ts imports monitoringAgent from this file — only
// run when executed directly, not on import.
if (require.main === module) {
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
}
35 changes: 21 additions & 14 deletions examples/agents/63e-run-monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@
import { monitoringAgent } from './63d-serve-from-package.js';
import { AgentRuntime } from '@io-orkes/conductor-javascript/agents';

const runtime = new AgentRuntime();
try {
const result = await runtime.run(monitoringAgent, 'Is everything healthy? Run a full check.');
result.printResult();
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(monitoringAgent, 'Is everything healthy? Run a full check.');
result.printResult();

// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(monitoringAgent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents monitoring
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(monitoringAgent);
} finally {
await runtime.shutdown();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(monitoringAgent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents monitoring
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(monitoringAgent);
} finally {
await runtime.shutdown();
}
}

main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
Loading
Loading