Architecture

On this page

There is no CLI, web server, ORM, or plugin-discovery mechanism in this package. Extensibility is achieved through plain constructor injection (e.g. passing a custom ContextManager or extra Guardrail objects into PromptEngine) and the STRATEGY_REGISTRY dict.

Module dependency graph

ab_testing.py is the one module with no import dependency on the rest of the package — it operates on plain strings and an injected llm object, and only optionally introspects a rag_system via getattr/hasattr at runtime (see api/ab_testing).

Request lifecycle: PromptEngine.build()

Class relationships

Extension points

Extension pointMechanismWhere
Custom context logicPass your own ContextManager subclass/instance to PromptEngine(context_manager=...)api/prompt_engine
Extra guardrailsPass extra_guardrails=[Guardrail(...), ...] to PromptEngine or directly to GuardrailEngineapi/guardrails
New reasoning strategySubclass BaseStrategy, implement _build_system/_build_user, register it in STRATEGY_REGISTRYapi/strategies
Event hooksengine.on("prompt.built", callback) — currently the only event name fired in the source is "prompt.built"api/prompt_engine
External memory/cache/routerConstructor params memory_store, cache_store, router are stored on PromptEngine but not referenced anywhere else in the provided source — they appear to be integration handles reserved for external wiringapi/prompt_engine

[!WARNING] Unused integration handles memory_store, cache_store, and router are accepted and stored by PromptEngine.__init__, but no method in prompt_engine reads them. Documenting them as functional would be speculative; treat them as forward-declared extension slots until their consumers appear in the codebase.

Initialization order

  1. PromptEngine.__init__ builds a GuardrailEngine (using guardrail_engine if given, else a new one seeded with extra_guardrails).
  2. It builds a PromptBuilder, passing in context_manager (or a new ContextManager()) and the guardrail engine.
  3. State containers are initialized: _metrics (PromptMetrics), _cache (dict), _feedback (list), _hooks (defaultdict(list)), _trace_log (list).
  4. No I/O, network calls, or file reads happen during construction — everything is in-memory.

Related pages