Kabelo Dike / AI Stack Mental Model

The Application Layer

The core concept: the brain vs. the body

Let’s start at the boundary of the Application layer and the “foundation model” layer. Below this layer, a foundation model is a pure, stateless compute engine. It does not behave like a persistent application server, an active process, or a database. It behaves much like a mathematical function: tokens in, tokens out.

Because the model itself cannot hold state, remember past interactions, access files, or execute actions, the Application Layer exists to build a complete, reliable software system around that stateless core. It orchestrates the entire operational lifecycle of a task.

Key distinction: orchestrator vs. model (common confusion)

The model is an invoked dependency L4
It has zero control over execution flow. It simply receives an input payload and computes a response.
The orchestrator is the control plane L5
It is the deterministic software runtime (written in Python, Go, TypeScript, etc.) that maintains state machines, executes database/API calls, manages the loop, and calls the model as a sub-routine.

The user interface (UI): surface area and ingress

Now let’s look at the very front of the Application Layer: the UI.

You interact with this every day, whether that is the standalone chat interface (typically on your phone app or website) in ChatGPT, Claude, or Gemini, or embedded tools like GitHub Copilot living directly inside VS Code.

Its role in an AI system is fundamentally different from a regular app. In traditional software, a button click simply calls a deterministic endpoint (POST /submit). In an AI application, the UI is an ingress boundary that captures human intent, streams back asynchronous execution in real time, and acts as a human-in-the-loop checkpoint.

It has four core responsibilities:

  • Token streaming: Because generating answers token-by-token takes time, the UI cannot wait on a traditional 10-second blocking HTTP request. It maintains an open connection (like Server-Sent Events) to render tokens on your screen word-by-word as they are generated, keeping perceived latency low.
  • Telemetry & execution visibility: In an agentic system, the model does not just spit out text; it performs work behind the scenes. The UI is responsible for showing that progress so you know the system is executing rather than frozen:
    • In the Claude or Gemini apps, you see collapsible pillboxes saying “Searching documentation…” or “Running code…”.
    • In GitHub Copilot, you see it index workspace files, read a function signature, and draft a pull request diff.
  • Approval checkpoints (human-in-the-loop): For destructive or high-risk actions, the UI serves as a safety gate. When GitHub Copilot CLI suggests a terminal command or an enterprise assistant stages a database modification, the UI pauses execution and presents an explicit Approve / Reject / Edit checkpoint before anything touches production.
  • Capturing ambient context: Beyond the text you type into the prompt box, modern AI interfaces automatically capture your surrounding environment (the open file tab in your editor, your cursor position, or your authenticated user session) and package it as context for the runtime below.

The architectural boundary The UI never calls the foundation model directly, and it never touches databases or external tools on its own. It sends your intent down to the Harness and Orchestrator, which manage the actual execution loop and stream the results back to the screen.

The runtime engine: the agent harness

Once the UI captures user intent, it hands execution over to the core runtime kernel of the Application Layer: the Harness.

Remember our boundary rule: the foundation model is completely stateless. It cannot retain memories, manage sessions, or know what you asked three seconds ago. The harness is the software scaffolding wrapping the model that makes it behave like a durable, reliable system.

It handles four continuous operational responsibilities:

  • Session persistence and memory: Because the model forgets everything between API calls, the harness maintains state. It stores chat history, intermediate variables, and task progress in external databases (like Redis or PostgreSQL). Every time it invokes the model, the harness reassembles and injects the necessary past context so the conversation feels seamless.
  • Context window budgeting: Every model has a hard token limit. If a prompt becomes too long, the API call fails or drops critical instructions. The harness actively manages this budget: it truncates older messages, summarizes background discussions, or swaps out data so the prompt remains within safe token caps.
  • Intent extraction and schema validation: The model outputs probabilistic text, but enterprise software requires deterministic data structures. The harness enforces strict schemas (like JSON Schema) on the model’s output. If the model generates a malformed payload or misses a required field, the harness catches the error internally and reprompts the model before bad data ever touches downstream systems.
  • Guardrails and policy enforcement: The harness operates security and compliance filters on both sides of the model call. Inbound, it sanitizes input, masks sensitive PII (like customer IDs or account numbers), and blocks prohibited requests. Outbound, it inspects the generated output to make sure it complies with company policies before sending it back to the UI or passing it to external tools.

The boundary The harness is the runtime sandbox. It ensures the model operates within strict token budgets, maintains memory across requests, and obeys deterministic business rules.

Execution control: orchestration and control loops

Now that the harness has prepared the context, how does real work actually progress? That is where Orchestration comes in.

A simple chatbot is a single turn: you ask a question, the model gives an answer, and execution stops. An agentic system, however, runs a multi-step workflow until a broader objective is met. The orchestrator is the state machine running that loop:

  • The ReAct loop (Reason + Act): The orchestrator guides the system through an iterative cycle: Plan (the model evaluates what it needs to do), Act (the model requests a tool call), Observe (the orchestrator executes the tool and passes the output back), and Repeat until the goal is finished.
  • Deterministic graphs vs. autonomous paths:
    • In a Deterministic Pipeline, engineers hardcode the exact path (Step 1 → Step 2 → Step 3), using the model solely to extract or summarize data at each node.
    • In an Autonomous Loop, the model dynamically decides the path based on intermediate results, pivoting if a tool returns an unexpected error.
  • State machine mechanics: The orchestrator keeps track of execution states (Planning, Executing_Tool, Awaiting_Human_Approval, Complete) so if a process fails halfway through, the system can retry or recover without restarting the whole job.

System capabilities: tool use and function calling

During that orchestration loop, the model often realizes it lacks data. It needs to look up a customer record, query a SQL database, or check an API.

Because the model is sandboxed and cannot execute code or touch networks, tool use follows a strict four-step contract:

  1. Schema advertisement: In the API call, the orchestrator passes a menu of available tools defined as structured schemas (e.g., JSON Schema detailing search_orders(customer_id: string, date_range: string)).
  2. Intent to act (not execution): The model does not run the query itself. It outputs a structured payload stating: “I intend to call search_orders with the argument {'customer_id': '1048'}”.
  3. Host-side execution: The orchestrator halts model generation, inspects the request against allowed permissions, and uses standard application code to execute the real database query or API call.
  4. Context injection: The orchestrator takes the raw database result, packages it as a tool response frame, appends it to the conversation history, and invokes the model again so it can synthesize the final answer.

Standardization: Model Context Protocol (MCP)

As systems scale, tool use hits an architectural bottleneck: the M × N integration problem.

If you have 5 different agent workflows (customer support, data analysis, internal dev tooling) and 10 different internal systems (Jira, GitHub, PostgreSQL, Snowflake, Google Drive), writing custom integration glue code for every combination requires building and maintaining 50 separate integrations.

Model Context Protocol (MCP) solves this by acting as an open, client-server standard for AI integration:

  • The MCP client: Lives inside your orchestrator and harness. It knows how to speak the universal MCP protocol.
  • The MCP server: A lightweight adapter sitting in front of a specific service (like your company’s ticket tracking or database). It advertises what it can do without caring which foundation model or framework is calling it.
  • Core primitives exposed:
    • Tools: Executable operations with side effects (e.g., create_jira_ticket).
    • Resources: Read-only contextual data feeds (e.g., reading logs or system docs).
    • Prompts: Standardized workflow templates maintained directly on the resource side.

By standardizing on MCP, you turn a complex web of point-to-point connections into a plug-and-play architecture. If you switch foundation models tomorrow, your MCP tool servers remain completely untouched.