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
Execution
Sub-Agent Pattern
A parent agent (K9AgentSpawner) spawns lightweight ChildAgents that execute concurrently and independently, then merges their results — applying the multithreading model to enterprise agentic AI.
Used in
K9AgentSpawnerChildAgentK9TransactionAgentK9Newfoundland
Routing
Event Router Pattern
Single entry point for all events — deterministic routing when intent is known, decoupled IntentOrchestrator when it is not, guaranteed response in all cases.
Used in
K9EventRouterIntentOrchestratorIntentSquadK9IntentAgent
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
Inference
LLM Invoke Pattern
Single utility function — llm_invoke() — encapsulates all inference calls with retry, governance, and audit in one place.
Used in
llm_invoke()K9ValidationLoopAgentK9CriticActorAgentK9IntentAgent
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
Theoretical Lineage

Enterprise Integration Patterns Mapping

These patterns are not new. They are established Enterprise Integration Patterns (Hohpe & Woolf, 2003) applied to agentic AI — with formal ABB contracts, structural governance, and lifecycle guarantees added. K9-AIF did not invent the concepts. It brought the discipline.

EIP PatternK9-AIF EquivalentWhat K9-AIF adds
Pipes and FiltersAgent Squad — sequential flowShared context enrichment, governance per step
Scatter-GatherSub-Agent Pattern — K9AgentSpawnerNo-orphan guarantee, deadlock prevention, bounded concurrency
Aggregatormerge_results() in K9AgentSpawnerSBB-controlled result policy, partial failure handling
SplitterK9AgentSpawner splitting work to ChildAgentsTyped ChildAgent contract, lifecycle registry
Content-Based RouterK9EventRouterSingle entry point, intent fallback, governance boundary
Content EnricherContext enrichment — each agent enriches shared contextProgressive enrichment contract across the Squad flow
Process ManagerOrchestratorSquad coordination, governance enforcement, Zero Trust layer
Publish-Subscribe ChannelKafka topics per domainRouter owns publish; Orchestrator owns consume — strict ownership
Transactional ClientK9TransactionAgent — 2-Phase CommitFormal PREPARE/COMMIT/ROLLBACK over ChildAgents
Wire TapGovernance pipeline interceptPre/post hooks on every agent, enforced in production
Canonical Data ModelK9-AIF shared context payloadTyped payload contract flowing Router → Squad → Agent
Correlation Identifiersession_id + transaction_id in payloadSession ABB with Redis-backed store, TTL, enable/disable flag
Message StoreK9Session — session_context persistenceProvider-agnostic store (Redis / SQLite / InMemory), auto-wired from config
Dead Letter ChannelPlanned
Idempotent ReceiverPlanned

Reference: Hohpe, G. & Woolf, B. — Enterprise Integration Patterns (Addison-Wesley, 2003)