LocalAGI Documentation

repository·main·Indexed 23 days ago

https://github.com/mudler/localagi

A self-hostable AI Agent platform for creating and managing customizable AI assistants, automations, and chatbots that run locally on consumer-grade CPU/GPU hardware. It features a Web UI, support for Model Context Protocol (MCP) servers, built-in RAG via LocalRecall, and extensible agent behaviors through Go-scripted custom actions and reusable skills.

Tokens
14.1K
Snippets
23
Records
72
Agent score
84%

What's inside LocalAGI

  1. Understand the React + Vite setup in react-ui

    main

    The react-ui package uses a Vite-based template for React development, providing Hot Module Replacement (HMR). It supports two official plugin options for Fast Refresh:

    • @vitejs/plugin-react: Uses Babel for Fast Refresh.
    • @vitejs/plugin-react-swc: Uses SWC (Speedy Web Compiler) for Fast Refresh.
  2. Manage multiple agents with AgentPool

    main

    For managing multiple agents simultaneously, use the state.NewAgentPool system. An AgentPool allows you to define default models, API credentials, and global configurations for actions, connectors, dynamic prompts, and job filters.

    Once a pool is initialized, you can create specific agents within it using an AgentConfig and control the entire group using StartAll(), Stop(), or Remove().

    Key capabilities of the AgentPool include:

    • Bulk Management: Start, stop, or remove agents by name.
    • Global Configuration: Define shared actions, connectors, and prompts.
    • Status Tracking: Retrieve status history for specific agents.
    • Custom Logic: Implement custom job filtering and dynamic prompt templates.
    import (
        "github.com/mudler/LocalAGI/core/state"
        "github.com/mudler/LocalAGI/core/types"
    )
    
    // Create a new agent pool
    pool, err := state.NewAgentPool(
        "default-model",           // default model name
        "default-multimodal-model", // default multimodal model
        "transcription-model",     // default transcription model
        "en",                     // default transcription language
        "tts-model",              // default TTS model
        "http://localhost:8080",  // API URL
        "your-api-key",           // API key
        "./state",                // state directory
        func(config *AgentConfig) func(ctx context.Context, pool *AgentPool) []types.Action {
            // Define available actions for agents
            return func(ctx context.Context, pool *AgentPool) []types.Action {
                return []types.Action{
                    // Add your custom actions here
                }
            }
        },
        func(config *AgentConfig) []Connector {
            // Define connectors for agents
            return []Connector{
                // Add your custom connectors here
            }
        },
        func(config *AgentConfig) []DynamicPrompt {
            // Define dynamic prompts for agents
            return []DynamicPrompt{
                // Add your custom prompts for agents
            }
        },
        func(config *AgentConfig) types.JobFilters {
            // Define job filters for agents
            return types.JobFilters{
                // Add your custom filters here
            }
        },
        "10m",  // timeout
        true,   // enable conversation logs
        nil,    // skills service (optional),
    )
    
    // Create a new agent in the pool
    agentConfig := &AgentConfig{
        Name: "my-agent",
        Model: "gpt-4",
        SystemPrompt: "You are a helpful assistant.",
        EnableKnowledgeBase: true,
        EnableReasoning: true,
        // Add more configuration options as needed
    }
    
    err = pool.CreateAgent("my-agent", agentConfig)
    
    // Start all agents
    err = pool.StartAll()
    
    // Get agent status
    status := pool.GetStatusHistory("my-agent")
    
    // Stop an agent
    pool.Stop("my-agent")
    
    // Remove an agent
    err = pool.Remove("my-agent")
  3. Core concepts of LocalAGI

    main

    LocalAGI is a self-hostable AI Agent platform designed for privacy and local execution. Key abstractions include:

    • Agents: No-code, easy-to-configure entities that can be managed via the Web UI. Every agent provides a drop-in replacement for OpenAI's Responses APIs.
    • Skills: Reusable agent tools following the skillserver format. Skills can be managed in the Web UI (create, edit, import/export, git sync) and enabled per agent.
    • Knowledge Base (RAG): Built-in short and long-term memory using LocalRecall. Managed via the Knowledge base section in the Web UI for collections and semantic search.
    • Connectors: Built-in integrations for Discord, Slack, Telegram, GitHub Issues, and IRC.
    • Custom Actions: Extensible behaviors scripted in Go that are interpreted without compilation.
  4. Manage and use Agent Skills

    main

    Skills are reusable instructions and resources (like scripts or assets) that agents can leverage.

    Enabling Skills

    To allow an agent to use skills, you must enable them in the agent's Advanced Settings by toggling Enable Skills. Once enabled, the agent can use built-in skill tools (list, read, search, resources) via a specialized skills MCP.

    Managing Skills via Web UI

    • Open Skills in the sidebar.
    • Skills are stored in the STATE_DIR/skills directory.
    • You can create, edit, search, import, and export skills.
    • You can sync skills by adding Git repositories.

    Storage and Persistence

    In Docker environments, skills are persisted in the /pool directory. To use a host folder for skills, mount it to /pool/skills in your Docker configuration.

    Docker Mount Example:

    volumes:
      - ./my-skills:/pool/skills

    Compatibility

    Skills use the same format as skillserver (e.g., containing a SKILL.md file). Skills exported from LocalAGI are compatible with the standalone skillserver.

  5. Quickstart LocalAGI with Docker Compose

    main

    To get started with LocalAGI, clone the repository and use Docker Compose to launch the environment based on your hardware. Once running, the Web UI is accessible at http://localhost:8080.

    # Clone the repository
    git clone https://github.com/mudler/LocalAGI
    cd LocalAGI
    
    # CPU setup (default)
    docker compose up
    
    # NVIDIA GPU setup
    docker compose -f docker-compose.nvidia.yaml up
    
    # Intel GPU setup (for Intel Arc and integrated GPUs)
    docker compose -f docker-compose.intel.yaml up
    
    # AMD GPU setup
    docker compose -f docker-compose.amd.yaml up
  6. Configure MCP (Model Context Protocol) Servers

    main

    LocalAGI supports the Model Context Protocol (MCP) to connect agents to external tools and data sources. You can use both local and remote servers.

    Local MCP Servers

    Local servers run as processes spawned by LocalAGI via STDIO. A common pattern is running MCP servers inside Docker containers.

    Example Configuration (GitHub MCP Server):

    {
      "mcpServers": {
        "github": {
          "command": "docker",
          "args": [
            "run",
            "-i",
            "--rm",
            "-e",
            "GITHUB_PERSONAL_ACCESS_TOKEN",
            "ghcr.io/github/github-mcp-server"
          ],
          "env": {
            "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
          }
        }
      }
    }

    Remote MCP Servers

    Remote servers are accessed via HTTP URLs. You can add these URLs directly in the LocalAGI Web UI or via the API configuration.

    Configuration Methods

    • Web UI: Use the MCP Settings section during agent creation.
    • API: Include the mcpServers configuration object in your agent's JSON configuration.
  7. Set up LocalAGI for Development

    main

    To develop LocalAGI, you need to run the Go backend and the React/Vite frontend. The frontend requires a build directory to exist before the backend can start.

    1. Frontend Setup (React + Vite)

    Navigate to the webui/react-ui directory to install dependencies and build the assets.

    cd webui/react-ui
    
    # Install dependencies using bun
    bun i
    
    # Compile frontend
    bun run build
    
    # Start frontend development server
    bun run dev

    2. Backend Setup (Go)

    In a separate terminal, set the required environment variables and run the Go server.

    cd LocalAGI
    
    # Create state directory
    mkdir pool
    
    # Set required environment variables
    export LOCALAGI_MODEL=gemma-3-4b-it-qat
    export LOCALAGI_MULTIMODAL_MODEL=moondream2-20250414
    export LOCALAGI_IMAGE_MODEL=sd-1.5-ggml
    export LOCALAGI_LLM_API_URL=http://localai:8080
    export LOCALAGI_STATE_DIR=./pool
    export LOCALAGI_TIMEOUT=5m
    export LOCALAGI_ENABLE_CONVERSATIONS_LOGGING=false
    export LOCALAGI_SSHBOX_URL=root:root@sshbox:22
    
    # Start development server
    go run main.go

    Note: Check webui/react-ui/.vite.config.js for additional environment variables used to configure the backend URL connection.

  8. Create Custom Actions using Go code

    main

    LocalAGI allows you to extend agent functionality by defining custom actions in Go. These actions can be defined inline within the Web UI when creating an agent or loaded automatically from a directory.

    Automatic Loading via Environment Variable

    You can configure LocalAGI to automatically load all .go files from a specific directory by setting the LOCALAGI_CUSTOM_ACTIONS_DIR environment variable.

    Environment Variable:

    • LOCALAGI_CUSTOM_ACTIONS_DIR: Path to a directory containing .go files.

    Example Setup (Docker Compose):

    environment:
      - LOCALAGI_CUSTOM_ACTIONS_DIR=/app/custom-actions

    Custom Action Requirements

    Every custom action must implement three specific functions:

    1. Run(config map[string]interface{}) (string, map[string]interface{}, error): The core logic. It receives configuration parameters and returns a result string, a map of additional data, and an error.
    2. Definition() map[string][]string: Defines the parameters the action accepts. The map key is the parameter name, and the value is a slice containing the type (e.g., "string") and a description.
    3. RequiredFields() []string: A list of parameter names that must be provided for the action to execute.

    Note: You may only use standard Go libraries; additional external modules are not supported.

  9. Build LocalAGI from Source

    main

    To build LocalAGI from source, you need Go 1.20+, Git, and Bun 1.2+. Follow these steps to clone, build the web UI, and compile the binary:

    # Clone repo
    git clone https://github.com/mudler/LocalAGI.git
    cd LocalAGI
    
    # Build the web UI
    cd webui/react-ui && bun i && bun run build
    cd ../..
    
    # Build the Go binary
    go build -o localagi
    
    # Run it
    ./localagi
    # Clone repo
    git clone https://github.com/mudler/LocalAGI.git
    cd LocalAGI
    
    # Build it
    cd webui/react-ui && bun i && bun run build
    cd ../..
    go build -o localagi
    
    # Run it
    ./localagi
  10. Configure ESLint and TypeScript for production development

    main
    For production-grade applications, it is recommended to use TypeScript and enable type-aware lint rules. You can integrate TypeScript and typescript-eslint by following the standard Vite TypeScript template patterns.
  11. Hardware configuration profiles

    main

    LocalAGI provides specific Docker Compose files for different hardware acceleration needs:

    • CPU (Default): Uses docker compose up. Best for testing; supports text models only.
    • NVIDIA GPU: Uses docker compose -f docker-compose.nvidia.yaml up. Requires NVIDIA drivers and uses CUDA. Supports text, multimodal, and image models.
    • Intel GPU: Uses docker compose -f docker-compose.intel.yaml up. Supports Intel Arc and integrated GPUs using SYCL. Supports text, multimodal, and image models.
    • AMD GPU: Uses docker compose -f docker-compose.amd.yaml up.
  12. Configure LocalAGI models via environment variables

    main

    You can customize the models used by LocalAGI by setting specific environment variables when running docker compose. If no models are specified, the system uses the following defaults:

    • Text model: gemma-3-4b-it-qat
    • Multimodal model: moondream2-20250414
    • Image model: sd-1.5-ggml

    Available environment variables:

    • MODEL_NAME: The text model to use.
    • MULTIMODAL_MODEL: The multimodal model to use.
    • IMAGE_MODEL: The image generation model to use.
    • LOCALAI_SINGLE_ACTIVE_BACKEND: Set to true to enable single active backend mode.
    # CPU with custom model
    MODEL_NAME=gemma-3-12b-it docker compose up
    
    # NVIDIA GPU with custom models
    MODEL_NAME=gemma-3-12b-it \
    MULTIMODAL_MODEL=moondream2-20250414 \
    IMAGE_MODEL=flux.1-dev-ggml \
    docker compose -f docker-compose.nvidia.yaml up
    
    # Intel GPU with custom models
    MODEL_NAME=gemma-3-12b-it \
    MULTIMODAL_MODEL=sd-1.5-ggml \
    docker compose -f docker-compose.intel.yaml up