AI Business Maturity Model
Certifications
Find a CoachFind a SpeakerSign In
Recursive AI Tool Loop

/

Deep Dive

Recursive AI Employee

Deep Dive

A complete technical walkthrough of every moving part — from the moment a user sends a message to the moment a response appears. Built on a real-world implementation by Coulee Tech, generalized as a reusable framework pattern.

The Big Picture

An AI Employee is not a program you write — it is a config object you define. The shared engine handles all execution. This separation means you can add a new Employee by writing a TypeScript object, not a new loop.

WorkerDefinition

Config (who you are)

+

Worker Engine

Runtime (how you run)

=

AI Employee

Fully functional agent

No Employee has its own loop code. They all share the same engine. This is the key architectural insight.

How It All Connects

The complete lifecycle of a single user message. Click any highlighted node to jump to that section of the deep dive.

Explore Each Part

Each section is a standalone deep dive. Read them in order for the full picture, or jump to the part you need.

1

The Worker Definition

The Employee's DNA

Every AI Employee is a plain TypeScript config object — not a program. Learn how a single interface encodes identity, tools, loop guardrails, and expertise.

WorkerDefinition
Config
System Prompt
Pre-Enrichment

2

The Tool System

The Employee's Hands

Tools are how the AI interacts with the real world. Understand the ToolResult contract, permission tiers, naming conventions, and how the registry executes calls.

ToolResult
Permissions
Registry
Parallel Execution

3

The Worker Engine

The Loop That Runs Everything

A 6-phase state machine shared by every Employee. From state initialization through pre-enrichment, the main loop, escalation, and synthesis fallback.

State Machine
Living Document
Escalation
Exit Conditions

4

The Streaming Layer

How the UI Stays Live

The engine is an async generator that yields events as they happen. See every event type, what triggers it, and how the UI reacts in real time.

SSE
Async Generator
Event Types
Real-Time

5

The API Layer

How a Message Gets In

The route handler that validates, authenticates, resolves the Employee, and wires the streaming engine to the HTTP response — including approval re-entry.

Route Handler
Auth
Session Scoping
Approval Re-entry

6

A Complete Session

End-to-End Walkthrough

Follow a real session from first message to final response across 5 passes. See the AI's thinking at every decision point, cost breakdown, and design principles.

End-to-End
AI Thinking
Cost Analysis
Design Principles
Reading Guide for AI Assistants

Each sub-page contains genericized TypeScript code and annotated “AI thinks” callouts that show the AI's internal reasoning at each step. The code is structurally identical to Coulee Tech's production system but uses generic domain names so the patterns apply to any use case.

To implement this pattern: start with Part 1 (Worker Definition) to understand the config interface, then Part 3 (Engine) for the loop, then Part 6 (Complete Flow) to see it all together.

Back to Recursive AI Tool Loop Overview