Skip to content

FlexNetOS/teri

Β 
Β 

Teri

Rust-native Swarm Intelligence Prediction Engine A ground-up rewrite of MiroFish β€” designed for performance, type safety, and deployment simplicity.

Name: "Teri" (Indonesian: ikan teri) is the anchovy β€” one of the smallest fish in the sea, yet one of the most consequential. Anchovies move in vast, tightly coordinated schools: thousands of individuals following simple local rules, producing emergent behavior no single fish planned or directed. That is exactly what this engine does. Seed the world. Spawn the swarm. Watch emergence happen.


What is Teri?

Teri turns seed materials (news articles, policy drafts, financial signals, novels, or live community knowledge) into a high-fidelity parallel digital world populated by independent agents. Each agent carries its own persona, long-term memory, and behavioral logic. The swarm self-organizes, and you observe β€” or intervene β€” from a God's-eye view.

Input β†’ seed file or community platform signal + natural-language prediction query Output β†’ structured prediction report + interactive living simulation world

Key Features

  • 🧠 Multi-Provider LLM Support - OpenAI, Anthropic, Google Gemini, local models (Ollama, LM Studio, shimmy) via adapter pattern
  • πŸ¦€ Rust-native - Fast, type-safe, zero-GIL overhead for future parallelism
  • πŸ’Ύ Persistent Memory - redb-backed agent long-term memory
  • πŸ”Œ Zero Vendor Lock-in - Adapter pattern for any OpenAI-compatible LLM provider
  • πŸ“¦ Single Binary - cargo build --release, no Docker required
  • ⚑ Envctl Auto-Injection - Secrets auto-injected via envctl run -- teri ...
  • 🧠 Multi-Provider LLM Support β€” OpenAI, Anthropic, Google Gemini, local models (Ollama, LM Studio, vLLM, shimmy)
  • βš™οΈ Concurrent agent simulation β€” two-phase ticks with bounded tokio concurrency (SIM_PARALLELISM)
  • πŸ’Ύ Persistent Memory β€” Rust-native redb for fast agent long-term memory
  • πŸ›‘οΈ Backend honesty guard β€” preflight refuses stub/canned inference backends before any run
  • 🎯 Zero Vendor Lock-in β€” adapter pattern for any LLM provider
  • πŸ“¦ Single Binary β€” no Docker, no venv, just cargo build --release
  • πŸ”Œ Community Platform Adapters β€” ingest live community signal from Pebesen, Reddit, Zulip, Discourse; write predictions back via CommunityFeedback
  • 🌐 Streaming-ready β€” SSE stream types are built (api/streaming); the HTTP server itself lands in the serve phase (see Status)

Quick Start

Prerequisites

Concern Python (MiroFish) Teri (Rust)
Agent concurrency GIL-limited threads tokio bounded concurrency
Memory per agent ~MB overhead Controlled, stack-friendly
Deployment Docker + venv Single static binary
Type safety Runtime errors Compile-time guarantees
Async LLM calls asyncio tokio native
  1. LLM API Key β€” one of:

    # Direct (manual):
    export LLM_API_KEY=sk-...
    
    # Or via envctl (recommended):
    # Ensure your LLM provider is registered in envctl's vault
  2. Optional backend config:

    export LLM_BASE_URL=https://api.openai.com/v1  # default
    export LLM_MODEL=gpt-4o                          # default

Run a Simulation

# With envctl (auto-inject secrets):
envctl run -- teri run \
  --seed ./examples/seed.txt \
  --query "How will this policy affect public sentiment in 30 days?"

# Or directly:
LLM_API_KEY=sk-... cargo run --release -- run \
# CLI surface works without any secrets:
cargo run --release -- --help

# Secrets arrive via envctl injection (vault-held, child-env only):
#   env-ctl secret add teri-llm --provider openai --value-stdin   # one-time registration
#   env-ctl run --provider openai -- teri run ...                 # canonical invocation
# For local development only, a .env file (gitignored) is accepted:
cp .env.example .env

# Run a simulation (preflights the inference backend, then runs the pipeline*)
cargo run --release -- run \
  --seed ./examples/seed.txt \
  --query "How will this policy affect public sentiment in 30 days?"

Start REST API Server

envctl run -- teri serve --addr 0.0.0.0:8080
# Start REST API server (*see Status β€” server wiring is the serve-phase milestone)
cargo run --release -- serve --addr 0.0.0.0:8080

Never export real API keys in your shell profile. The missing-key error message tells you the sanctioned path.


Configuration

All configuration via environment variables (no config files required):

Variable Default Description
LLM_BASE_URL https://api.openai.com/v1 LLM API endpoint
LLM_API_KEY (required) API key for the LLM backend
LLM_MODEL gpt-4o Model name for completions
EMBED_MODEL text-embedding-3-small Embedding model
DEFAULT_AGENT_COUNT 100 Default number of agents per simulation
SIM_MAX_TICKS 50 Maximum ticks per simulation run
RUST_LOG teri=debug,tower_http=info Logging level

Local Inference with Shimmy

For local/offline inference, Teri supports shimmy (the FlexNetOS local LLM server) as an OpenAI-compatible endpoint:

export LLM_BASE_URL=http://localhost:8080/v1

# Teri will preflight the backend and refuse to run if shimmy reports stub mode.
envctl run -- teri run --seed ./examples/seed.txt --query "Test query"

