Skip to content
GitHub

Guide

PackageRequiredPurpose
lexigramYesCore framework
lexigram-contractsYesProtocol definitions
lexigram-ai-llmYesLLM client integration
lexigram-ai-ragYesRAG pipeline integration
lexigram-ai-feedbackYesFeedback collection
lexigram-ai-observabilityYesObservability
lexigram-ai-agentsOptionalAgent system (runtime discovery)
lexigram-ai-skillsOptionalSkills system (runtime discovery)
lexigram-ai-memoryOptionalMemory system (runtime discovery)
lexigram-ai-sessionOptionalSession management (runtime discovery)
lexigram-ai-mcpOptionalMCP protocol (runtime discovery)
lexigram-ai-workersOptionalBackground workers (runtime discovery)

lexigram-ai is the orchestration layer for the AI subsystem. Instead of wiring LLM clients, vector stores, RAG pipelines, and observability providers individually, you configure a single AIConfig and AIModule wires everything through the DI container.

It discovers sub-packages via Python entry points (lexigram.ai.subsystems), so installing a supported extension (e.g., lexigram-ai-llm) is enough — no manual registration.

AIConfig ──► AIModule.configure()
AIProvider (register)
├── LLMProvider (lexigram-ai-llm)
├── VectorProvider (lexigram-vector, optional)
├── RAGProvider (lexigram-ai-rag, optional)
├── Observability (always on: metrics, tracing, health)
├── Governance (optional)
└── Entry-point discovery (any subsystem with ep group)

AIModule is the public entrypoint. AIProvider is the internal orchestrator that delegates to sub-providers.

The single config object that drives the entire AI subsystem. It nests sub-configs for each subsystem:

from lexigram.ai.config import AIConfig
from lexigram.ai.llm import ClientConfig
config = AIConfig(
enabled=True,
llm=ClientConfig(provider="openai", model="gpt-4o"),
# vector=VectorConfig(...),
# rag=RAGConfig(...),
)

Config is read from LEX_AI__* environment variables or the ai: section of application.yaml.

The provider class that orchestrates sub-providers. In register() it:

  1. Registers monitoring singletons (AIHealthMonitor, AIMetrics, AITracer, CallbackManagerProtocol)
  2. Delegates LLM, Vector, and RAG to their respective sub-providers
  3. Discovers additional subsystems via lexigram.ai.subsystems entry points
  4. Wires governance and RAG cache when the relevant config is present
from lexigram.ai.di.provider import AIProvider
provider = AIProvider(config=AIConfig(llm=ClientConfig(provider="openai")))
# Used internally by AIModule — you normally don't instantiate it directly

Any installed package declaring the lexigram.ai.subsystems entry-point group is automatically discovered:

# pyproject.toml of a subsystem package
[project.entry-points."lexigram.ai.subsystems"]
llm = "lexigram.ai.llm.di.provider:LLMProvider"

The AIProvider.register() method loads each entry point and calls sub_provider.register(container).

from lexigram import Application
from lexigram.ai.module import AIModule
from lexigram.ai.llm import ClientConfig
from lexigram.contracts.ai import LLMClientProtocol
async def main() -> None:
config = AIConfig(llm=ClientConfig(provider="openai", model="gpt-4o"))
async with Application.boot(
name="ai-demo",
modules=[AIModule.configure(config)],
) as app:
llm = await app.container.resolve(LLMClientProtocol)
result = await llm.complete([{"role": "user", "content": "Hello!"}])
if result.is_ok():
print(result.unwrap().content)
from lexigram.contracts.core import HealthStatus
health = await app.health_check()
print(health.status) # HealthStatus.HEALTHY or .DEGRADED
from lexigram import Application
from lexigram.ai.di.provider import AIProvider
from lexigram.ai.config import AIConfig
app = Application(name="ai-demo")
app.add_provider(AIProvider(config=AIConfig(llm=ClientConfig(provider="openai"))))
await app.start()
  • Start with AIModule.configure() — it’s the intended public API. Only drop to AIProvider directly when you need fine-grained control over sub-provider configuration.
  • One AIConfig per app — the AI subsystem is designed as a singleton. Creating multiple instances will register duplicate bindings.
  • Use env vars for secrets — set LEX_AI_LLM__API_KEY instead of hardcoding API keys. AIConfig reads environment variables automatically.
  • Enable governance in productionAIConfig(governance=GovernanceConfig(enabled=True)) provides an audit trail for AI operations.
  • Don’t import sub-packages directly — resolve LLMClientProtocol through the container instead of importing LLMProvider or individual clients.