Multi-Agent

Serve multiple agents from a single runtime

Run multiple agents together from a single server.

The Agents

import { Agent, serve } from '@reminix/runtime';

// First agent: Greeter
const greeter = new Agent('greeter');

greeter.onInvoke(async (input) => {
  const name = (input.name as string) ?? 'World';
  return { output: `Hello, ${name}! Welcome to Reminix.` };
});

greeter.onChat(async () => {
  return {
    message: {
      role: 'assistant',
      content: "Hello! I'm the greeter agent. How can I help?",
    },
  };
});

// Second agent: Calculator
const calculator = new Agent('calculator');

calculator.onInvoke(async (input) => {
  const a = (input.a as number) ?? 0;
  const b = (input.b as number) ?? 0;
  const operation = (input.operation as string) ?? 'add';

  let result: number | string;

  switch (operation) {
    case 'add':
      result = a + b;
      break;
    case 'subtract':
      result = a - b;
      break;
    case 'multiply':
      result = a * b;
      break;
    case 'divide':
      result = b !== 0 ? a / b : 'Error: Division by zero';
      break;
    default:
      result = `Unknown operation: ${operation}`;
  }

  return { output: result };
});

// Serve multiple agents together
serve([greeter, calculator], { port: 8080 });

Running

npx tsx agent.ts

Testing

# Health check shows both agents
curl http://localhost:8080/health
# {"status": "healthy", "agents": ["greeter", "calculator"]}

# Greeter agent
curl -X POST http://localhost:8080/agent/greeter/invoke \
    -H "Content-Type: application/json" \
    -d '{"input": {"name": "World"}, "stream": false}'

# Calculator agent
curl -X POST http://localhost:8080/agent/calculator/invoke \
    -H "Content-Type: application/json" \
    -d '{"input": {"a": 5, "b": 3, "operation": "add"}, "stream": false}'

Agent Endpoints

Each agent gets its own endpoints:

EndpointDescription
GET /agent/greeter/healthGreeter capabilities
POST /agent/greeter/invokeInvoke greeter
POST /agent/greeter/chatChat with greeter
GET /agent/calculator/healthCalculator capabilities
POST /agent/calculator/invokeInvoke calculator

Agent Names

Agent names must be unique and contain only:

  • Lowercase letters (a-z)
  • Numbers (0-9)
  • Hyphens (-)
  • Underscores (_)
// Valid names
new Agent('my-agent');
new Agent('agent_v2');
new Agent('chat123');

// Invalid names (will throw an error)
new Agent('My Agent');  // spaces not allowed
new Agent('Agent!');    // special characters not allowed

Next Steps

On this page