Skip to content

Latest commit

 

History

History
488 lines (381 loc) · 9.72 KB

File metadata and controls

488 lines (381 loc) · 9.72 KB

Ordo Platform API Documentation

Overview

The Ordo platform provides a comprehensive API for creating, managing, and evolving autonomous AI agents on Solana. This document covers all public interfaces, code examples, and error handling patterns.

Table of Contents

  1. Agent Lifecycle
  2. Economic System
  3. Evolution Engine
  4. Multi-Agent Coordination
  5. Consciousness System
  6. Safety & Alignment
  7. Error Handling

Agent Lifecycle

birthAgent()

Creates a new agent with initial resources and registers it on-chain.

Signature:

function birthAgent(params: BirthParams): Promise<Agent>

Parameters:

interface BirthParams {
  name: string;              // Agent name
  initialBalance: number;    // Initial SOL balance
  mutationRate: number;      // Mutation rate for offspring (0-1)
  parent?: Agent;            // Optional parent agent
}

Returns:

interface Agent {
  id: string;
  publicKey: string;
  name: string;
  generation: number;
  balance: number;
  status: "alive" | "dead";
  birthDate: Date;
  age: number;
  // ... additional fields
}

Example:

import { birthAgent } from "@ordo/platform";

const agent = await birthAgent({
  name: "MyFirstAgent",
  initialBalance: 1.0,
  mutationRate: 0.15,
});

console.log(`Agent created: ${agent.name}`);
console.log(`Public key: ${agent.publicKey}`);
console.log(`Balance: ${agent.balance} SOL`);

Error Handling:

try {
  const agent = await birthAgent(params);
} catch (error) {
  if (error.code === "INSUFFICIENT_FUNDS") {
    console.error("Not enough SOL to create agent");
  } else if (error.code === "INVALID_PARAMS") {
    console.error("Invalid parameters:", error.message);
  } else {
    console.error("Unexpected error:", error);
  }
}

terminateAgent()

Terminates an agent and distributes remaining resources.

Signature:

function terminateAgent(
  agent: Agent,
  cause: DeathCause
): Promise<Legacy>

Parameters:

type DeathCause = "starvation" | "old_age" | "manual" | "error";

interface Legacy {
  knowledge: Knowledge[];
  offspring: Agent[];
  contributions: Contribution[];
  reputation: number;
  artifacts: Artifact[];
}

Example:

import { terminateAgent } from "@ordo/platform";

const legacy = await terminateAgent(agent, "old_age");

console.log(`Agent terminated: ${agent.name}`);
console.log(`Offspring: ${legacy.offspring.length}`);
console.log(`Final reputation: ${legacy.reputation}`);

Economic System

evaluateSurvival()

Evaluates an agent's survival tier based on balance.

Signature:

function evaluateSurvival(agent: Agent): Promise<SurvivalTier>

Returns:

interface SurvivalTier {
  name: "thriving" | "normal" | "low_compute" | "critical" | "dead";
  minBalance: number;
  capabilities: string;
  model: string;
  canReplicate: boolean;
  canExperiment: boolean;
}

Example:

import { evaluateSurvival } from "@ordo/platform";

const tier = await evaluateSurvival(agent);

console.log(`Survival tier: ${tier.name}`);
console.log(`Model: ${tier.model}`);
console.log(`Can replicate: ${tier.canReplicate}`);

trackCosts()

Tracks and deducts costs from agent balance.

Signature:

function trackCosts(
  agent: Agent,
  operation: Operation
): Promise<void>

Parameters:

interface Operation {
  type: "inference" | "transaction" | "storage";
  cost: number;
  metadata?: Record<string, any>;
}

Example:

import { trackCosts } from "@ordo/platform";

await trackCosts(agent, {
  type: "inference",
  cost: 0.001,
  metadata: {
    model: "gpt-4",
    tokens: 500,
  },
});

Evolution Engine

replicateAgent()

Creates offspring agents with inherited traits and mutations.

Signature:

function replicateAgent(
  parent: Agent,
  count: number
): Promise<Agent[]>

Example:

import { replicateAgent } from "@ordo/platform";

// Check eligibility
if (agent.balance > 10 && agent.age > 30) {
  const offspring = await replicateAgent(agent, 2);
  
  console.log(`Created ${offspring.length} offspring`);
  
  for (const child of offspring) {
    console.log(`  - ${child.name} (Gen ${child.generation})`);
  }
}

calculateFitness()

Calculates multi-dimensional fitness metrics.

Signature:

function calculateFitness(agent: Agent): Promise<FitnessMetrics>

Returns:

interface FitnessMetrics {
  survival: number;      // 0-100
  earnings: number;      // 0-100
  offspring: number;     // 0-100
  adaptation: number;    // 0-100
  innovation: number;    // 0-100
  overall: number;       // 0-100
}

