Looking at this through the lens of maximum reusability with achievable decoupling, the smallest cohesive foundational layer would be:The smallest cohesive reusable foundational layer consists of 6 core components that represent the irreducible abstractions needed for any prompt engineering system:
The 4 Essential Abstractions
- BaseModule - The execution primitive (like PyTorch’s nn.Module)
- Signature - The interface contract (declarative I/O specification)
- BaseBackend - The AI service interface (works for any AI modality)
- Adapter - The format bridge (structured ↔ raw format conversion)
The 2 Essential Data Types
- Example - Universal data container
- Settings - Configuration context
Why This Boundary is Optimal
Reusability Test: These 6 components appear in every prompt engineering system I can imagine - from simple chatbots to complex agents to multi-modal applications.
Decoupling Achievement:
- ✅ Zero knowledge of specific LLM providers
- ✅ Zero dependencies on heavy ML libraries
- ✅ Zero assumptions about prompt formats or optimization strategies
- ✅ Only ~2,000 lines of code with minimal dependencies (just
pydantic
)
Completeness Test: You can build any prompt engineering pattern with just these primitives:
- Traditional completion systems
- Agent frameworks
- Tool-using systems
- Multi-modal applications
- Reasoning chains
This is the “Linux kernel” approach - the minimal, stable foundation that everything else builds upon. Any smaller and you lose essential functionality. Any larger and you include implementation details that reduce reusability.
The key insight is that this foundation is paradigm-agnostic - it doesn’t assume chat vs. completion, doesn’t assume specific reasoning patterns, doesn’t assume particular AI services. It just provides the essential abstractions that any AI interaction system needs.