Core Types

Simplex provides a set of built-in primitive types for common operations.

Numeric Types

Type Description Example
i64 64-bit signed integer let x: i64 = 42
i32 32-bit signed integer let x: i32 = 42
f64 64-bit floating point let x: f64 = 3.14
f32 32-bit floating point let x: f32 = 3.14

Text and Boolean

Type Description Example
String UTF-8 encoded text let s = "hello"
Bool Boolean value let b = true
Char Single Unicode character let c = 'a'

Collections

List<T>

An ordered, growable collection of elements.

List methods
let items = [1, 2, 3]

items.len()                  // 3
items.push(4)                // [1, 2, 3, 4]
items.pop()                  // Some(4)
items.map(x => x * 2)        // [2, 4, 6]
items.filter(x => x > 1)     // [2, 3]
items.reduce(0, (a, b) => a + b)  // 6
items.contains(2)            // true
items.is_empty()             // false
items.first()                // Some(1)
items.last()                 // Some(3)

Map<K, V>

A key-value collection with unique keys.

Map methods
let data = {"name": "Alice", "age": "30"}

data.get("name")            // Some("Alice")
data.insert("city", "NYC") // adds key-value
data.remove("age")          // removes key
data.contains_key("name")  // true
data.keys()                 // ["name", "city"]
data.values()               // ["Alice", "NYC"]
data.len()                  // 2

Set<T>

An unordered collection of unique elements.

Set methods
let tags = {"rust", "ai", "web"insert("api")          // adds element
tags.remove("web")          // removes element
tags.contains("ai")        // true
tags.union(other_set)       // set union
tags.intersection(other)   // set intersection

Specialists & Hives

Functions for working with specialists, hives, and message passing.

Specialist Functions

Function Description Returns
spawn T Create a new specialist instance SpecialistRef<T>
send(specialist, msg) Send message (fire-and-forget) ()
ask(specialist, msg) Send message and wait for reply T
checkpoint() Persist specialist state and Anima ()
stop(specialist) Gracefully stop a specialist ()

Hive Functions

Function Description Returns
hive.spawn<T>() Spawn specialist within hive SpecialistRef<T>
hive.route(task) Route task to best specialist SpecialistRef
hive.broadcast(msg) Send message to all specialists ()
hive.specialists() List all specialists in hive List<SpecialistRef>

Anima API

The Anima is the cognitive core of each specialist, providing memory, beliefs, and intentions.

Memory Operations

anima-memory.sx
// Store a memory (episodic by default)
self.anima.remember(key, value)
self.anima.remember(key, value, type: MemoryType::Semantic)

// Recall memories by query
let memories = self.anima.recall_for(query, limit: 5)

// Recall by similarity (semantic search)
let similar = self.anima.recall_similar(embedding, limit: 10)

// Get specific memory by key
let memory = self.anima.recall(key)  // Option<Memory>

// Forget a memory
self.anima.forget(key)

Belief Management

anima-beliefs.sx
// Form a belief with confidence (0.0-1.0)
self.anima.believe("user_prefers_dark_mode", true, confidence: 0.85)

// Get a belief
let belief = self.anima.beliefs.get("user_prefers_dark_mode")
// Returns Belief { value: true, confidence: 0.85 }

// Check if belief exceeds threshold
if self.anima.beliefs.confident("key", threshold: 0.7) {
    // Act on confident belief
}

// Revise belief with new evidence
self.anima.revise("deadline", "Monday", evidence: 0.9)

// List all beliefs
let all_beliefs = self.anima.beliefs.all()

Anima Memory Types

Type Description Use Case
MemoryType::Episodic Specific experiences with timestamps Conversation history, events
MemoryType::Semantic Generalized facts and knowledge Learned patterns, facts
MemoryType::Procedural Skills and behavioral patterns How to perform tasks
MemoryType::Working Active context for current task Current conversation state

HiveMnemonic API

HiveMnemonic provides shared consciousness across all specialists in a hive.

hive-mnemonic.sx
// Share knowledge with the hive (50% confidence threshold)
hive.mnemonic.learn(insight, confidence: 0.75)

// Query shared knowledge
let shared = hive.mnemonic.recall_for(query, limit: 10)

// Get shared beliefs
let hive_belief = hive.mnemonic.beliefs.get("project_deadline")

// Promote individual memory to shared
hive.mnemonic.promote(self.anima.recall("discovery"))

// Subscribe to hive updates
hive.mnemonic.on_learn(|memory| {
    println("Hive learned: {}", memory.key)
})

Memory Hierarchy Thresholds

Level Threshold Description
Anima (Specialist) 30% Personal beliefs, easily revised
Mnemonic (Hive) 50% Shared beliefs, requires more evidence
Divine (Solution) 70% Global truths, highly stable

Inference

The infer() function uses the hive's shared SLM for AI operations.

Basic Inference

inference.sx
// Basic inference using hive SLM
let response = infer(prompt)

// Inference with memory context
let memories = self.anima.recall_for(query, limit: 5)
let response = infer(prompt, context: memories)

// Inference with system prompt
let response = infer(prompt, system: "You are a helpful analyst.")

Structured Extraction

extraction.sx
// Extract structured data into a type
struct Invoice {
    vendor: String,
    amount: f64,
    date: Date,
}

let invoice = infer<Invoice>(document)

// Classify into enum variants
enum Sentiment { Positive, Negative, Neutral }
let sentiment = infer<Sentiment>(text)

Inference Options

Option Type Description
context List<Memory> Memory context to include
system String System prompt override
temperature f64 Sampling temperature (0.0-2.0)
max_tokens i64 Maximum response length

I/O Operations

Function Description
print(msg) Print to stdout
println(msg) Print with newline
read_file(path) Read file contents
write_file(path, content) Write to file
http::get(url) HTTP GET request
http::post(url, body) HTTP POST request

Concurrency

Function Description
await future Wait for async operation
parallel(futures...) Run futures concurrently, wait for all
race(futures...) Return first completed future
timeout(duration, future) Add timeout to future
sleep(duration) Pause execution

Error Handling

Option<T>

Option<T>
let maybe: Option<i64> = Some(42)

maybe.unwrap()              // 42 (panics if None)
maybe.unwrap_or(0)          // 42 (returns 0 if None)
maybe.is_some()             // true
maybe.is_none()             // false
maybe.map(x => x * 2)       // Some(84)

Result<T, E>

Result<T, E>
let result: Result<i64, Error> = Ok(42)

result.unwrap()             // 42 (panics if Err)
result.unwrap_or(0)         // 42 (returns 0 if Err)
result.is_ok()              // true
result.is_err()             // false

// Propagate errors with ?
fn process() -> Result<Data, Error> {
    let data = load_data()?   // returns early if Err
    Ok(transform(data))
}

Full Documentation

For complete API documentation including all modules and detailed examples, visit the GitHub repository.