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:

  1. Receive — prompt, settings, session history, and tool schemas enter the model’s context
  2. Decide — the model reasons and chooses: answer now, or call a tool
  3. Execute — approved tools run; results return to the model
  4. 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.