The Claude agent loop explained — Transcript
Full transcript
- 0:02You've made API calls, but a single call
- 0:04only returns [music] one response.
- 0:06If you want to replace workflows, well,
- 0:08Claude needs to act, look at the result,
- 0:11decide what's next, and keep going. And
- 0:13this is what's commonly known as agentic
- 0:15workflows.
- 0:18An agent is an autonomous version of
- 0:20Claude running both sides of the
- 0:21messaging loop without human
- 0:22involvement. Agents receive a task, pick
- 0:25a tool, and execute code in a loop until
- 0:28Claude deems the task done.
- 0:31Here's the easiest way to implement an
- 0:32agent loop.
- 0:33First, send a message to Claude with
- 0:35tools available.
- 0:37Then, Claude responds with either a
- 0:39final answer
- 0:40or uses a tool that you define.
- 0:43Then, your code executes that tool.
- 0:46And then that result is sent back to
- 0:48Claude.
- 0:49And this repeats until stop reason is
- 0:51end turn.
- 0:55I want to see this loop run end to end
- 0:56without dragging in a database or UI.
- 0:58So, I'll wire up a fake Get weather, and
- 1:01ask Claude what to wear in Austin today.
- 1:04Claude has no way to know the weather on
- 1:06its own, so it'll have to call the tool,
- 1:08read the result, and then give you an
- 1:09answer. So, here's the whole script.
- 1:12First, the tools array tells Claude
- 1:14what's available. Name,
- 1:16description,
- 1:18and a JSON schema for the inputs.
- 1:21Run tool is just a hard-coded lookup. In
- 1:24a real app, this would hit your
- 1:25database, an API, whatever.
- 1:28And then our loop here is the agent
- 1:29loop.
- 1:30Each iteration sends messages to Claude
- 1:32and switches on the response stop
- 1:34reason. And so, if the response is end
- 1:37turn, then Claude is done. Print the
- 1:39final text and just break. But, on tool
- 1:42use, find the tool use block in the
- 1:44response, run each one, and push the
- 1:46assistant's response and our tool
- 1:47results back into messages and loop
- 1:49again, so Claude can answer.
- 1:52So, let's run it.
- 1:53You'll see two turns. Turn one is the
- 1:56stop reason, which is tool use.
- 1:58Claude requests get weather, which is
- 2:00Austin in this case.
- 2:02Our code returns the temp and the
- 2:04conditions.
- 2:06And then turn two, the stop reason is
- 2:08end turn. And so Claude tells you to
- 2:10wear something light and breathable. Two
- 2:12API calls, one tool execution, and one
- 2:14final answer. And that's the entire
- 2:16loop. Everything that you make with the
- 2:18Claude API is going to be similar to
- 2:20this. And so in a real environment, this
- 2:23same loop powers something like auto
- 2:25review endpoint, a compliance agent that
- 2:27reads a structural report, looks up the
- 2:29relevant building codes via tool, and
- 2:31writes risk finding back to the database
- 2:33one by one as it works. The shape of the
- 2:36loop is identical to what you just ran.
- 2:38The differences are real tools instead
- 2:40of a mock weather lookup, results stream
- 2:42back to the UI as server-sent events,
- 2:45and findings persisted to a risk finding
- 2:48table.
- 2:50An agent is Claude in a loop. Observe,
- 2:53decide, act, repeat. You own the loop
- 2:56and the tools. Claude owns the
- 2:58reasoning. And when you don't want to
- 3:00own the loop, managed agents run this
- 3:02exact loop for you on Anthropic's
- 3:04infrastructure.
About this transcript
This page contains the full transcript of The Claude agent loop explained by Claude, generated from the public captions YouTube serves with the video. The transcript has 528 words across 86 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.