Buckets:

hf-doc-build/doc-dev / agents-course /pr_545 /en /unit1 /agent-steps-and-structure.html
rtrm's picture
download
raw
25.2 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Understanding AI Agents through the Thought-Action-Observation Cycle&quot;,&quot;local&quot;:&quot;understanding-ai-agents-through-the-thought-action-observation-cycle&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;The Core Components&quot;,&quot;local&quot;:&quot;the-core-components&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;The Thought-Action-Observation Cycle&quot;,&quot;local&quot;:&quot;the-thought-action-observation-cycle&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Alfred, the weather Agent&quot;,&quot;local&quot;:&quot;alfred-the-weather-agent&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Thought&quot;,&quot;local&quot;:&quot;thought&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Action&quot;,&quot;local&quot;:&quot;action&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Observation&quot;,&quot;local&quot;:&quot;observation&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Updated thought&quot;,&quot;local&quot;:&quot;updated-thought&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Final Action&quot;,&quot;local&quot;:&quot;final-action&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/agents-course/pr_545/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/entry/start.1596c81c.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/scheduler.37c15a92.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/singletons.8a3d92bd.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/index.18351ede.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/paths.5b2602e7.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/entry/app.856a784e.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/index.2bf4358c.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/nodes/0.1cd5790a.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/nodes/22.7c14ecb1.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/CodeBlock.4e987730.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/Heading.8ada512a.js">
<link rel="modulepreload" href="/docs/agents-course/pr_545/en/_app/immutable/chunks/getInferenceSnippets.031140c2.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Understanding AI Agents through the Thought-Action-Observation Cycle&quot;,&quot;local&quot;:&quot;understanding-ai-agents-through-the-thought-action-observation-cycle&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;The Core Components&quot;,&quot;local&quot;:&quot;the-core-components&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;The Thought-Action-Observation Cycle&quot;,&quot;local&quot;:&quot;the-thought-action-observation-cycle&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Alfred, the weather Agent&quot;,&quot;local&quot;:&quot;alfred-the-weather-agent&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Thought&quot;,&quot;local&quot;:&quot;thought&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Action&quot;,&quot;local&quot;:&quot;action&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Observation&quot;,&quot;local&quot;:&quot;observation&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Updated thought&quot;,&quot;local&quot;:&quot;updated-thought&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Final Action&quot;,&quot;local&quot;:&quot;final-action&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="understanding-ai-agents-through-the-thought-action-observation-cycle" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#understanding-ai-agents-through-the-thought-action-observation-cycle"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Understanding AI Agents through the Thought-Action-Observation Cycle</span></h1> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/whiteboard-check-3.jpg" alt="Unit 1 planning"> <p data-svelte-h="svelte-7llfj6">In the previous sections, we learned:</p> <ul data-svelte-h="svelte-3e83i0"><li><strong>How tools are made available to the agent in the system prompt</strong>.</li> <li><strong>How AI agents are systems that can ‘reason’, plan, and interact with their environment</strong>.</li></ul> <p data-svelte-h="svelte-1dokcbw">In this section, <strong>we’ll explore the complete AI Agent Workflow</strong>, a cycle we defined as Thought-Action-Observation.</p> <p data-svelte-h="svelte-14c74an">And then, we’ll dive deeper on each of these steps.</p> <h2 class="relative group"><a id="the-core-components" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-core-components"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>The Core Components</span></h2> <p data-svelte-h="svelte-1o7nh6s">Agents work in a continuous cycle of: <strong>thinking (Thought) → acting (Act) and observing (Observe)</strong>.</p> <p data-svelte-h="svelte-optv5e">Let’s break down these actions together:</p> <ol data-svelte-h="svelte-1h7ub85"><li><strong>Thought</strong>: The LLM part of the Agent decides what the next step should be.</li> <li><strong>Action:</strong> The agent takes an action, by calling the tools with the associated arguments.</li> <li><strong>Observation:</strong> The model reflects on the response from the tool.</li></ol> <h2 class="relative group"><a id="the-thought-action-observation-cycle" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-thought-action-observation-cycle"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>The Thought-Action-Observation Cycle</span></h2> <p data-svelte-h="svelte-1qe4h0s">The three components work together in a continuous loop. To use an analogy from programming, the agent uses a <strong>while loop</strong>: the loop continues until the objective of the agent has been fulfilled.</p> <p data-svelte-h="svelte-s2kplf">Visually, it looks like this:</p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/AgentCycle.gif" alt="Think, Act, Observe cycle"> <p data-svelte-h="svelte-i9knc1">In many Agent frameworks, <strong>the rules and guidelines are embedded directly into the system prompt</strong>, ensuring that every cycle adheres to a defined logic.</p> <p data-svelte-h="svelte-140ldms">In a simplified version, our system prompt may look like this:</p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/system_prompt_cycle.png" alt="Think, Act, Observe cycle"> <p data-svelte-h="svelte-e5pmx1">We see here that in the System Message we defined :</p> <ul data-svelte-h="svelte-1a0b0ns"><li>The <em>Agent’s behavior</em>.</li> <li>The <em>Tools our Agent has access to</em>, as we described in the previous section.</li> <li>The <em>Thought-Action-Observation Cycle</em>, that we bake into the LLM instructions.</li></ul> <p data-svelte-h="svelte-1tsmln9">Let’s take a small example to understand the process before going deeper into each step of the process.</p> <h2 class="relative group"><a id="alfred-the-weather-agent" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#alfred-the-weather-agent"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Alfred, the weather Agent</span></h2> <p data-svelte-h="svelte-1232lbo">We created Alfred, the Weather Agent.</p> <p data-svelte-h="svelte-11lbwya">A user asks Alfred: “What’s the current weather in New York?”</p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/alfred-agent.jpg" alt="Alfred Agent"> <p data-svelte-h="svelte-1yedpwx">Alfred’s job is to answer this query using a weather API tool.</p> <p data-svelte-h="svelte-82uzmq">Here’s how the cycle unfolds:</p> <h3 class="relative group"><a id="thought" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#thought"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Thought</span></h3> <p data-svelte-h="svelte-bbakro"><strong>Internal Reasoning:</strong></p> <p data-svelte-h="svelte-x8n7iu">Upon receiving the query, Alfred’s internal dialogue might be:</p> <p data-svelte-h="svelte-1rwco72"><em>“The user needs current weather information for New York. I have access to a tool that fetches weather data. First, I need to call the weather API to get up-to-date details.”</em></p> <p data-svelte-h="svelte-nh852z">This step shows the agent breaking the problem into steps: first, gathering the necessary data.</p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/alfred-agent-1.jpg" alt="Alfred Agent"> <h3 class="relative group"><a id="action" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#action"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Action</span></h3> <p data-svelte-h="svelte-15s12fo"><strong>Tool Usage:</strong></p> <p data-svelte-h="svelte-5pokbk">Based on its reasoning and the fact that Alfred knows about a <code>get_weather</code> tool, Alfred prepares a JSON-formatted command that calls the weather API tool. For example, its first action could be:</p> <p data-svelte-h="svelte-rqzrlx">Thought: I need to check the current weather for New York.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;action&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;get_weather&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;action_input&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;location&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;New York&quot;</span>
<span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-u780jw">Here, the action clearly specifies which tool to call (e.g., get_weather) and what parameter to pass (the “location”: “New York”).</p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/alfred-agent-2.jpg" alt="Alfred Agent"> <h3 class="relative group"><a id="observation" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#observation"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Observation</span></h3> <p data-svelte-h="svelte-xv12jk"><strong>Feedback from the Environment:</strong></p> <p data-svelte-h="svelte-f8am0x">After the tool call, Alfred receives an observation. This might be the raw weather data from the API such as:</p> <p data-svelte-h="svelte-17ah7xm"><em>“Current weather in New York: partly cloudy, 15°C, 60% humidity.”</em></p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/alfred-agent-3.jpg" alt="Alfred Agent"> <p data-svelte-h="svelte-1qtefyv">This observation is then added to the prompt as additional context. It functions as real-world feedback, confirming whether the action succeeded and providing the needed details.</p> <h3 class="relative group"><a id="updated-thought" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#updated-thought"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Updated thought</span></h3> <p data-svelte-h="svelte-thyb76"><strong>Reflecting:</strong></p> <p data-svelte-h="svelte-12w4wqc">With the observation in hand, Alfred updates its internal reasoning:</p> <p data-svelte-h="svelte-26gu5r"><em>“Now that I have the weather data for New York, I can compile an answer for the user.”</em></p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/alfred-agent-4.jpg" alt="Alfred Agent"> <h3 class="relative group"><a id="final-action" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#final-action"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Final Action</span></h3> <p data-svelte-h="svelte-1ce6r84">Alfred then generates a final response formatted as we told it to:</p> <p data-svelte-h="svelte-oe9jao">Thought: I have the weather data now. The current weather in New York is partly cloudy with a temperature of 15°C and 60% humidity.”</p> <p data-svelte-h="svelte-1pdvdow">Final answer : The current weather in New York is partly cloudy with a temperature of 15°C and 60% humidity.</p> <p data-svelte-h="svelte-1o695ae">This final action sends the answer back to the user, closing the loop.</p> <img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/alfred-agent-5.jpg" alt="Alfred Agent"> <p data-svelte-h="svelte-beg0lg">What we see in this example:</p> <ul data-svelte-h="svelte-rhh31l"><li><strong>Agents iterate through a loop until the objective is fulfilled:</strong></li></ul> <p data-svelte-h="svelte-iiv7bs"><strong>Alfred’s process is cyclical</strong>. It starts with a thought, then acts by calling a tool, and finally observes the outcome. If the observation had indicated an error or incomplete data, Alfred could have re-entered the cycle to correct its approach.</p> <ul data-svelte-h="svelte-ibv0wc"><li><strong>Tool Integration:</strong></li></ul> <p data-svelte-h="svelte-9n1qd1">The ability to call a tool (like a weather API) enables Alfred to go <strong>beyond static knowledge and retrieve real-time data</strong>, an essential aspect of many AI Agents.</p> <ul data-svelte-h="svelte-hbr0le"><li><strong>Dynamic Adaptation:</strong></li></ul> <p data-svelte-h="svelte-1e08iqd">Each cycle allows the agent to incorporate fresh information (observations) into its reasoning (thought), ensuring that the final answer is well-informed and accurate.</p> <p data-svelte-h="svelte-xccp62">This example showcases the core concept behind the <em>ReAct cycle</em> (a concept we’re going to develop in the next section): <strong>the interplay of Thought, Action, and Observation empowers AI agents to solve complex tasks iteratively</strong>.</p> <p data-svelte-h="svelte-2zcn5x">By understanding and applying these principles, you can design agents that not only reason about their tasks but also <strong>effectively utilize external tools to complete them</strong>, all while continuously refining their output based on environmental feedback.</p> <hr> <p data-svelte-h="svelte-7kcpcc">Let’s now dive deeper into the Thought, Action, Observation as the individual steps of the process.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/agents-course/blob/main/units/en/unit1/agent-steps-and-structure.mdx" target="_blank"><span data-svelte-h="svelte-1kd6by1">&lt;</span> <span data-svelte-h="svelte-x0xyl0">&gt;</span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_17hovx6 = {
assets: "/docs/agents-course/pr_545/en",
base: "/docs/agents-course/pr_545/en",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/agents-course/pr_545/en/_app/immutable/entry/start.1596c81c.js"),
import("/docs/agents-course/pr_545/en/_app/immutable/entry/app.856a784e.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 22],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
25.2 kB
·
Xet hash:
1f73c4448c90e8635b04d3ecf9634c439565b4fd14ab69fd0e33158c236967ab

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.