Skip to content

Architecture

Alquimia Platform has two layers:

flowchart TB
  clients["External clients<br/>HTTP · SSE · Slack · WhatsApp · Email"]

  subgraph runtime["alquimia-runtime"]
    master["Master<br/>Auth · Registry · Event ingestion · SSE streaming"]
    worker["Worker<br/>Event consumer"]
  end

  subgraph core["alquimia-core · runs inside the worker"]
    engine["Controller · Stages · Worklog · Execution loop<br/>Tools · Memory · Evaluation · Shields · Knowledge"]
  end

  kafka[("Kafka<br/>signed CloudEvents")]

  subgraph infra["State, storage and secrets"]
    redis[("Redis<br/>state · locks")]
    pg[("PostgreSQL<br/>persistence")]
    s3[("S3<br/>blobs · registry")]
    qdrant[("Qdrant<br/>vectors")]
    vault["Vault<br/>secrets"]
  end

  ext["LLM providers · MCP servers · A2A agents"]

  clients --> master
  master -->|"publish"| kafka -->|"consume"| worker
  worker --> engine
  engine --> ext
  master --> infra
  worker --> infra

alquimia-runtime handles HTTP, authentication, session state, and event routing. It delegates all agent reasoning to alquimia-core, which executes the agent step by step and emits a complete audit trail.

The runtime exposes a single HTTP API and runs in one of two roles from the same container image:

RoleResponsibilityHTTP exposure
MasterReceives external requests, manages registry and context, publishes eventsFull API
WorkerConsumes events, executes inference, emits results back to the busHealth probes only

In production, you run a single master replica and one or more worker replicas. The master publishes events to an event bus; workers consume them and run the core engine. Workers are stateless, so you can scale them to match throughput.

A single-process all mode is available for local development or small deployments where separate master and worker containers are impractical.

Every inference request flows through a three-stage pipeline inside the core engine:

flowchart TB
  req(["Incoming request"])
  pre["Preprocess<br/>Shields · attachment normalization · safety checks"]
  proc["Process<br/>Tool discovery · LLM calls · tool execution loop"]
  ans["Answer<br/>Memory flush · context persistence · final response"]
  done(["Final response"])

  req --> pre --> proc --> ans --> done
  proc -->|"tool call requested"| proc
  pre -.->|"blocked by a shield"| done

Each stage emits commands for work it needs done and processes responses as they arrive. The pipeline continues until a final response is produced or an unrecoverable error occurs.

Inference is non-blocking. The master does not execute agents directly; it hands work to workers through the event bus.

  1. A client posts a request to the master.
  2. The master validates authentication and the agent registry entry, then publishes an inference event to the event bus.
  3. The master immediately returns a task identifier to the client.
  4. A worker consumes the event and runs the agent through the core engine.
  5. The worker writes progress records to a state store.
  6. The client opens a streaming endpoint using the task identifier and receives progress events until the final response arrives.
sequenceDiagram
  autonumber
  participant C as Client
  participant M as Master
  participant K as Event bus (Kafka)
  participant W as Worker
  participant S as State store (Redis)
  C->>M: POST inference request
  M->>K: publish signed inference event
  M-->>C: task_id
  K->>W: consume (consumer group alquimia-workers)
  W->>W: execute agent with alquimia-core
  W->>S: write progress records
  C->>M: GET stream for task_id
  M->>S: read progress
  M-->>C: SSE events until the final response

This design decouples request acceptance from execution. Long-running agents with many tool calls do not block HTTP connections, and workers can be scaled independently.

All master-to-worker communication uses a signed event bus. Events carry a standard envelope and an integrity signature. Workers reject any event with a missing or invalid signature, preventing unauthorized execution requests.

The event bus also carries intermediate results such as tool outputs, shield verdicts, and memory flushes back into the execution pipeline.

StorePurposeTypical backend
State storeTask progress, session context, distributed locksRedis
Persistent storeAudit worklog, webhook subscriptionsPostgreSQL
Blob storeUploaded files, audio, large attachmentsS3-compatible object store
Vector storeRAG chunks and embeddingsQdrant, Redis, or in-memory

Agents retrieve context from multiple knowledge source types through a single abstraction:

Search modeBehavior
ragRetrieve semantically similar chunks for every inference
on_demandExpose a search tool the agent invokes explicitly
directExpose file-listing and reading tools over topic files
brainQuery a registered Boltzmann brain with per-module authorization

Shields are pre-inference classifiers that run in the preprocess stage. They can observe, flag, or block requests before the LLM is invoked. The built-in prompt-injection detector is fail-closed, so a classification failure defaults to blocking.

Client-managed tools (provider_id: "client") let callers register curated, user-supplied schemas that are executed through a dedicated ClientToolExecution path. Request-supplied schemas are stripped when a matching registered client tool exists, preventing schema collisions while still allowing governance through the tool registry.

Knowledge access is governed at two levels. Every topic has an access_policy enforced by KnowledgeAuthzPolicy. Starting with 0.7.0, a layered FileAccessPolicy applies fine-grained controls to individual files, and search, list_files, and read_file results are filtered accordingly. read_file also converts PDF, Word, PowerPoint, Excel, and EPUB documents to text using the same loaders as ingestion.

Knowledge approval is handled by the controller. RAG retrievals and built-in knowledge tool calls that require approval are parked as HumanApprovalRequired events and resumed once a human answer is received, so the approval gate does not block the execution loop.

Event bus for coordination. Decoupling masters and workers through an event bus makes the system horizontally scalable and resilient to slow or failing workers.

Signed events. Every event is signed before publishing and verified before dispatch. This prevents a compromised worker or misconfigured client from injecting unauthorized execution commands.

Registry-driven configuration. Agent configurations are stored in a registry and can be distributed as OCI artifacts. This enables version-controlled, portable agent packages that can be validated and promoted independently of the runtime. Versioned (“cold”) registries can load a specific OCI tag into an isolated snapshot without overwriting the workspace dist.json, making inference reproducible and promotion safer.

Observability by default. Every inference run carries shared dimensions such as agent, agentspace, session, user, and task identifiers. These dimensions propagate through metrics, traces, and logs for cross-signal correlation. OpenTelemetry metrics are gated by a feature flag and setup_observability() short-circuits when no readers or endpoint are configured.

Safe registry cloning. When a dist.json is pulled or loaded into a different agentspace, foreign agentspace_id values are rebound to the local namespace. Cloned agentspaces therefore query their own vector collections and file registrations instead of the source agentspace’s.