> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Recap Foundations

> Overview of the Claude Agent SDK's one-loop Think Act Observe Decide workflow, tool categories, determinism, and stateful memory plus guardrails for safe, auditable automation

Module 1, Foundations.

Let's bring the three core pieces together and review how each one builds on the previous.

At the heart of the system is a single query loop: you call `query`, hand Claude an instruction, and the SDK runs one loop to complete the task—Think → Act → Observe → Decide. The model reads your prompt, selects a tool, inspects the tool's output, and then either finishes or loops again.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/_CTwEK7wfhlq4R-D/images/Learn-By-Doing-Building-AI-Agents-with-Claude-Agent-SDK/Foundations/Recap-Foundations/think-act-observe-decide-loop.jpg?fit=max&auto=format&n=_CTwEK7wfhlq4R-D&q=85&s=ab7166f47ec52b8ea3eec768899ca608" alt="A circular flowchart titled &#x22;One Query, One Loop: Think → Act → Observe → Decide.&#x22; It shows four boxes: Think (read the prompt), Act (run a tool), Observe (read the result), and Decide (done, or loop again)." width="1920" height="1080" data-path="images/Learn-By-Doing-Building-AI-Agents-with-Claude-Agent-SDK/Foundations/Recap-Foundations/think-act-observe-decide-loop.jpg" />
</Frame>

The important operational detail: you do not implement that loop yourself. The Claude Agent SDK orchestrates it and streams a sequence of structured messages rather than returning a single string. Those streamed messages include:

* assistant messages that reveal the model’s internal reasoning and any tool calls, and
* a final result message that closes the run with cost, token usage, and timing.

One query, one loop, a full stream of messages—this makes debugging and observability straightforward.

Toolbox: capabilities and purpose

You then gave the agent a toolbox. A compact set of tools expands into four practical capability categories. Each category targets a different phase of a real-world change workflow:

| Category | Purpose | Examples |
| - | - | - |
| Discovery | Inspect and understand a codebase or environment before making changes | `Glob`, `Read`, `Grep` |
| Modification | Make precise edits to files and write new content | `edit`, `multi-edit`, `write` |
| Execution | Run commands to see real system behavior | `bash` (execute shell commands) |
| Output | Record documentation, logs, or generated artifacts | `write` tools that persist results |

<Callout icon="lightbulb" color="#1CB2FE">
  Design agents so the model decides what to do and deterministic tools do the work. Streaming tool outputs back to you improves traceability and reduces hallucinations.
</Callout>

A single guiding rule underpins safe, reliable agents: production agents should be \~99% deterministic tools and \~1% model reasoning. In other words, the model orchestrates and chooses actions; the tools perform concrete operations on files, run commands, and return reproducible outputs. Because tools interact with real files and systems, they minimize hallucination and make results auditable.

State: memory and guardrails

A one-shot query is stateless: it forgets everything between calls. That means if you ask for encryption settings in one stateless query, the model won’t remember which bucket you meant the next time. Replacing single-shot queries with the Claude SDK client gives your agent persistent context across turns. Memory lets the agent remember what it has built and enables iterative, multi-step workflows without restarting each time.

Two controls determine what the agent can touch:

* Permission mode — how freely the agent may act (e.g., read-only vs. full modify).
* Allowed tools — which toolset is available to the agent.

Memory plus guardrails yields a stateful agent you can trust to operate on real infrastructure.

<Callout icon="warning" color="#FF6B6B">
  Set strict permission modes and carefully limit allowed tools for production agents. Even with deterministic tools, overly broad permissions increase risk.
</Callout>

Recap of the arc

* A single-turn query proved the agent could access your systems and run the Think → Act → Observe → Decide loop.
* A real toolbox enabled discovering, modifying, executing, and validating changes against the actual environment.
* Memory allowed the agent to maintain context across turns and build multi-step workflows incrementally.

Next steps

From this foundation you can extend the agent in three directions: teach reusable skills, delegate to specialized sub-agents, and connect to external systems and labs. For hands-on practice, see [Udemy Labs: Model Context Protocol (MCP) for Beginners](https://learn.kodekloud.com/user/courses/udemy-labs-model-context-protocol-mcp-for-beginners).

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/learn-by-doing-building-ai-agents-with-claude-agent-sdk/module/c7046700-56e6-42f1-9530-3e70b2e24350/lesson/087a86b3-f7ee-4eee-b978-f3efbc56f100" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.