Skip to content

rshade/ElixirChain

Repository files navigation

πŸ§ͺ ElixirChain: Concurrent AI Agents for the BEAM VM

What if AI agents could truly run in parallel, recover from failures automatically, and scale across machines seamlessly?

ElixirChain brings the battle-tested principles of actor-model concurrency, fault tolerance, and distributed computing to AI agent development. Built on Elixir and the BEAM VMβ€”the same foundation that powers systems handling millions of concurrent connectionsβ€”ElixirChain treats each AI agent as a supervised, isolated process. Designed around Google Gemini's massive 2M token context window, ElixirChain simplifies agent architecture while enabling sophisticated multimodal interactions.

πŸš€ Why Elixir for AI Agents?

The Actor Model Advantage

Traditional AI frameworks face fundamental concurrency and reliability challenges:

  • Threading Complexity: Managing hundreds of concurrent agents requires careful thread management
  • Failure Propagation: One agent failure can impact others sharing the same process space
  • Scaling Challenges: Distributing agents across machines requires significant infrastructure
  • State Management: Coordinating shared state between agents becomes increasingly complex

The BEAM VM Solution

# Each agent is an isolated, supervised process
{:ok, agents} = Enum.map(1..100, fn i ->
  ElixirChain.start_agent(%{
    name: "agent_#{i}",
    system_prompt: "You are assistant #{i}",
    tools: [:web_search, :calculator]
  })
end)

# Agents run in parallel, restart on failure, scale across nodes

🎯 Key Benefits:

  • πŸ”₯ Actor Model Concurrency: Each agent is a lightweight process with isolated state
  • πŸ›‘οΈ Supervised Fault Tolerance: Agents restart automatically without affecting others
  • ⚑ BEAM VM Efficiency: Proven virtual machine optimized for massive concurrency
  • 🌐 Distribution Ready: Built-in clustering and remote process communication
  • πŸ”§ Hot Code Reloading: Update agent behavior without stopping the system
  • πŸ’Ύ Process Isolation: Agents cannot interfere with each other's memory

πŸ—οΈ Architecture That Makes Sense

Process-Per-Agent Model

Application Supervisor
β”œβ”€β”€ Agent Registry (1000+ agents)
β”‚   β”œβ”€β”€ Agent 1 (GenServer) ──► Conversation State
β”‚   β”œβ”€β”€ Agent 2 (GenServer) ──► Tool Execution  
β”‚   └── Agent N (GenServer) ──► Memory Management
β”œβ”€β”€ LLM Provider Pool
β”œβ”€β”€ Tool Registry
└── Memory Supervisors

Every agent is:

  • Isolated: Crashes don't propagate
  • Supervised: Automatic restart with state recovery
  • Concurrent: True parallelism across all CPU cores
  • Scalable: Add nodes, not complexity

🎯 Core Features

πŸ€– Intelligent Agent Management

  • Process-Based Agents: Each agent is a supervised GenServer process
  • Automatic Recovery: Supervision trees handle crashes gracefully
  • Hot Code Swapping: Update agent behavior without restarts
  • Resource Isolation: Memory and compute boundaries per agent
  • Large Context Windows: Leverage Gemini's 2M token capacity for complex reasoning

🧠 Advanced Memory System

  • Multiple Types: Conversation, semantic, episodic, working memory
  • Pluggable Backends: ETS, Mnesia, PostgreSQL, Redis, vector databases
  • Large Context Leverage: Use Gemini's 2M tokens to reduce memory complexity
  • Distributed Storage: Memory that spans across nodes
  • Multimodal Memory: Store and retrieve text, images, and documents

πŸ”§ Powerful Tool System

defmodule MyCustomTool do
  use ElixirChain.Tool

  def execute(%{"query" => query}, _context) do
    # Tool logic here
    {:ok, result}
  end
end

# Tools run in parallel with automatic timeout/retry
ElixirChain.add_tool(agent, MyCustomTool)

