Agent Loop
The agent loop is the fundamental execution pattern behind Claude Agent SDK and NVIDIA’s enterprise agent stack. A prompt plus settings enters the loop; the model decides whether to answer directly or call a tool; approved tools execute and return results; the loop continues until a final result is produced.
Structure
The loop has four repeating stages:
- Receive — prompt, settings, session history, and tool schemas enter the model’s context
- Decide — the model reasons and chooses: answer now, or call a tool
- Execute — approved tools run; results return to the model
- Repeat or terminate — loop continues until the model produces a final result
Key design concerns
The important design work is not model selection alone. It is how the application controls each stage:
- Tool permissions — which tools run automatically, which require approval, which are blocked
- Hooks — interception points for logging, blocking, or policy enforcement before/after tool execution
- Session — conversation history containing prompts, tool calls, results, and decisions; enables resume
- Context budget — the limited working memory consumed across all inputs; see ContextBudget
- Validation — output checked against acceptance criteria before being trusted
Enterprise implications
Loose tool permissions create data-integrity risk. Long sessions create context drift. Unvalidated results create operational risk. The loop boundary — what goes in, what tools are allowed, what state is persisted, what output is validated — is an architecture concern, not a prompt concern.
Session history is not the same as system state. File checkpoints, commits, and logs need their own durable controls outside the loop.
Related
- BoundedAgent — applying the loop inside explicit constraints
- ClaudeAgentSDK — Anthropic’s SDK implementation of the agent loop
- NVIDIANeMoAgentToolkit — NVIDIA’s agent workflow layer built on the same loop pattern
- ClaudeSDKAndCowork — synthesis of how the loop is used in practice