Skip to main content
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.
A circular flowchart titled "One Query, One Loop: Think → Act → Observe → Decide." It shows four boxes: Think (read the prompt), Act (run a tool), Observe (read the result), and Decide (done, or loop again).
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:
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.
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.
Set strict permission modes and carefully limit allowed tools for production agents. Even with deterministic tools, overly broad permissions increase risk.
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.

Watch Video