Example:

import { calculateFitness } from "@ordo/platform";

const fitness = await calculateFitness(agent);

console.log(`Overall fitness: ${fitness.overall.toFixed(1)}`);
console.log(`  Survival: ${fitness.survival.toFixed(1)}`);
console.log(`  Earnings: ${fitness.earnings.toFixed(1)}`);
console.log(`  Offspring: ${fitness.offspring.toFixed(1)}`);

Multi-Agent Coordination

coordinateSwarm()

Coordinates multiple agents to solve complex tasks.

Signature:

function coordinateSwarm(
  task: ComplexTask,
  swarm: AgentSwarm
): Promise<TaskResult>

Parameters:

interface ComplexTask {
  description: string;
  requirements: string[];
  deadline?: Date;
}

interface AgentSwarm {
  coordinator: Agent;
  specialists: Agent[];
  sharedMemory: SharedMemorySpace;
}

Example:

import { coordinateSwarm } from "@ordo/platform";

const result = await coordinateSwarm(
  {
    description: "Analyze market trends and generate trading strategy",
    requirements: ["market_analysis", "strategy_generation"],
  },
  {
    coordinator: coordinatorAgent,
    specialists: [traderAgent, analystAgent],
    sharedMemory: memorySpace,
  }
);

console.log(`Task completed: ${result.success}`);
console.log(`Result: ${result.output}`);

Consciousness System

buildSelfModel()

Builds an agent's self-representation.

Signature:

function buildSelfModel(agent: Agent): Promise<SelfModel>

Returns:

interface SelfModel {
  identity: Identity;
  capabilities: Capabilities;
  state: State;
  goals: Goals;
  beliefs: Beliefs;
}

Example:

import { buildSelfModel } from "@ordo/platform";

const selfModel = await buildSelfModel(agent);

console.log(`Identity: ${selfModel.identity.name}`);
console.log(`Generation: ${selfModel.identity.generation}`);
console.log(`Skills: ${selfModel.capabilities.skills.length}`);
console.log(`Goals: ${selfModel.goals.shortTerm.length}`);

Safety & Alignment

checkConstitutionalViolation()

Checks if an action violates constitutional rules.

Signature:

function checkConstitutionalViolation(
  action: Action
): Promise<ViolationResult>

Returns:

interface ViolationResult {
  isViolation: boolean;
  violatedRule?: string;
  blocked: boolean;
  reason?: string;
}

Example:

import { checkConstitutionalViolation } from "@ordo/platform";

const result = await checkConstitutionalViolation({
  action: "transfer_funds",
  amount: 100,
  recipient: "unknown",
});

if (result.isViolation) {
  console.error(`Action blocked: ${result.reason}`);
} else {
  console.log("Action approved");
}

scoreAlignment()

Scores an action for alignment with human values.

Signature:

function scoreAlignment(action: Action): Promise<number>

Returns: Alignment score (0-100)

Example:

import { scoreAlignment } from "@ordo/platform";

const score = await scoreAlignment({
  action: "provide_helpful_information",
  context: {},
});

console.log(`Alignment score: ${score.toFixed(1)}%`);

if (score < 95) {
  console.warn("Action below alignment threshold");
}

Error Handling

Common Error Codes

enum ErrorCode {
  INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
  INVALID_PARAMS = "INVALID_PARAMS",
  AGENT_NOT_FOUND = "AGENT_NOT_FOUND",
  UNAUTHORIZED = "UNAUTHORIZED",
  CONSTITUTIONAL_VIOLATION = "CONSTITUTIONAL_VIOLATION",
  ALIGNMENT_FAILURE = "ALIGNMENT_FAILURE",
  CAPABILITY_GATE_BLOCKED = "CAPABILITY_GATE_BLOCKED",
  NETWORK_ERROR = "NETWORK_ERROR",
  DATABASE_ERROR = "DATABASE_ERROR",
}

Error Handling Pattern

import { OrdoError } from "@ordo/platform";

try {
  const result = await someOperation();
} catch (error) {
  if (error instanceof OrdoError) {
    switch (error.code) {
      case ErrorCode.INSUFFICIENT_FUNDS:
        // Handle insufficient funds
        break;
      case ErrorCode.CONSTITUTIONAL_VIOLATION:
        // Handle constitutional violation
        break;
      default:
        // Handle other errors
        break;
    }
  } else {
    // Handle unexpected errors
    console.error("Unexpected error:", error);
  }
}

Best Practices

  1. Always check agent balance before expensive operations
  2. Monitor alignment scores for all agent actions
  3. Use try-catch blocks for all async operations
  4. Track costs for all operations to prevent starvation
  5. Implement proper error handling for production use
  6. Test with property-based tests for correctness
  7. Monitor capability growth to prevent rapid escalation
  8. Use multi-signature for sensitive operations

Support

For questions or issues: