How marieai/marie-ai works
Purpose and Entry Points
Marie-AI is a Python-first, agentic document-intelligence runtime: it accepts document/workflow requests, executes OCR, classification, extraction, NER, LLM/RAG, and transformation agents, and manages them as durable DAG jobs. Primary CLI/package entry points are marie/__main__.py and marie_server/__main__.py; service configurations define gateway and executor deployments in config/service/marie-gateway-4.0.0.yml and config/service/extract/marie-extract-4.0.0.yml.
Request Gateway and Distributed Serving
The gateway is the external control/data-plane boundary, exposing HTTP/FastAPI, gRPC, WebSocket, and streaming request paths before routing to executors. It constructs topology-aware request dispatch and supports load balancing and service discovery. Core paths: marie/serve/runtimes/gateway/gateway.py, marie/serve/runtimes/gateway/http_fastapi_app.py, marie/serve/runtimes/gateway/graph/topology_graph.py. Clients use corresponding protocol abstractions under marie/clients/.
Durable DAG Scheduling and Job Control
Workflow submissions become DAGs and jobs persisted in PostgreSQL. Scheduler services admit DAGs, resolve dependencies, prioritize by SLA, lease attempts, dispatch work, reconcile terminal state, and retain operational history. The primary boundary is scheduler logic versus SQL-enforced state transitions: marie/scheduler/job_scheduler.py, marie/scheduler/services/dag_submission_service.py, marie/scheduler/services/attempt_lifecycle_service.py. Database schema and lease operations are material runtime contracts in config/psql/schema/007_dag.sql, config/psql/schema/065_job_attempt.sql, and config/psql/schema/lease/001_lease_jobs_by_id.sql.
Executors and Document Processing
Executors are independently deployable processing agents invoked by the gateway/scheduler. Document extraction combines OCR/layout-derived content with configured annotators, parsers, table processors, LLM passes, validation, and result conversion. Key implementations: marie/executor/extract/document_extractor_executor.py, marie/executor/extract/document_annotator_llm_executor.py, marie/extract/engine/engine.py. Traditional pipeline composition remains available through marie/pipe/extract_pipeline.py and marie/pipe/llm_pipeline.py.
Planning, Agents, and Knowledge Workloads
Query planners map higher-level requests into executable plans, including OCR, branching, guardrail, HITL, knowledge-base indexing, and RAG flows: marie/query_planner/planner.py, marie/query_planner/branching.py, marie/query_planner/kb_indexing_planner.py. The embedded AI framework provides agents, retrieval/index abstractions, tools, memory, and LLM integration under marie/core/agent/, marie/core/ingestion/pipeline.py, and marie/core/query_engine/. The separately packaged agent SDK adds A2A coordination, skills, guardrails, and tool runtime at packages/marie-agent/src/marie/agent/coordination/workflow.py.
State, Messaging, and External Services
PostgreSQL is the system of record for scheduler state, job history, assets, agent memory, and tracking. Etcd provides service discovery; RabbitMQ and gRPC/SSE/webhook handlers support event distribution; Valkey/Redis supports caching/LLM queueing; S3-compatible storage holds documents/artifacts; pgvector supports vector search. Integration boundaries are represented by marie/storage/database/postgres.py, marie/serve/discovery/etcd_client.py, and marie/messaging/publisher.py. LLM dispatch can target OpenAI-compatible services through packages/marie-engine/src/marie/engine/llm_queue/dispatcher.py.
Deployment and Extensibility
The system runs locally or in containers, Kubernetes/Helm, and via a Kubernetes operator. Docker composition provisions dependencies and service variants in Dockerfiles/docker-compose.yml; Helm packages server, executor, PostgreSQL, etcd, RabbitMQ, MinIO, and Valkey under deploy/helm/charts/marie/. Extensions are manifest-validated and may run through the Go plugin daemon: packages/marie-extension/src/marie/extension/loader.py, packages/marie-plugin-daemon/cmd/server/main.go, marie/executor/extensions/plugin_daemon_executor.py.
Main entry points: gateway.py Request gateway · job_scheduler.py Job scheduler · document_extractor_executor.py Document extractor · planner.py Query planner
Components 23
Entry & Serving
- CLI entry points · Starts package and server runtimes.
marie/__main__.py - Request gateway · External HTTP, gRPC, WebSocket, and streaming boundary.
marie/serve/runtimes/gateway/gateway.py - HTTP API
marie/serve/runtimes/gateway/http_fastapi_app.py - Topology dispatch · Routes requests across executor topology.
marie/serve/runtimes/gateway/graph/topology_graph.py - Protocol clients
Workflow Control
- Query planner · Builds executable OCR, RAG, guardrail, and HITL plans.
marie/query_planner/planner.py - Branching plans
marie/query_planner/branching.py - Job scheduler · Admits, prioritizes, leases, dispatches, and reconciles jobs.
marie/scheduler/job_scheduler.py - DAG submission
marie/scheduler/services/dag_submission_service.py - Attempt lifecycle · Controls leased execution attempts and terminal state.
marie/scheduler/services/attempt_lifecycle_service.py
Processing & AI
- Document extractor · Independently deployable extraction agent.
marie/executor/extract/document_extractor_executor.py - Extraction engine · Runs OCR/layout, annotators, parsers, LLM passes, validation, and conversion.
marie/extract/engine/engine.py - LLM annotator
marie/executor/extract/document_annotator_llm_executor.py - AI framework · Provides agents, retrieval, tools, memory, and query engines.
- Agent SDK · Adds A2A workflows, skills, guardrails, and tool runtime.
packages/marie-agent/src/marie/agent/coordination/workflow.py
State & Integrations
- PostgreSQL · Persists DAGs, jobs, history, assets, memory, and tracking.
marie/storage/database/postgres.py - SQL state contracts · Database-enforced DAG, attempt, and lease transitions.
config/psql/schema/lease/001_lease_jobs_by_id.sql - Etcd discovery
marie/serve/discovery/etcd_client.py - Event publisher · Distributes events through RabbitMQ and external handlers.
marie/messaging/publisher.py - LLM dispatcher · Dispatches work to OpenAI-compatible services.
packages/marie-engine/src/marie/engine/llm_queue/dispatcher.py
Extensions & Deployment
- Extension loader · Loads manifest-validated extensions.
packages/marie-extension/src/marie/extension/loader.py - Plugin daemon executor · Runs extensions through the Go plugin daemon.
marie/executor/extensions/plugin_daemon_executor.py - Container & Helm deployment · Provisions service variants and infrastructure dependencies.
Connections 23
- CLI entry points → Request gateway: starts
- Protocol clients → Request gateway: invoke
- HTTP API → Request gateway: HTTP ingress
- Request gateway → Topology dispatch: selects route
- Request gateway → Etcd discovery: discovers services
- Request gateway → Query planner: submits request
- Query planner → Branching plans: composes branches
- Query planner → DAG submission: creates DAG
- DAG submission → Job scheduler: admits
- Job scheduler → Attempt lifecycle: manages attempts
- Job scheduler → PostgreSQL: persists state
- Job scheduler → SQL state contracts: uses leases
- Job scheduler → Document extractor: dispatches work
- Document extractor → Extraction engine: executes
- Extraction engine → LLM annotator: uses LLM annotation
- Extraction engine → AI framework: uses agents and RAG
- LLM annotator → LLM dispatcher: queues LLM work
- Job scheduler → Event publisher: publishes lifecycle events
- Agent SDK → AI framework: extends runtime
- Extension loader → Plugin daemon executor: loads into
- Plugin daemon executor → Document extractor: extends processing
- Container & Helm deployment → Request gateway: deploys
- Container & Helm deployment → Document extractor: deploys