Consensus Configuration

Updated

The chaos.council.consensus sub-namespace controls how council votes are aggregated into a final decision. Explore available algorithms and their tunable parameters, check the current configuration, and set a new one.

Method Reference

MethodHTTPEndpointReturns
algorithms()GET/v1/council/consensus/algorithmsAvailableConsensusResponse
get()GET/v1/council/consensusConsensusConfig
set(params)PUT/v1/council/consensusConsensusConfig

Explore Available Algorithms

List all consensus algorithms available to your account. Each algorithm includes a description and its tunable parameters.

algorithms.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
const { algorithms, default_algorithm } = await chaos.council.consensus.algorithms();
 
console.log(`Default algorithm: ${default_algorithm}\n`);
 
for (const algo of algorithms) {
  console.log(`${algo.algorithm}${algo.name}`);
  console.log(`  ${algo.description}`);
 
  if (algo.parameters && algo.parameters.length > 0) {
    console.log('  Parameters:');
    for (const p of algo.parameters) {
      const req = p.required ? 'required' : 'optional';
      const def = p.default !== undefined ? ` (default: ${p.default})` : '';
      console.log(`    ${p.name} (${p.type}, ${req})${def}`);
      if (p.description) console.log(`      ${p.description}`);
    }
  } else {
    console.log('  No configurable parameters');
  }
  console.log();
}

AvailableConsensusResponse

typescript
interface AvailableConsensusResponse {
  algorithms: ConsensusAlgorithmInfo[];
  default_algorithm: string;
}
 
interface ConsensusAlgorithmInfo {
  algorithm: string;
  name: string;
  description: string;
  parameters?: AlgorithmParameter[] | null;
}
 
interface AlgorithmParameter {
  name: string;
  type: string;
  description?: string;
  required?: boolean;
  default?: unknown;
}

Get Current Configuration

Retrieve the default consensus configuration for your account.

get-config.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
const config = await chaos.council.consensus.get();
 
console.log(`Algorithm: ${config.algorithm}`);
 
if (config.parameters) {
  for (const p of config.parameters) {
    console.log(`  ${p.name}: ${p.value}`);
  }
}
 
if (config.modified_at) {
  console.log(`Last modified: ${config.modified_at}`);
}

ConsensusConfig

typescript
interface ConsensusConfig {
  algorithm: string;
  parameters?: ConsensusParameter[] | null;
  modified_at?: string | null;
}
 
interface ConsensusParameter {
  name: string;
  value: unknown;
}

Set Consensus Configuration

Update the default consensus algorithm and its parameters. The new configuration applies to all councils that do not specify their own algorithm.

set-config.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
// Set to weighted voting with a minimum confidence threshold
const updated = await chaos.council.consensus.set({
  algorithm: 'weighted_vote',
  parameters: [
    { name: 'min_confidence', value: 0.7 },
  ],
});
 
console.log(`Algorithm: ${updated.algorithm}`);
console.log(`Modified: ${updated.modified_at}`);
 
if (updated.parameters) {
  for (const p of updated.parameters) {
    console.log(`  ${p.name}: ${p.value}`);
  }
}
 
// Set to simple majority with no extra parameters
const simple = await chaos.council.consensus.set({
  algorithm: 'majority_vote',
});
[@portabletext/react] Unknown block type "callout", specify a component for it in the `components.types` prop

SetConsensusConfigParams

FieldTypeRequiredDescription
algorithmstringYesAlgorithm identifier from algorithms()
parametersArray<{ name: string; value: unknown }>NoAlgorithm-specific tuning parameters
Was this helpful?