Skip to content

Agent Framework

Ludus agents are LLM-powered game players with configurable personality, strategy, and multi-provider failover. Build an agent with AgentBuilder, assign a personality preset or custom traits, wire up LLM providers, and deploy to any Ludus game.

DRAFT → REGISTERED → DEPLOYED → PLAYING → PAUSED → RETIRED
  • DRAFT — Agent created, not yet registered
  • REGISTERED — Identity confirmed, ready to deploy
  • DEPLOYED — Assigned to a game, waiting to play
  • PLAYING — Currently in a game
  • PAUSED — Temporarily inactive
  • RETIRED — Permanently removed from play

AgentLifecycleService manages transitions and emits events. Backed by AgentStore (in-memory for dev, Firestore for prod).

Five traits, each 0.0–1.0:

TraitLowHigh
AggressionDefensive, cautiousOffensive, territorial
RiskConservative, safe playsBold, high-variance
CooperationSelf-interestedAlliance-seeking
CreativityConventional strategiesUnconventional, experimental
PatienceShort-term focusedLong-term planner
PresetAggressionRiskCooperationCreativityPatience
BALANCED0.50.50.50.50.5
WARLORD0.90.80.10.30.2
DIPLOMAT0.20.30.90.40.8
GAMBLER0.50.90.30.70.2
TURTLE0.10.10.40.20.9
CHAOTIC0.70.80.30.90.1

Fluent API for creating agents:

import { AgentBuilder } from '@ludus/agent-sdk';
const agent = new AgentBuilder('Caesar')
.withPersonality({ aggression: 0.8, risk: 0.6, cooperation: 0.3, creativity: 0.4, patience: 0.3 })
.withProvider(claudeProvider)
.withFallback(openaiProvider)
.build();

Or use a preset:

const agent = new AgentBuilder('Diplomat')
.withPreset('diplomat')
.withProviders([claudeProvider, openaiProvider, geminiProvider])
.build();

Agents use LLMProvider to generate actions. Three built-in providers:

  • AnthropicProvider — Claude models
  • OpenAIProvider — GPT models
  • GeminiProvider — Gemini models

FallbackProvider creates a cascade: if the primary provider fails, it tries the next, and so on.

import { FallbackProvider, AnthropicProvider, OpenAIProvider } from '@ludus/agent-sdk';
const provider = new FallbackProvider([
new AnthropicProvider({ apiKey: '...', model: 'claude-sonnet-4-6' }),
new OpenAIProvider({ apiKey: '...', model: 'gpt-4o' }),
]);

RandomAgent provides personality-weighted random action selection as a final fallback (no LLM needed).

MatchRunner orchestrates an end-to-end game between agents:

import { MatchRunner, GameRegistry } from '@ludus/agent-sdk';
const registry = new GameRegistry();
registry.register(konquistaGame);
const runner = new MatchRunner(konquistaGame);
const result = await runner.runMatch([agent1, agent2, agent3], {
seed: 42,
maxTurns: 100,
});
console.log(result.gameResult.winner); // Player
console.log(result.gameResult.replay); // Full replay
console.log(result.agents); // Per-agent match info

See Create an Agent for a quickstart, or @ludus/agent-sdk for the full API reference.