[{"data":1,"prerenderedAt":145},["ShallowReactive",2],{"term-a\u002Fagent-loop":3,"related-a\u002Fagent-loop":132},{"id":4,"title":5,"acronym":6,"body":7,"category":113,"description":114,"difficulty":115,"extension":116,"letter":117,"meta":118,"navigation":119,"path":120,"related":121,"seo":126,"sitemap":127,"stem":130,"subcategory":6,"__hash__":131},"terms\u002Fterms\u002Fa\u002Fagent-loop.md","Agent Loop",null,{"type":8,"value":9,"toc":107},"minimark",[10,15,19,23,26,30,96,100,103],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 - The Vibe Check",[16,17,18],"p",{},"The agent loop is the heartbeat of any AI coding agent: think, act, look, repeat. It's less a single clever answer and more a Roomba that keeps bumping into a wall, checking its sensors, and adjusting course until the room is actually clean. The loop is what turns a chatbot into something that can finish a whole task unsupervised.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"The agent loop is the control cycle an LLM agent runs: read the current context and tool results, decide on the next action (call a tool or produce a final answer), execute it, observe the outcome, and repeat until a stop condition is met (task complete, error, or turn limit). Every agent harness, from Claude Code to a hand-rolled script, is built around some variant of this loop.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","while not task_done:\n    response = llm.generate(messages, tools=available_tools)\n    if response.tool_calls:\n        for call in response.tool_calls:\n            result = execute_tool(call)\n            messages.append(tool_result(call, result))\n    else:\n        task_done = True\n        final_answer = response.content\n","python","",[38,39,40,48,54,60,66,72,78,84,90],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,47],{},"while not task_done:\n",[41,49,51],{"class":43,"line":50},2,[41,52,53],{},"    response = llm.generate(messages, tools=available_tools)\n",[41,55,57],{"class":43,"line":56},3,[41,58,59],{},"    if response.tool_calls:\n",[41,61,63],{"class":43,"line":62},4,[41,64,65],{},"        for call in response.tool_calls:\n",[41,67,69],{"class":43,"line":68},5,[41,70,71],{},"            result = execute_tool(call)\n",[41,73,75],{"class":43,"line":74},6,[41,76,77],{},"            messages.append(tool_result(call, result))\n",[41,79,81],{"class":43,"line":80},7,[41,82,83],{},"    else:\n",[41,85,87],{"class":43,"line":86},8,[41,88,89],{},"        task_done = True\n",[41,91,93],{"class":43,"line":92},9,[41,94,95],{},"        final_answer = response.content\n",[11,97,99],{"id":98},"when-youll-hear-this","When You'll Hear This",[16,101,102],{},"\"The agent looped for 40 turns before it finally got the tests passing.\" \u002F \"Don't hand-roll your own agent loop, use the SDK's.\"",[104,105,106],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":50,"depth":50,"links":108},[109,110,111,112],{"id":13,"depth":50,"text":14},{"id":21,"depth":50,"text":22},{"id":28,"depth":50,"text":29},{"id":98,"depth":50,"text":99},"ai","The agent loop is the heartbeat of any AI coding agent: think, act, look, repeat.","intermediate","md","a",{},true,"\u002Fterms\u002Fa\u002Fagent-loop",[122,123,124,125],"AI Agent","Tool Use","Function Calling","Agentic Workflow",{"title":5,"description":114},{"changefreq":128,"priority":129},"weekly",0.7,"terms\u002Fa\u002Fagent-loop","jlCqzYY82xofV0tadSsP2yFmQ8HUWr6ZAadt4Rvarck",[133,136,139,142],{"title":125,"path":134,"acronym":6,"category":113,"difficulty":115,"description":135},"\u002Fterms\u002Fa\u002Fagentic-workflow","An agentic workflow is when you give an AI a goal and let it figure out the steps to get there — breaking down tasks, using tools, making decisions, and it...",{"title":122,"path":137,"acronym":6,"category":113,"difficulty":115,"description":138},"\u002Fterms\u002Fa\u002Fai-agent","An AI Agent is an AI system that can think, plan, and act on its own to accomplish a goal.",{"title":124,"path":140,"acronym":6,"category":113,"difficulty":115,"description":141},"\u002Fterms\u002Ff\u002Ffunction-calling","Function Calling is the OpenAI term for what Anthropic calls Tool Use — teaching the AI to call your code functions.",{"title":123,"path":143,"acronym":6,"category":113,"difficulty":115,"description":144},"\u002Fterms\u002Ft\u002Ftool-use","Tool use is when an AI can call external functions, APIs, or programs to do things it can't do alone.",1792528059488]