Seed File or Community Platform β”‚ β–Ό [seed] ── parse & normalise ──► SeedDocument β”‚ β–Ό [graph] ── entity/relation extraction ──► KnowledgeGraph (petgraph) β”‚ β”‚ β–Ό β–Ό [agent] ── persona gen + memory init ──► AgentPool (N agents) β”‚ β–Ό [sim] ── tick loop (tokio, bounded) ──► SimulationState β”‚ β–² β”‚ └── God's-eye variable injection β–Ό [report] ── ReportAgent synthesis ──► PredictionReport + InteractiveWorld β”‚ β”œβ”€β”€β–Ί [api] ── REST / SSE ──► Client (CLI or frontend) β”‚ └──► [feedback] ── CommunityFeedback ──► Source platform (optional write-back)


See `agent-env.toml` for teri's required secrets configuration.

---

## Project Structure

teri/ β”œβ”€β”€ Cargo.toml β”œβ”€β”€ README.md β”œβ”€β”€ agent-env.toml # envctl auto-injection manifest β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ main.rs # CLI entry point (clap, arg-parse before config) β”‚ β”œβ”€β”€ lib.rs # Module declarations + preflight_check_backend β”‚ β”œβ”€β”€ config.rs # Lazy Config loading (FIX-1.2: envctl seam) β”‚ β”œβ”€β”€ error.rs # Error types (includes TeriError::ConfigMissing) β”‚ β”œβ”€β”€ agent/ # Agent pool, personas, memory structures β”‚ β”œβ”€β”€ api/ # HTTP server scaffold + SSE streaming β”‚ β”œβ”€β”€ graph/ # Knowledge graph (petgraph) structure β”‚ β”œβ”€β”€ llm.rs # LlmClient trait + 3 adapter stubs (OpenAI, Anthropic, Gemini) β”‚ β”œβ”€β”€ memory/ # Persistent memory (redb) structures β”‚ β”œβ”€β”€ report/ # Report generation scaffold β”‚ β”œβ”€β”€ seed/ # Seed file parsing structure β”‚ └── sim/ # Simulation loop scaffold


---

## LLM Provider Support
β”œβ”€β”€ ARCHITECTURE.md
└── src/
    β”œβ”€β”€ main.rs          # CLI entry point (clap; parses before config β€” help is keyless)
    β”œβ”€β”€ lib.rs           # Module declarations
    β”œβ”€β”€ preflight.rs     # Inference-backend identity + stub refusal
    β”œβ”€β”€ seed/            # Seed ingestion & normalisation
    β”‚   └── community/   # CommunityAdapter + CommunityFeedback traits + platform adapters
    β”œβ”€β”€ graph/           # Knowledge graph (petgraph + LLM extraction)
    β”œβ”€β”€ agent/           # Agent pool, personas, memory
    β”œβ”€β”€ sim/             # Simulation engine (two-phase tick loop, tokio)
    β”œβ”€β”€ report/          # Report generation & world interaction
    β”œβ”€β”€ memory/          # Persistent memory (redb)
    └── api/             # DTOs + SSE stream types (server wiring = serve phase)

Configuration

All configuration via envctl injection, environment variables, or a local .env (dev only). See .env.example.

Teri uses an adapter pattern β€” the core simulation logic never depends on a specific provider:

  • OpenAI (GPT-4, GPT-4o) - OpenAiAdapter
  • Anthropic (Claude 3.5 Sonnet, Opus, Haiku) - AnthropicAdapter
  • Google (Gemini 1.5 Pro, Flash) - GeminiAdapter
  • Local models (Ollama, LM Studio, vLLM, shimmy) - via OpenAiAdapter (OpenAI-compatible endpoint)

Security

GGUF/Stub Backend Guard (FIX-1.3)

Before any simulation runs, Teri preflight-checks the backend:

  • Health probe (/health endpoint) if available
  • Sentinel completion request as fallback
  • Detects stub/canned-text backends and refuses to proceed (prevents meaningless simulations on deterministic cached responses)
  • Anthropic (Claude) - AnthropicAdapter
  • Google (Gemini) - GeminiAdapter
  • Local models (Ollama, LM Studio, vLLM, shimmy) - OpenAiAdapter (OpenAI-compatible)
  • Custom providers - Implement the LlmClient trait

Environment Safety

API keys are never written to config files. They flow through environment variables only, with optional auto-injection via envctl's secrets engine.

Backend honesty guard

run/serve preflight the configured backend before doing anything: GET /models (identity) and a 1-token completion probe. Backends that list no models or answer with canned stub text (e.g. shimmy's SafeTensors placeholder "Full transformer inference coming soon!") are refused β€” a swarm simulated on canned text is fabrication, not prediction. Serve a real GGUF model.


Status

🚧 Pre-alpha β€” core infrastructure built. Module interfaces defined, config/CLI/adapter layers wired. Pipeline and persistence implementation pending.


Development

# Check compilation (requires LLM_API_KEY for Config::load verification)
cargo check

# Run tests
cargo test

# Build release binary
cargo build --release

🚧 Skeleton with real organs β€” 140+ tests green.

Layer State
seed ingestion (pdf/md/txt/json/url) implemented + tested
LLM adapters (retry/backoff, multi-provider) implemented + tested
persona generation (minijinja) implemented + tested
sim loop (two-phase ticks, God-events) implemented + tested
report generation (+ streaming variant) implemented + tested
memory store (redb) implemented; write-back wiring pending
graph build orchestration placeholder β€” the P1 keystone
pipeline composition (run) / HTTP server (serve) preflight + explicit bail; wiring pending

The phased plan (P1 wire-the-spine β†’ P2 parity-core β†’ P3 serve β†’ P4 scale) lives in the meta workspace: MIROFISH-PORT-PLAN.md.


Acknowledgements

MiroFish by BaiFu / 666ghj is the original reference implementation (AGPL-3.0; teri is an MIT-licensed independent rewrite β€” parity by spec, never by code copy). Simulation design draws on OASIS from the CAMEL-AI team.


License

MIT

About

Rust-native Swarm Intelligence Prediction Engine

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 97.4%
  • Jinja 2.6%