Skip to contentমূল লেখায় যান

Topic 01 · AI harnessesটপিক 01 · AI harnesses

Agent Loop

The harness runs the loop: it calls the model, runs the tools that the model asks for, and gives the results back. The loop stops when the model gives an answer with no tool call, when a limit is reached, or when a person interrupts it.

4 min read4 মিনিটে পড়া যায় · 5 sections5টি সেকশন · 2 sources2টি সোর্স · updated Nov 2026আপডেট: Nov 2026

The agent loop, turn by turnএজেন্ট লুপ, টার্নে টার্নে

Watch the model ask for tools and the harness run them. Then move max_turns and see the loop end with an answer or with an error.মডেলকে টুল চাইতে আর harness-কে তা চালাতে দেখুন। তারপর max_turns সরান আর দেখুন লুপ উত্তর দিয়ে শেষ হয় নাকি এরর দিয়ে।

2 min2 মিনিট8 steps8টি ধাপ
  • Turns usedটার্ন ব্যবহার0 / 3
  • max_turnsসর্বোচ্চ টার্ন3
  • Resultফলাফল…
requestঅনুরোধuserব্যবহারকারীModelমডেলturn 0 / 3টার্ন 0 / 3reads requestঅনুরোধ পড়েHarnessHarnessturns →টার্ন →123–––––limit · 3সীমা · 3number: tool turn ✓ final reply – past the limitসংখ্যা: টুল টার্ন ✓ শেষ উত্তর – সীমার পরে

You’ll learnআপনি শিখবেন

  • What a harness does around the modelমডেলের চারপাশে harness কী করে
  • How the loop runs: call, tool, resultলুপ কীভাবে চলে: কল, টুল, ফলাফল
  • How max_turns counts the final replymax_turns কীভাবে শেষ উত্তরকে গোনে
  • Why you check the subtype firstকেন আগে subtype দেখতে হয়
  • How a person stops the loopমানুষ কীভাবে লুপ থামায়

What a harness is

A model alone can only read text and write text. To change a file or run a command, it needs software around it. The Claude Code docs call this software the agentic harness: the layer around the model that provides the tools and manages the context that the model sees Source 1সোর্স 1.

The docs say it this way: without tools, Claude can only respond with text, and with tools, Claude can act Source 1সোর্স 1. So the harness decides what tools the model has and what context it sees Source 1সোর্স 1. In the Agent SDK, you also control whether each tool call is allowed to run Source 2সোর্স 2.

The six topics of this module are the parts of a harness. This page is the first part: the loop that connects them.

সহজ English

A model alone can only read text and write text. It cannot open a file or run a command by itself. The harness is the software around the model that gives it tools and controls what it sees Source 1সোর্স 1.

Without tools, the model can only answer with text. With tools, it can act Source 1সোর্স 1. The harness decides which tools the model gets and what it sees Source 1সোর্স 1. In the Agent SDK, you also control whether each tool call is allowed to run Source 2সোর্স 2.

This module has six topics. Each topic is one part of a harness. This page is about the loop that connects all the parts.

বাংলা ব্যাখ্যা

একটা মডেল একা শুধু টেক্সট পড়তে আর লিখতে পারে। নিজে থেকে ফাইল খুলতে বা কমান্ড চালাতে পারে না। মডেলের চারপাশের যে সফটওয়্যার তাকে টুল দেয় আর সে কী দেখবে তা নিয়ন্ত্রণ করে, সেটাই harness Source 1সোর্স 1।

টুল ছাড়া মডেল শুধু টেক্সটে উত্তর দিতে পারে। টুল থাকলে সে কাজ করতে পারে Source 1সোর্স 1। মডেল কোন টুল পাবে আর কী দেখবে, তা harness ঠিক করে Source 1সোর্স 1। Agent SDK-তে প্রতিটা টুল কল চলতে পারবে কি না, তাও আপনি নিয়ন্ত্রণ করেন Source 2সোর্স 2।

এই মডিউলে ছয়টা টপিক আছে। প্রতিটা টপিক harness-এর একটা অংশ। এই পেজটা সেই লুপ নিয়ে, যেটা সব অংশকে জোড়া লাগায়।

How the loop works

The Claude Agent SDK runs the same loop that powers Claude Code. Claude evaluates the prompt, calls tools to take action, receives the results, and repeats until the task is complete Source 2সোর্স 2.

            ┌──────────────┐
Request ──► │    Model     │ ── tool call ──► Harness runs the tool
            └──────────────┘                         │
               ▲      │                              │
               │      └─ no tool call ──► Final answer
               └──────── tool result ◄───────────────┘

Each set of tool results feeds back to Claude for the next decision Source 2সোর্স 2. The turns continue until Claude produces output with no tool calls. Then the loop ends and the harness delivers the final result Source 2সোর্স 2.

In Claude Code, the work goes through three phases: gather context, take action, and verify results. The docs say that these phases blend together Source 1সোর্স 1.

সহজ English

The loop has a small number of steps, and they repeat Source 2সোর্স 2:

  1. The model reads the request.
  2. The model asks for a tool, for example "read this file".
  3. The harness runs the tool and gives the result back to the model.
  4. The model uses the result to decide the next step.

When the model answers with no tool request, the loop stops. The harness then gives the final answer to the user Source 2সোর্স 2.

Claude Code describes the work as three phases: gather context, take action, and verify results. The phases mix together while Claude works Source 1সোর্স 1.

বাংলা ব্যাখ্যা

লুপে অল্প কয়েকটা ধাপ আছে, আর ধাপগুলো বারবার ঘোরে Source 2সোর্স 2:

  1. মডেল রিকোয়েস্টটা পড়ে।
  2. মডেল একটা টুল চায়, যেমন "এই ফাইলটা পড়ো"।
  3. harness টুলটা চালায় আর ফলাফলটা মডেলকে ফেরত দেয়।
  4. মডেল সেই ফলাফল দেখে পরের ধাপ ঠিক করে।

