{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreihbzlrdwkljukslr4kp67zoo6kc547aiwbib3afbhz4ud7h257qfy",
    "uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mope67hjhnb2"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreicga6h63kde7sxe2wmevb2awdridmc7qxslthcacyqyigdim4vgd4"
    },
    "mimeType": "image/webp",
    "size": 68344
  },
  "path": "/dev48v/ai-agents-explained-the-thought-action-observation-loop-3mgb",
  "publishedAt": "2026-06-20T07:07:51.000Z",
  "site": "https://dev.to",
  "tags": [
    "ai",
    "llm",
    "beginners",
    "machinelearning",
    "https://dev48v.infy.uk/ai/days/day11-agents.html",
    "Run a task"
  ],
  "textContent": "A chatbot answers in one shot. An AI agent runs in a loop, uses tools, and acts — Thought → Action → Observation → repeat — until the job's done. Watch one solve a multi-step task by calling a calculator and a search.\n\n🤖 **Run the agent:** https://dev48v.infy.uk/ai/days/day11-agents.html\n\n##  Agent = LLM + tools + a loop\n\nYou describe tools to the model (name, purpose, arguments). It can't divide big numbers reliably or know today's data — but it CAN decide \"call the calculator with this expression\". Tools cover the model's weak spots.\n\n##  The ReAct loop\n\n\n    while (true) {\n      const step = await llm(history);            // model emits a Thought + Action\n      if (step.type === \"answer\") return step.text;\n      const result = tools[step.tool](step.args); // run the tool\n      history += `Observation: ${result}`;         // feed the real result back\n    }\n\n\nThe model writes a **Thought** (plan), emits an **Action** (tool + args), your code runs it and returns an **Observation** , which goes back into context. Then it thinks again.\n\n##  Why it beats one-shot\n\nEach observation is REAL, fed back before the next decision — so it's not guessing the tip amount, it sees `126` from the calculator. And it plans the steps itself: \"population of France's capital, doubled\" becomes search → then calculator, chained because the model worked out the dependency.\n\n##  Power needs guardrails\n\nCap iterations (no infinite loops), validate tool inputs, gate risky actions (email, payments) behind approval. Autonomy is the point; limits make it safe.\n\nRun a task and watch the Thought→Action→Observation trace build.",
  "title": "AI Agents Explained: the Thought-Action-Observation Loop"
}