⚑ Chain Execution Engine

research_chain = ElixirChain.Chain.new()
|> add_step({:llm, :gemini, "Generate search queries for: {{topic}}"})
|> add_step({:parallel, [
    {:tool, :web_search, %{query: "{{query1}}"}},
    {:tool, :web_search, %{query: "{{query2}}"}}
  ]})
|> add_step({:llm, :gemini, "Synthesize comprehensive report: {{results}}"})

{:ok, result} = ElixirChain.Chain.run(research_chain, %{topic: "AI trends"})

🌍 Distributed Computing

  • Multi-Node Clustering: Agents communicate across machines seamlessly
  • Load Balancing: Automatic distribution of agent workloads
  • State Synchronization: Consistent memory across the cluster
  • Network Partition Tolerance: Graceful handling of node failures

πŸš€ Quick Start

Installation

def deps do
  [
    {:elixir_chain, "~> 0.1.0"}
  ]
end

Your First Agent

# Start an intelligent research assistant
{:ok, agent} = ElixirChain.start_agent(%{
  name: "research_assistant",
  system_prompt: "You are a brilliant research assistant with access to web search and calculations.",
  tools: [:web_search, :calculator, :file_reader],
  llm_provider: :gemini,  # 2M token context window
  memory_type: :semantic
})

# Chat naturally
{:ok, response} = ElixirChain.chat(agent, 
  "Research the latest developments in quantum computing and calculate the market growth rate")

# Stream responses for long-form content
stream = ElixirChain.chat_stream(agent, "Write a comprehensive report on AI trends")
for chunk <- stream do
  IO.write(chunk)
end

Multi-Agent Coordination

# Create specialized agents
{:ok, researcher} = ElixirChain.start_agent(%{name: "researcher", tools: [:web_search]})
{:ok, writer} = ElixirChain.start_agent(%{name: "writer", tools: [:text_processor]})
{:ok, reviewer} = ElixirChain.start_agent(%{name: "reviewer", tools: []})

# Coordinate complex workflows
workflow_result = ElixirChain.Coordination.delegate([
  {researcher, "Research quantum computing trends"},
  {writer, "Create a technical summary from: {{research}}"},
  {reviewer, "Review and improve: {{summary}}"}
])

πŸ› οΈ Development Setup

Prerequisites

  • Erlang/OTP 26+ - The foundation of reliability
  • Elixir 1.15+ - Modern language features
  • PostgreSQL 13+ - Vector storage with pgvector
  • Redis 6+ - High-performance caching

Lightning-Fast Setup

# One command to rule them all
make ensure        # Installs Elixir, Erlang, PostgreSQL, Redis via mise
make setup         # Complete project setup (dependencies + database)
make test          # Verify everything works
make console       # Start interactive development environment

Development Commands

# Development workflow
make console       # Interactive shell (iex -S mix)
make test          # Run comprehensive test suite
make test-watch    # Continuous testing during development
make lint          # Code quality with Credo
make format        # Consistent code formatting
make dialyzer      # Static type analysis
make check-all     # Run all quality checks

# Database operations  
make db-setup      # Initialize database with schema
make db-reset      # Fresh database reset
make db-migrate    # Apply schema migrations
make db-console    # Direct PostgreSQL access

# Service management
mise run services-start   # Start PostgreSQL and Redis
mise run services-stop    # Stop background services
mise run services-status  # Check service health

πŸ—οΈ Built on Proven Technology

BEAM VM Track Record

The BEAM virtual machine powers some of the world's most reliable systems:

  • WhatsApp: 2+ billion users with 99.999% uptime
  • Discord: Millions of concurrent voice/text channels
  • Pinterest: Handling billions of requests per day
  • Bet365: Real-time sports betting with zero downtime
  • Klarna: Financial transactions requiring absolute reliability

Design Goals

