Skip to main content

Node.js Calculator

A simple but complete example of an Orpheus agent written in Node.js.

Overview

This agent demonstrates how to use the Node.js 20 runtime. It accepts a JSON payload with a math expression and returns the result. It calculates usage of eval() (safe-guarded) to process the math.

Code Structure

  • agent.js: The main entrypoint. Exports a handler function.
  • agent.yaml: Configuration specifying runtime: nodejs20.

Usage

orpheus run calculator-nodejs '{"expression": "10 * 10"}'
Returns:
{
  "result": 100,
  "status": "success"
}

Source Code

name: calculator-nodejs
runtime: nodejs20
module: agent.js
entrypoint: handler

# Memory configuration
memory: 256
memory_limit: 512

# Timeout configuration
timeout: 120
idle_timeout: 60

# Environment variables (resolved from local shell at deploy time)
env:
  - OPENAI_API_KEY=${OPENAI_API_KEY}  # Set in your environment

# Scaling configuration for load testing
scaling:
  min_workers: 1
  max_workers: 5
  target_utilization: 1.5
  scale_up_threshold: 2.0
  scale_down_threshold: 0.3
  scale_up_delay: "10s"
  scale_down_delay: "30s"
  queue_size: 20