Summary: Autonomous AI agents are systems that execute multi-step workflows by iterating through a structured loop of reasoning, tool use, and result evaluation until a defined objective is met. They differ from single-turn LLMs by maintaining persistent state, managing context windows, and operating within safety budgets (turn limits, cost caps, permission modes).
Introduction
An autonomous agent transforms a stateless LLM into a persistent worker that can:
- Maintain context across multiple turns (files read, analysis performed, decisions made)
- Use tools to interact with environments (filesystem, shell, APIs, web)
- Self-correct based on tool output (test failures, lint errors, search results)
- Terminate based on evidence of completion rather than fixed turn counts
Core Architecture: agent-sdk, context-window-management, tool-use-patterns
Agent Loop (The Universal Pattern)
Diagram: (Mermaid diagram - view source for diagram code)
graph TD A[Receive Prompt] --> B[Evaluate & Respond] B --> C{Tool Calls?} C -->|Yes| D[Execute Tools] D --> E[Feed Back Results] E --> B C -->|No| F[Return Result]
Each iteration = one turn. The loop runs until:
- Task complete (evidence verifies outcome) ✅
- Budget exhausted (turn limit / cost cap) ⚠️
- Error / limit hit ❌
Key Components
| Component | Purpose | Examples |
|---|---|---|
| System Prompt | Defines agent role, tools, constraints | "You are a software engineer..." |
| Tool Definitions | Schemas for actions agent can take | Read, Edit, Bash, WebSearch |
| Memory/Context | Accumulated history across turns | File contents, analysis, decisions |
| Permission Mode | Controls autonomy level | acceptEdits, bypassPermissions |
| Budget Controls | Safety rails | max_turns, max_budget_usd |
Production-Grade Agent SDKs (2024–2025)
| SDK | Loop Type | Context Mgmt | Tool Parallelism | Permissions | Best For |
|---|---|---|---|---|---|
| Claude Code Agent SDK | Turn-based, async streaming | Auto-compaction, subagents, prompt caching | Read-only parallel, writes sequential | 6 modes (default → bypassPermissions) |
Dev agents, CI/CD, research repro |
| OpenAI Codex (Goals) | Persistent objective + evidence loop | Thread-scoped goals, continuation at safe boundaries | Sequential by default | Goal-scoped tool allowlist | Research repro, multi-step debugging |
| LangGraph | Stateful graph (cycles allowed) | Checkpointing, configurable reducers | Explicit parallel nodes | Custom middleware | Complex multi-agent workflows |
| AutoGen | Conversational multi-agent | Shared context + per-agent memory | Group chat patterns | Human-in-loop by default | Collaborative agent teams |
| CrewAI | Role-based sequential process | Process memory + task outputs | Sequential by default | Task-level permissions | Business process automation |
Design Patterns
1. Single-Agent Loop (Claude Code, Codex)
Prompt → [Reason → Act → Observe]ⁿ → Result
- Simple, predictable, auditable
- Best for: coding tasks, research reproduction, refactoring
2. Hierarchical / Subagent Delegation
Main Agent → Subagent A (investigate) → Summary
→ Subagent B (fix) → Summary
→ Main Agent (verify) → Result
- Fresh context per subtask, only summary returns
- Best for: large codebases, multi-repo tasks
3. Multi-Agent Orchestration (LangGraph, AutoGen)
Planner → [Researcher → Coder → Reviewer] → Integrator
- Explicit state machine, human checkpoints
- Best for: complex workflows, team simulation
Safety & Observability
| Control | Purpose |
|---|---|
max_turns |
Hard cap on tool-use rounds (prevents runaway loops) |
max_budget_usd |
Cost guardrail (stops at dollar threshold) |
permission_mode |
default/acceptEdits/plan/dontAsk/auto/bypassPermissions |
effort (low→max) |
Reasoning depth per turn; trade latency for quality |
| Session IDs | Resume/fork sessions; exact replay for debugging |
| Message Stream | SystemMessage, AssistantMessage, UserMessage, ResultMessage for observability |
Research Applications
| Use Case | Agent Pattern | Key SDK Feature |
|---|---|---|
| Paper reproduction | Single-agent + Goals | Evidence-based termination, audit trail |
| Hyperparameter search | Subagent per trial | Parallel exploration, shared context |
| Benchmark evaluation | Orchestrated pipeline | Checkpointing, resumable runs |
| Codebase archaeology | Hierarchical delegation | Subagents for file search, analysis |
Related Concepts
- agent-sdk — Primitive definitions (Agent, Tool, Memory, Orchestration)
- context-window-management — Compaction, caching, subagents, RAG
- tool-use-patterns — Sequential, parallel, conditional, recursive patterns
- claude-code — CLI implementation of the agent loop
- codex — OpenAI's autonomous coding agent with Goals
Sources
- how-the-agent-loop-works — Agent loop architecture, message types, control knobs
- using-goals-in-codex — Persistent goals, evidence-based completion, research workflows