ElixirChain aims to achieve:

  • High Concurrency: Support thousands of simultaneous agents
  • Fault Isolation: Individual agent failures don't cascade
  • Rapid Recovery: Automatic restart with state preservation
  • Horizontal Scaling: Add nodes to increase capacity
  • Hot Updates: Deploy changes without downtime

🏒 Production Ready

Enterprise Features

  • πŸ”’ Security: Input validation, permission systems, secure tool execution
  • πŸ“Š Observability: Telemetry integration, distributed tracing, health checks
  • πŸš€ Deployment: Docker containers, Kubernetes StatefulSets, zero-downtime updates
  • πŸ”„ Scaling: Horizontal scaling across multiple nodes
  • πŸ’ͺ Reliability: Supervision trees, circuit breakers, graceful degradation

Monitoring & Operations

# Built-in observability
:observer.start()                    # Visual process monitoring
ElixirChain.Metrics.agent_count()    # Current active agents
ElixirChain.Health.cluster_status()  # Distributed health check

πŸ—‚οΈ Project Status

⚠️ Current Phase: Design & Architecture

This project is currently in the design and architecture phase. The comprehensive technical design document (elixir_chain_design_doc.md) contains the complete blueprint, but no Elixir implementation exists yet.

🎯 Implementation Timeline

Phase 1: Core Framework (4-6 weeks)

  • βœ… Technical design complete
  • πŸ”² Basic agent GenServer implementation
  • πŸ”² LLM provider abstractions (OpenAI, Anthropic)
  • πŸ”² Simple memory management (ETS-based)
  • πŸ”² Tool system with basic tools
  • πŸ”² Chain execution engine

Phase 2: Production Features (4-6 weeks)

  • πŸ”² Persistent memory backends
  • πŸ”² Vector similarity search
  • πŸ”² Streaming responses with GenStage
  • πŸ”² Middleware system (logging, metrics, caching)
  • πŸ”² Rate limiting and circuit breakers

Phase 3: Advanced Features (6-8 weeks)

  • πŸ”² Distributed multi-node support
  • πŸ”² Advanced memory compression
  • πŸ”² Web UI for agent management
  • πŸ”² Plugin system for extensions
  • πŸ”² Performance optimization

Phase 4: Ecosystem (4-6 weeks)

  • πŸ”² Integration with vector databases
  • πŸ”² Pre-built agent templates
  • πŸ”² Deployment tooling (Docker, Kubernetes)
  • πŸ”² Monitoring and observability
  • πŸ”² Security hardening

πŸ“š Documentation & Resources

🀝 Contributing

ElixirChain is designed to become the definitive AI agent framework for production systems. We welcome contributions that align with our core philosophy:

  1. Concurrency First: Leverage BEAM's process model
  2. Fault Tolerance: Let it crash, but recover gracefully
  3. Distribution Ready: Design for multiple nodes from day one
  4. Developer Experience: Make complex things simple

Getting Started

  1. Read the technical design document
  2. Check out the development setup
  3. Run make setup to get your environment ready
  4. Look for issues tagged good-first-issue

πŸ“„ License

ElixirChain is released under the MIT License - see the LICENSE file for details.

🌟 The Vision

ElixirChain represents a different approach to AI agent architectureβ€”one that prioritizes reliability, concurrency, and operational simplicity. By leveraging decades of research in actor systems and fault-tolerant computing, we aim to make AI agents as robust and scalable as the telecommunication systems that inspired the BEAM VM.

AI agents deserve the same reliability guarantees as mission-critical systems.


⭐ Star this repo if you're interested in exploring actor-model approaches to AI agents!
πŸš€ Watch for updates as we develop this experimental framework!
🀝 Contribute to help explore new paradigms in agent architecture!

About

A LangChain-inspired AI agent framework built for the BEAM VM, featuring process-isolated agents, automatic fault recovery, and native support for Google Gemini's 2M token context. Build resilient multi-agent systems with true parallelism, hot code reloading, and distributed coordination.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors