YouTube2Text

The Claude agent loop explained — Transcript

by Claude · 528 words · 86 segments · language en · Watch on YouTube

Full transcript

  1. 0:02You've made API calls, but a single call
  2. 0:04only returns [music] one response.
  3. 0:06If you want to replace workflows, well,
  4. 0:08Claude needs to act, look at the result,
  5. 0:11decide what's next, and keep going. And
  6. 0:13this is what's commonly known as agentic
  7. 0:15workflows.
  8. 0:18An agent is an autonomous version of
  9. 0:20Claude running both sides of the
  10. 0:21messaging loop without human
  11. 0:22involvement. Agents receive a task, pick
  12. 0:25a tool, and execute code in a loop until
  13. 0:28Claude deems the task done.
  14. 0:31Here's the easiest way to implement an
  15. 0:32agent loop.
  16. 0:33First, send a message to Claude with
  17. 0:35tools available.
  18. 0:37Then, Claude responds with either a
  19. 0:39final answer
  20. 0:40or uses a tool that you define.
  21. 0:43Then, your code executes that tool.
  22. 0:46And then that result is sent back to
  23. 0:48Claude.
  24. 0:49And this repeats until stop reason is
  25. 0:51end turn.
  26. 0:55I want to see this loop run end to end
  27. 0:56without dragging in a database or UI.
  28. 0:58So, I'll wire up a fake Get weather, and
  29. 1:01ask Claude what to wear in Austin today.
  30. 1:04Claude has no way to know the weather on
  31. 1:06its own, so it'll have to call the tool,
  32. 1:08read the result, and then give you an
  33. 1:09answer. So, here's the whole script.
  34. 1:12First, the tools array tells Claude
  35. 1:14what's available. Name,
  36. 1:16description,
  37. 1:18and a JSON schema for the inputs.
  38. 1:21Run tool is just a hard-coded lookup. In
  39. 1:24a real app, this would hit your
  40. 1:25database, an API, whatever.
  41. 1:28And then our loop here is the agent
  42. 1:29loop.
  43. 1:30Each iteration sends messages to Claude
  44. 1:32and switches on the response stop
  45. 1:34reason. And so, if the response is end
  46. 1:37turn, then Claude is done. Print the
  47. 1:39final text and just break. But, on tool
  48. 1:42use, find the tool use block in the
  49. 1:44response, run each one, and push the
  50. 1:46assistant's response and our tool
  51. 1:47results back into messages and loop
  52. 1:49again, so Claude can answer.
  53. 1:52So, let's run it.
  54. 1:53You'll see two turns. Turn one is the
  55. 1:56stop reason, which is tool use.
  56. 1:58Claude requests get weather, which is
  57. 2:00Austin in this case.
  58. 2:02Our code returns the temp and the
  59. 2:04conditions.
  60. 2:06And then turn two, the stop reason is
  61. 2:08end turn. And so Claude tells you to
  62. 2:10wear something light and breathable. Two
  63. 2:12API calls, one tool execution, and one
  64. 2:14final answer. And that's the entire
  65. 2:16loop. Everything that you make with the
  66. 2:18Claude API is going to be similar to
  67. 2:20this. And so in a real environment, this
  68. 2:23same loop powers something like auto
  69. 2:25review endpoint, a compliance agent that
  70. 2:27reads a structural report, looks up the
  71. 2:29relevant building codes via tool, and
  72. 2:31writes risk finding back to the database
  73. 2:33one by one as it works. The shape of the
  74. 2:36loop is identical to what you just ran.
  75. 2:38The differences are real tools instead
  76. 2:40of a mock weather lookup, results stream
  77. 2:42back to the UI as server-sent events,
  78. 2:45and findings persisted to a risk finding
  79. 2:48table.
  80. 2:50An agent is Claude in a loop. Observe,
  81. 2:53decide, act, repeat. You own the loop
  82. 2:56and the tools. Claude owns the
  83. 2:58reasoning. And when you don't want to
  84. 3:00own the loop, managed agents run this
  85. 3:02exact loop for you on Anthropic's
  86. 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.