Skip to main content

loom-ai

loom-ai

Pluggable AI orchestration framework with swappable backends. Zero required dependencies.

Install

pip install flossware-loom-ai              # core (stdlib only)
pip install flossware-loom-ai[server]      # + FastAPI REST server
pip install flossware-loom-ai[postgresql]  # + PostgreSQL/pgvector storage
pip install flossware-loom-ai[redis]       # + Redis queues
pip install flossware-loom-ai[all]         # everything

Quick Start

As a Python library

from loom_ai import LoomConfig, Document, ChatMessage

# Zero-config: all in-memory / no-op backends
cfg = LoomConfig.from_env()

# Store a document
doc_id = await cfg.storage.store_document(Document(
    id="doc-1", title="Example", content="Hello world"
))

# Multi-model consensus (requires LOOM_LLM_BASE_URL)
responses = await cfg.llm.consensus(
    [ChatMessage(role="user", content="Explain distributed systems")],
    models=["gemini-3.5-flash", "llama-3.3-70b", "mistral-small"],
)

As a REST server

# Minimal — just LLM routing
export LOOM_LLM_BASE_URL=http://localhost:4000/v1
python -m loom_ai

# Full stack
export LOOM_STORAGE=postgresql
export LOOM_QUEUE=redis
export LOOM_GRAPH=memory
export LOOM_LLM_BASE_URL=http://localhost:4000/v1
python -m loom_ai

Routes mount dynamically based on configuration:

Backend Routes When
Storage /knowledge/* Always
Queue /pipeline/* Always
Search /search/* Always
Secrets /secrets/* Always
LLM /llm/* LOOM_LLM_BASE_URL set
Graph /graph/* LOOM_GRAPH != disabled
Health /health Always

Configuration

All via environment variables (defaults in parentheses):

Variable Options Default
LOOM_STORAGE memory, postgresql memory
LOOM_QUEUE memory, redis memory
LOOM_SECRETS env, dotenv, postgresql env
LOOM_EMBEDDING noop, openai, litellm noop
LOOM_SEARCH memory, postgresql memory
LOOM_GRAPH disabled, memory, orientdb disabled
LOOM_LLM_BASE_URL Any OpenAI-compatible URL (none)
LOOM_LLM_API_KEY Bearer token (none)
LOOM_LLM_MODEL Default model id gpt-4o-mini
LOOM_HOST Server bind address 0.0.0.0
LOOM_PORT Server port 5000

Don't set it? Don't get it. Set nothing at all and you get a pure in-memory orchestrator.

Architecture

loom_ai/
  protocols.py          7 Protocol interfaces (async, stdlib-only)
  models.py             9 dataclasses (Document, Chunk, ChatMessage, etc.)
  config.py             LoomConfig registry with from_env() factory
  prompts.py            Built-in consensus prompt templates
  server.py             Optional FastAPI REST server
  backends/
    memory.py           In-memory implementations (zero deps)
    env_secrets.py      Environment variable secrets
    http_llm.py         HTTP LLM backend (urllib, zero deps)

7 Pluggable Protocols

Protocol Purpose Default Enterprise
StorageBackend Documents, chunks, embeddings In-memory dicts PostgreSQL + pgvector
QueueBackend Named task queues In-memory deque Redis
SecretsBackend API keys and config os.environ PostgreSQL encrypted
EmbeddingBackend Text to vectors Zero vectors OpenAI / Jina / Voyage
SearchBackend Full-text + semantic Substring + cosine tsvector + pgvector ANN
GraphBackend Knowledge graph Disabled OrientDB
LLMBackend Chat + consensus HTTP (any OpenAI-compatible) Same

Multi-Model Consensus

Fan out to N models, synthesize with an arbiter:

from loom_ai.prompts import build_worker_messages, build_arbiter_messages

# Workers respond independently
worker_msgs = build_worker_messages("review", "Check this code for bugs")
responses = await cfg.llm.consensus(
    [ChatMessage(role=m["role"], content=m["content"]) for m in worker_msgs],
    models=["gemini-3.5-flash", "llama-3.3-70b", "codestral"],
    timeout_seconds=60,
    retries=2,
)

# Arbiter synthesizes
arbiter_msgs = build_arbiter_messages(
    "Check this code for bugs",
    [{"model": r.model, "response": r.content} for r in responses],
)
synthesis = await cfg.llm.chat(
    [ChatMessage(role=m["role"], content=m["content"]) for m in arbiter_msgs],
    model="gemini-3.5-flash",
    temperature=0.3,
)

Free AI Providers

See docs/free-ai-providers.md for 20+ free model providers with signup links, compatible with the HttpLLMBackend via LiteLLM proxy.

License

Apache 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flossware_loom_ai-1.1.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flossware_loom_ai-1.1-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file flossware_loom_ai-1.1.tar.gz.

File metadata

  • Download URL: flossware_loom_ai-1.1.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for flossware_loom_ai-1.1.tar.gz
Algorithm Hash digest
SHA256 af1b12b9331cef77ae0e8194f0ed16bd7fcc3e22dad4fdb2551d97b60f498c97
MD5 2a90eee428949b8df3581be43d82f7d1
BLAKE2b-256 6ee91d9f2a3d2f9b3cddbbc1028b31f3998e0163a75b304c800962a56bf58783

See more details on using hashes here.

File details

Details for the file flossware_loom_ai-1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flossware_loom_ai-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a98432d65199e3ef2318efe11e56e76d616704256ab17592d5c850111333773
MD5 54bdc372bfa1b3f3590d1080dfc39949
BLAKE2b-256 b5d2c99f42c05005869d2e32ca653a79083d27baddd24a80ce83e0fda13c3ad4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page