মডেল যখন কোনো টুল না চেয়ে উত্তর দেয়, তখন লুপ থামে। তারপর harness ইউজারকে ফাইনাল উত্তর দেয় Source 2সোর্স 2।

Claude Code কাজটাকে তিনটা ধাপে ভাগ করে: কনটেক্সট জোগাড় করা, কাজ করা, আর ফলাফল যাচাই করা। কাজের সময় ধাপগুলো একটার সাথে আরেকটা মিশে যায় Source 1সোর্স 1।

How the loop stops

A loop with no limit can run for a long time and cost a lot. The Agent SDK has two limits Source 2সোর্স 2:

Option (Python / TypeScript)What it limits
max_turns / maxTurnsThe number of turns (each turn with tool calls, plus one for the final text-only reply)
max_budget_usd / maxBudgetUsdThe estimated spend at which the loop stops

If the loop hits a limit, the SDK returns a ResultMessage with the error subtype error_max_turns or error_max_budget_usd Source 2সোর্স 2. The ResultMessage marks the end of the loop. It has the final text, the token usage, the cost, and the session ID Source 2সোর্স 2. The result field is only on the success variant, so check the subtype before you read it Source 2সোর্স 2.

A person can also stop the loop. In Claude Code, Esc stops Claude at once: the running tool call is canceled and Claude waits for the next instruction Source 1সোর্স 1. You can also interrupt to give more context or to ask for a different approach Source 1সোর্স 1.

সহজ English

A loop without a limit can run for a long time and cost a lot of money. So the Agent SDK lets you set two limits: a maximum number of turns, and a maximum budget Source 2সোর্স 2.

If the loop reaches a limit, the SDK stops it and reports an error type that tells you which limit it was Source 2সোর্স 2. The last message of the loop has the final text, the token use, the cost, and the session ID Source 2সোর্স 2. The final text is only there when the run succeeded, so check the type first Source 2সোর্স 2.

A person can stop the loop too. In Claude Code, press Esc. Claude stops the running tool and waits for you Source 1সোর্স 1.

বাংলা ব্যাখ্যা

লিমিট ছাড়া একটা লুপ অনেকক্ষণ চলতে পারে আর অনেক খরচ করতে পারে। তাই Agent SDK-তে দুটো লিমিট দেওয়া যায়: সর্বোচ্চ কয়টা টার্ন (max_turns), আর সর্বোচ্চ কত বাজেট (max_budget_usd) Source 2সোর্স 2।

লুপ কোনো লিমিটে পৌঁছালে SDK থেমে যায় আর একটা error subtype দেয়: error_max_turns অথবা error_max_budget_usd Source 2সোর্স 2। শেষ মেসেজ ResultMessage-এ ফাইনাল টেক্সট, টোকেন ব্যবহার, খরচ আর session ID থাকে Source 2সোর্স 2। result ফিল্ড শুধু সফল রানে থাকে, তাই আগে subtype চেক করুন Source 2সোর্স 2।

মানুষও লুপ থামাতে পারে। Claude Code-এ Esc চাপলে Claude চলমান টুলটা বাতিল করে আপনার পরের নির্দেশের জন্য অপেক্ষা করে Source 1সোর্স 1।

What a tester can check

Tutorial advice

The loop is where an agent spends time and money. Test these cases:

  • Normal end: a simple task ends with a final answer and a success result.
  • Turn limit: set a low turn limit and give a long task. The run stops with the turn-limit error, not with a crash.
  • Budget limit: do the same with a low budget.
  • Interrupt: stop the agent in the middle of a tool call. Check that it waits and that no half-done action stays.
  • Endless loop: give a task that cannot succeed, such as a test that always fails. The agent must stop and ask, not try forever.

সহজ English

Tutorial advice

Try these cases when you test an agent:

  • A simple task ends with a final answer.
  • A low turn limit stops a long task with a clear error.
  • A low budget stops the run with a clear error.
  • If you stop the agent in the middle of a step, it waits and leaves nothing half done.
  • A task that cannot succeed does not make the agent try forever.

বাংলা ব্যাখ্যা

Tutorial advice

একটা এজেন্ট টেস্ট করার সময় এই কেসগুলো চেষ্টা করুন:

  • একটা সহজ কাজ ফাইনাল উত্তর দিয়ে শেষ হয়।
  • কম turn limit দিলে লম্বা কাজ একটা পরিষ্কার এরর দিয়ে থামে।
  • কম বাজেট দিলেও রান একটা পরিষ্কার এরর দিয়ে থামে।
  • মাঝপথে এজেন্টকে থামালে সে অপেক্ষা করে, কোনো কাজ অর্ধেক করা অবস্থায় রেখে যায় না।
  • যে কাজ কখনো সফল হবে না, তার জন্য এজেন্ট অনন্তকাল চেষ্টা করে না।

Key words

TermMeaning
HarnessThe software around the model. It gives tools, manages the context, and runs the loop.
Agent loopModel call, tool run, result back, repeated until the model gives an answer with no tool call
TurnOne round of the loop
max_turnsThe Agent SDK limit on the number of turns
max_budget_usdThe Agent SDK limit on the estimated spend
ResultMessageThe last message of an Agent SDK run, with the result, the usage, and the cost

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    How Claude Code works

    Claude Code documentation · accessed 2026-10-28দেখা হয়েছে: 2026-10-28

  2. [2]
    How the agent loop works

    Claude Agent SDK documentation · accessed 2026-10-28দেখা হয়েছে: 2026-10-28