Flows category icon
Agent Architecture
Advanced

Design a Single-Loop Agent

Build the core agent loop the leading coding agents use: one model, one loop, tools in, results folded back into context.

5 steps15 verify checks90-150 minutesWorks with: emergent · chatgpt · claude · cursor
Start Guided Walkthrough

The Route

0/5 verified

Context Pack

Paste this first. It briefs the AI on requirements, constraints, and the Definition of Done before your first build prompt.

Context Pack
PROJECT CONTEXT:
I want to build an AI agent and I keep seeing complex multi-agent diagrams. Research on the strongest coding agents shows they run ONE main loop: model call, tool execution, fold results back, repeat until done.

GOAL:
Implement a robust single-loop agent: message history, tool dispatch, result folding, and a clear termination condition.

REQUIREMENTS:
- A single main loop: send context, receive text or tool calls, execute tools, append results, repeat
- A typed tool registry with JSON-schema definitions per tool
- Deterministic termination: max turns, explicit finish signal, and error budget
- Tool results folded back into the conversation in strict order
- A transcript log of every turn for debugging

CONSTRAINTS:
- One loop, one model call at a time - no parallel model calls in v1
- No framework magic: the loop must be readable in a single file

DEFINITION OF DONE:
- The agent completes a 3-tool task (read file, edit, verify) end to end
- The loop terminates on finish signal, max turns, and repeated errors
- Every turn is logged with role, content, and tool payloads
- Malformed tool calls are rejected with a corrective message, not a crash

COMMON FAILURES TO AVOID:
- Building an orchestration framework before a single loop works
- Dropping or reordering tool results so the model loses causality
- No termination condition - the agent loops forever on a stuck task
- Swallowing tool errors instead of showing them to the model

Paste this into your AI builder first. It teaches the AI what you want before you give it the build prompt.

Related routes

More Agent Architecture flows that share ground with this one.

Flows category icon
Agent Architecture

Add a Plan/Todo System to Your Agent

Give your agent the planning discipline of the leading harnesses: an explicit, model-visible todo list that survives long tasks.

01Design the todo data model and tool
02Render the plan into context every turn
03Enforce plan-first and completion gates

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps60-90 minutesIntermediate
Flows category icon
Agent Architecture

Assemble a System Prompt Like the Pros

Structure your agent's system prompt the way leading harnesses do: layered sections, dynamic context, and enforceable rules.

01Decompose the current prompt
02Build the section-based assembler
03Pair rules with enforcement

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps60-90 minutesIntermediate
Flows category icon
Agent Architecture

Sub-Agent Delegation with Context Isolation

Delegate bounded work to sub-agents that run in fresh context and return only distilled results - the pattern behind scalable long tasks.

01Specify the delegation contract
02Implement the isolated sub-loop
03Wire dispatch into the parent and distill

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-150 minutesAdvanced

Made with Emergent