Architecture Patterns

K9-AIF Pattern Catalog

Reusable architectural patterns for building governed, enterprise-scale agentic AI systems. Framework-agnostic. Production-tested in K9-AIF.

Execution
Agent Squad Pattern
Organize multiple agents into a coordinated execution unit with shared context, sequential flow, and governance enforcement.
Used in
BaseSquadSquadLoaderEOC domain squadsDoW DoDAF stages
Execution
Validation Loop Pattern
Enable iterative hypothesis testing — validate, observe, and retry until confidence is sufficient or iteration cap is reached.
Used in
BaseValidationLoopAgentK9ValidationLoopAgentFraudDetectionAgentDocumentExtractorAgent
Execution
Critic-Actor Pattern
An Actor produces a draft; a Critic evaluates it; the Actor refines — repeating until quality bar is met or escalation triggers.
Used in
BaseCriticActorAgentK9CriticActorAgentContract draftingReport writing
Inference
Model Router Pattern
Dynamically select the most appropriate model based on task type, cost, latency, and policy — fully decoupled from agent code.
Used in
BaseModelRouterK9ModelRouterModelRouterFactoryllm_invoke()
Inference
Inference Layer Pattern
Provider-independent inference layer — ABB contracts separate from SBB implementations. Swap Ollama, Watsonx, or OpenAI via config.
Used in
LLMFactoryOllamaLLMInferenceRequestProviderAdapterRegistry
Inference · Integration
Provider Adapter Pattern
Support multiple pluggable backends without coupling factories or agents to any vendor — LLMs, secret managers, caches.
Used in
SecretManagerFactoryCacheFactoryK9XLiteLLMBridgeAdapterEnvSecretAdapter
Governance · Execution
Factory Pattern
Centralise component instantiation through static factories. Never instantiate agents, routers, or LLMs directly in application code.
Used in
AgentRegistryRouterFactoryLLMFactoryModelRouterFactory
Governance · Execution
Runtime Agent Loader Pattern
Load and wire agents, squads, and orchestrators from declarative YAML at runtime — change orchestration without changing code.
Used in
SquadLoaderAgentLoader_load_squad()k9_generator.sh
Integration
External Connector Pattern
Access external systems through a standardised connector layer with governance enforced at the boundary — APIs, databases, MCP servers.
Used in
MCPHttpConnectorMCPStdioConnectorBaseMCPAgentDocling OCR