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

Topic 04 · AI agentsটপিক 04 · AI agents

The LLM Decides

After the context is built, the model reads it and makes one choice: answer now, or ask for a tool. The model only asks. Your code runs the tool. This page explains how the model shows its choice, which settings steer it, and why the same input can give a different choice the next time.

7 min read7 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 6 sources6টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Same question, 50 runsএকই প্রশ্ন, 50 বার চালানো

See tool_choice and stop_reason change what the model does, and why one run is never enough.দেখুন tool_choice আর stop_reason কীভাবে model-এর কাজ বদলায়, আর কেন একটা run কখনোই যথেষ্ট নয়।

2 min2 মিনিট8 steps8টি ধাপ
  • stop_reasonstop_reason (কারণ)—
  • tool_choicetool_choice (বাছাই)auto
staging login up?staging login চালু?testerটেস্টারModelমডেলtool_choice: autotool_choice: autohttp_gethttp_gettool: http_gettool: http_getstop_reason →stop_reason →tool_usetool_useend_turnend_turnmax_tokensmax_tokensrefusalrefusal

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

  • What stop_reason tells your codestop_reason আপনার কোডকে কী বলে
  • Why the model only asks, your code runs the toolকেন model শুধু চায়, tool চালায় আপনার কোড
  • Why a tester sets a pass rate over many runsকেন টেস্টার অনেক run-এ pass rate ঠিক করে
  • How the system prompt steers a guesssystem prompt কীভাবে অনুমান বদলায়
  • What tool_choice does, and the 400 errortool_choice কী করে, আর 400 error

In plain words

With tools, Claude decides when to call a tool. It bases the choice on the user's request and on the tool's description Source 1সোর্স 1. With the default tool_choice of auto, Claude decides on each turn whether to call a tool or to respond directly. Claude picks a tool when the request matches what that tool is described to do, and the answer is not in the context yet Source 1সোর্স 1.

In the Agent SDK loop, Claude can respond with text, ask for one or more tool calls, or both Source 6সোর্স 6. The model does not run the tool. For a client tool, Claude returns stop_reason: "tool_use" with at least one tool_use block. Your code runs the tool and returns its output in a tool_result block Source 1সোর্স 1.

The loop goes on until Claude gives a response with no tool calls Source 6সোর্স 6. So each decision is also a vote on whether the loop ends.

For what goes into the context before the choice, see Build Context. For what happens after it, see Act with Tools. For the tool side of this step, see Tool calling. For the whole cycle, see Agentic loops.

সহজ English

When tools are available, Claude decides when to use one. It looks at what the user asked and at the description of each tool Source 1সোর্স 1. By default (tool_choice set to auto), Claude decides on each turn: use a tool, or just answer. It uses a tool when the request matches what the tool does and the answer is not already in the context Source 1সোর্স 1.

In the Agent SDK loop, Claude can answer with text, ask for one or more tool calls, or both Source 6সোর্স 6. The model does not run the tool itself. It sends back stop_reason: "tool_use" and one or more tool_use blocks. Your code runs the tool and sends back a tool_result Source 1সোর্স 1.

The loop goes on until Claude answers with no tool calls Source 6সোর্স 6. So each choice also decides whether the loop ends.

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

Tool থাকলে Claude নিজেই ঠিক করে কখন একটা tool ব্যবহার করবে। সে দেখে user কী চেয়েছে আর প্রতিটা tool-এর description কী বলে Source 1সোর্স 1। ডিফল্টভাবে (tool_choice হলো auto) Claude প্রতিটা turn-এ ঠিক করে: tool ব্যবহার করবে, নাকি সরাসরি উত্তর দেবে। Request যখন কোনো tool-এর কাজের সঙ্গে মেলে আর উত্তরটা আগে থেকে context-এ নেই, তখন সে tool ব্যবহার করে Source 1সোর্স 1।

Agent SDK loop-এ Claude text দিয়ে উত্তর দিতে পারে, এক বা একাধিক tool call চাইতে পারে, বা দুটোই Source 6সোর্স 6। Model নিজে tool চালায় না। সে stop_reason: "tool_use" আর এক বা একাধিক tool_use block ফেরত দেয়। আপনার কোড tool চালায় আর একটা tool_result ফেরত পাঠায় Source 1সোর্স 1।

Claude যতক্ষণ না কোনো tool call ছাড়া উত্তর দেয়, loop চলতে থাকে Source 6সোর্স 6। তাই প্রতিটা সিদ্ধান্ত এটাও ঠিক করে যে loop শেষ হবে কি না।

How it works

What a decision looks like. One response can hold text and a tool call. Claude often says what it is doing before it calls a tool Source 2সোর্স 2. The thinking block appears when thinking is on. On many current models, such as Claude Opus 5.5, thinking is on by default Source 4সোর্স 4.

{
  "stop_reason": "tool_use",
  "content": [
    { "type": "thinking", "thinking": "", "signature": "..." },
    { "type": "text", "text": "I'll check the login endpoint." },
    { "type": "tool_use", "id": "toolu_...", "name": "http_get",
      "input": { "url": "https://staging.example.com/health" } }
  ]
}

The stop reason. stop_reason is part of every successful response. It is not an error. It tells you why Claude stopped writing Source 3সোর্স 3:

stop_reasonWhen it occurs
end_turnClaude finished its response.
tool_useClaude is calling a tool. Run it and return the result.
max_tokensThe response reached your max_tokens limit.
stop_sequenceClaude wrote one of your stop sequences.
pause_turnA server-tool loop reached its iteration limit.
refusalClaude declined to respond.
model_context_window_exceededThe response filled the context window.

সহজ English

What a choice looks like. One response can have text and a tool call. Claude often says what it will do before it calls a tool Source 2সোর্স 2. A thinking block shows up when thinking is on. On many current models, such as Claude Opus 5.5, thinking is on by default Source 4সোর্স 4.

The stop reason. Every successful response has a stop_reason. It is not an error. It tells you why Claude stopped writing Source 3সোর্স 3:

  • end_turn: Claude finished.
  • tool_use: Claude wants a tool. Run it and send back the result.
  • max_tokens: the answer hit your max_tokens limit.
  • stop_sequence: Claude wrote one of your stop words.
  • pause_turn: a server-tool loop hit its limit.
  • refusal: Claude said no.
  • model_context_window_exceeded: the answer filled the context window.

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

একটা সিদ্ধান্ত দেখতে কেমন। একটা response-এ text আর একটা tool call দুটোই থাকতে পারে। Tool call করার আগে Claude প্রায়ই বলে সে কী করবে Source 2সোর্স 2। Thinking চালু থাকলে একটা thinking block আসে। Claude Opus 5.5-এর মতো অনেক বর্তমান model-এ thinking ডিফল্টভাবেই চালু থাকে Source 4সোর্স 4।

Stop reason। প্রতিটা সফল response-এ একটা stop_reason থাকে। এটা error নয়। এটা বলে Claude কেন লেখা থামিয়েছে Source 3সোর্স 3:

  • end_turn: Claude শেষ করেছে।
  • tool_use: Claude একটা tool চায়। Tool চালান আর result ফেরত পাঠান।
  • max_tokens: উত্তর আপনার max_tokens সীমায় পৌঁছেছে।
  • stop_sequence: Claude আপনার দেওয়া একটা stop sequence লিখেছে।
  • pause_turn: একটা server-tool loop তার সীমায় পৌঁছেছে।
  • refusal: Claude উত্তর দিতে রাজি হয়নি।
  • model_context_window_exceeded: উত্তর context window ভরে ফেলেছে।

Steering the Tool Choice

Steering the choice with tool_choice Source 2সোর্স 2:

  • auto: Claude decides whether to call a tool. The default when you give tools.
  • any: Claude must use one of the tools, but it picks which one.
  • tool: Claude must use the named tool.
  • none: Claude must not use tools. The default when you give no tools.

With any or tool, the API makes the response start with the tool call, so Claude writes no text before the tool_use block. A forced tool call also skips thinking Source 2সোর্স 2. Claude Fable 5.2, Claude Mythos 5.2, Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1, and Claude Mythos 5.1 do not accept any or tool. They return a 400 error Source 2সোর্স 2. You can also steer the choice with the system prompt Source 1সোর্স 1.

Thinking before the choice. With thinking on, Claude works through the problem first. The thinking comes in thinking blocks before the response Source 4সোর্স 4. Adaptive thinking lets Claude decide when and how deeply to think Source 4সোর্স 4. With interleaved thinking, Claude also thinks between tool calls. It reasons about each tool result Source 4সোর্স 4. The text in a thinking block is a summary, never the raw chain of thought. With display: "omitted", the default on many models, the field is empty Source 4সোর্স 4. Thinking tokens are billed as output tokens and count toward max_tokens Source 4সোর্স 4. In the Agent SDK, the effort option sets how much reasoning Claude applies Source 6সোর্স 6.

Why the choice can change. Temperature controls the randomness of the output. Even at temperature 0, the results are not fully deterministic Source 5সোর্স 5. Identical inputs can give different outputs Source 5সোর্স 5.

সহজ English

Steering with tool_choice Source 2সোর্স 2:

  • auto: Claude decides. This is the default when you give tools.
  • any: Claude must use a tool, but it picks which one.
  • tool: Claude must use the tool you name.
  • none: Claude must not use tools. This is the default when you give no tools.

With any or tool, Claude writes no text before the tool call, and it skips thinking Source 2সোর্স 2. Some new models, such as Claude Opus 5.5 and Claude Sonnet 5.5, do not accept any or tool. They return a 400 error Source 2সোর্স 2. The system prompt can also steer the choice Source 1সোর্স 1.

Thinking first. With thinking on, Claude works through the problem before it answers. The thinking comes in thinking blocks before the answer Source 4সোর্স 4. With adaptive thinking, Claude decides when and how much to think. With interleaved thinking, it also thinks between tool calls about each tool result Source 4সোর্স 4. What you see in a thinking block is a summary, not the raw reasoning. On many models, the field is empty by default Source 4সোর্স 4. Thinking tokens cost the same as output tokens and count toward max_tokens Source 4সোর্স 4. In the Agent SDK, effort sets how much Claude reasons Source 6সোর্স 6.

Why the choice can change. Temperature controls how random the output is. Even at 0, the output is not fully fixed. The same input can give a different output Source 5সোর্স 5.

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

tool_choice দিয়ে নিয়ন্ত্রণ Source 2সোর্স 2:

  • auto: Claude নিজে ঠিক করে। Tool দিলে এটাই ডিফল্ট।
  • any: Claude-কে একটা tool ব্যবহার করতেই হবে, তবে কোনটা, সেটা সে বাছে।
  • tool: আপনি যে tool-এর নাম দেন, Claude-কে সেটাই ব্যবহার করতে হবে।
  • none: Claude কোনো tool ব্যবহার করবে না। Tool না দিলে এটাই ডিফল্ট।

any বা tool দিলে Claude tool call-এর আগে কোনো text লেখে না, আর thinking বাদ দেয় Source 2সোর্স 2। কিছু নতুন model, যেমন Claude Opus 5.5 আর Claude Sonnet 5.5, any বা tool নেয় না। তারা একটা 400 error দেয় Source 2সোর্স 2। System prompt দিয়েও সিদ্ধান্তকে প্রভাবিত করা যায় Source 1সোর্স 1।

আগে চিন্তা। Thinking চালু থাকলে Claude উত্তর দেওয়ার আগে সমস্যাটা নিয়ে কাজ করে। Thinking আসে উত্তরের আগে thinking block-এ Source 4সোর্স 4। Adaptive thinking-এ Claude ঠিক করে কখন আর কতটা চিন্তা করবে। Interleaved thinking-এ সে দুটো tool call-এর মাঝেও প্রতিটা tool result নিয়ে চিন্তা করে Source 4সোর্স 4। Thinking block-এ আপনি যা দেখেন, সেটা একটা সারাংশ, আসল চিন্তার ধারা নয়। অনেক model-এ ডিফল্টভাবে field-টা খালি থাকে Source 4সোর্স 4। Thinking token-এর দাম output token-এর মতো, আর এগুলো max_tokens-এর মধ্যে গোনা হয় Source 4সোর্স 4। Agent SDK-তে effort ঠিক করে Claude কতটা চিন্তা করবে Source 6সোর্স 6।

সিদ্ধান্ত কেন বদলাতে পারে। Temperature ঠিক করে output কতটা এলোমেলো হবে। Temperature 0 হলেও output পুরোপুরি নির্দিষ্ট নয়। একই input ভিন্ন output দিতে পারে Source 5সোর্স 5।

A real-life example

This example is invented. A QA team builds a small agent with one tool, http_get. The prompt is: "Is the login service on staging up?"

call 1  context: prompt + http_get definition
        -> text + tool_use(http_get, /health)   stop_reason: tool_use
        your code runs the request -> tool_result: 200 OK
call 2  context: + tool_use + tool_result
        -> "Yes, the login service is up."      stop_reason: end_turn

Call 1 ends with tool_use, so the code runs the tool and sends the result Source 1সোর্স 1. Call 2 has no tool call, so the loop ends Source 6সোর্স 6.

The team then runs the same prompt 50 times. Most runs look like the trace above, but not all of them. Identical inputs can give different outputs, even at temperature 0 Source 5সোর্স 5. In another test, the prompt says only "Is login up?" with no environment. When a required parameter is missing, Claude may ask for it, or it may guess a value Source 1সোর্স 1. Here it guesses a production URL. The team adds "Ask for the environment if it is not given" to the system prompt, because the system prompt steers when Claude calls a tool Source 1সোর্স 1.

সহজ English

This example is invented. A QA team builds a small agent with one tool, http_get. The question is: "Is the login service on staging up?"

In call 1, Claude says what it will do and asks for http_get on the health page. The stop reason is tool_use. The team's code runs the request and sends back "200 OK" Source 1সোর্স 1. In call 2, Claude answers "Yes, the login service is up." with no tool call. So the loop ends Source 6সোর্স 6.

Then the team runs the same question 50 times. Most runs look the same, but not all. The same input can give a different output, even at temperature 0 Source 5সোর্স 5. In another test, the question is only "Is login up?", with no environment. When a needed value is missing, Claude may ask for it, or it may guess Source 1সোর্স 1. Here it guesses a production URL. The team adds "Ask for the environment if it is not given" to the system prompt. The system prompt can steer when Claude uses a tool Source 1সোর্স 1.

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

এই উদাহরণটা বানানো। একটা QA টিম একটা ছোট agent বানায়, যার একটাই tool: http_get। প্রশ্ন হলো: "staging-এ login service চালু আছে কি?"

Call 1-এ Claude বলে সে কী করবে, আর health page-এর জন্য http_get চায়। Stop reason হলো tool_use। টিমের কোড request চালায় আর "200 OK" ফেরত পাঠায় Source 1সোর্স 1। Call 2-এ Claude কোনো tool call ছাড়া উত্তর দেয়: "হ্যাঁ, login service চালু আছে।" তাই loop শেষ হয় Source 6সোর্স 6।

তারপর টিম একই প্রশ্ন 50 বার চালায়। বেশিরভাগ run একই রকম, কিন্তু সব নয়। Temperature 0 হলেও একই input ভিন্ন output দিতে পারে Source 5সোর্স 5। আরেকটা টেস্টে প্রশ্ন শুধু "login চালু আছে?", কোনো environment ছাড়া। দরকারি কোনো value না থাকলে Claude সেটা জিজ্ঞেস করতে পারে, বা অনুমান করতে পারে Source 1সোর্স 1। এখানে সে একটা production URL অনুমান করে। টিম system prompt-এ যোগ করে: "environment না দিলে জিজ্ঞেস করো।" Claude কখন tool ব্যবহার করবে, system prompt সেটা প্রভাবিত করতে পারে Source 1সোর্স 1।

Common mistakes

  • Not checking stop_reason. Anthropic advises you to check it in your response handling every time Source 3সোর্স 3. Code that reads only the text misses a tool call, a refusal, or a cut-off answer.
  • A cut-off tool call. If max_tokens cuts a response inside a tool_use block, the call is incomplete. Retry with a higher max_tokens Source 3সোর্স 3.
  • Parsing the text around a tool call. Claude can phrase that text in many ways. Treat it like any other model text and do not rely on a fixed format Source 2সোর্স 2.
  • Expecting the same output every time. Temperature 0 does not make the output fully deterministic Source 5সোর্স 5.
  • Forcing a tool on a model that rejects it. any and tool return a 400 error on some current models Source 2সোর্স 2. And a forced call has no text and no thinking before it Source 2সোর্স 2.
  • Reading thinking as the real reasoning. A thinking block holds a summary, never the raw chain of thought, and it can be empty Source 4সোর্স 4.
  • A vague prompt with a required value missing. Claude may guess the value and call the tool with it Source 1সোর্স 1.

সহজ English

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

  • stop_reason যাচাই না করা। Anthropic বলে, প্রতিবার response সামলানোর সময় এটা যাচাই করুন Source 3সোর্স 3। যে কোড শুধু text পড়ে, সে tool call, refusal বা কেটে যাওয়া উত্তর ধরতে পারে না।
  • কেটে যাওয়া tool call। max_tokens যদি tool_use block-এর মাঝখানে উত্তর কেটে দেয়, call-টা অসম্পূর্ণ থাকে। বড় max_tokens দিয়ে আবার চেষ্টা করুন Source 3সোর্স 3।
  • Tool call-এর আশেপাশের text-কে data হিসেবে পড়া। Claude এটা নানা ভাবে লিখতে পারে। নির্দিষ্ট format আশা করবেন না Source 2সোর্স 2।
  • প্রতিবার একই উত্তর আশা করা। Temperature 0 হলেও output পুরোপুরি নির্দিষ্ট নয় Source 5সোর্স 5।
  • যে model মানে না, তাতে tool জোর করা। কিছু বর্তমান model-এ any আর tool একটা 400 error দেয় Source 2সোর্স 2। তাছাড়া জোর করা call-এর আগে কোনো text বা thinking থাকে না Source 2সোর্স 2।
  • Thinking-কে আসল চিন্তা ভাবা। Thinking block শুধু একটা সারাংশ, আর এটা খালিও থাকতে পারে Source 4সোর্স 4।
  • দরকারি value ছাড়া অস্পষ্ট prompt। Claude value-টা অনুমান করে tool call-এ ব্যবহার করতে পারে Source 1সোর্স 1।

What a tester can check

Tutorial advice

This list is the tutorial's own advice, not a fact from a source.

  • Run each case many times. Send the same input 20 to 50 times. Record how often the agent calls each tool. Set a pass rate, not a single expected output.
  • Test every stop reason. Make the app meet tool_use, end_turn, max_tokens, and refusal. Each one needs its own path in the code.
  • Assert on the tool call, not the words. Check the tool name and the input fields of the tool_use block. Do not assert on the exact text before it.
  • Remove a required value. Leave out a value that a tool needs. The agent must ask for it, not guess it.
  • Check "answer from context". Put the answer in the context. The agent should answer directly and not call a tool again.
  • Check tool_choice settings. With none, the agent must not call a tool. On a model that rejects forced tools, the app must handle the 400 error.
  • Compare the answer with the tool result. The final text must agree with what the tool returned, for example "up" only after a 200 response.

সহজ English

Tutorial advice

This list is the tutorial's own advice, not a fact from a source.

  • Run each case many times. Send the same input 20 to 50 times. Count how often the agent uses each tool. Set a pass rate, not one exact expected answer.
  • Test every stop reason. Make the app get tool_use, end_turn, max_tokens, and refusal. Each one needs its own path in the code.
  • Check the tool call, not the words. Check the tool name and the input values. Do not check the exact text before the call.
  • Leave out a needed value. Remove a value that a tool needs. The agent must ask for it, not guess.
  • Check "answer from context". Put the answer in the context already. The agent should just answer, without calling a tool again.
  • Check the tool_choice settings. With none, the agent must not call a tool. On a model that does not allow forced tools, the app must handle the 400 error.
  • Compare the answer with the tool result. The final answer must match what the tool returned. For example, "up" only after a 200 response.

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

Tutorial advice

এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, কোনো source থেকে নেওয়া তথ্য নয়।

  • প্রতিটা case অনেকবার চালান। একই input 20 থেকে 50 বার পাঠান। Agent কোন tool কতবার ব্যবহার করে, গুনে রাখুন। একটা নির্দিষ্ট উত্তরের বদলে একটা pass rate ঠিক করুন।
  • প্রতিটা stop reason টেস্ট করুন। App যেন tool_use, end_turn, max_tokens আর refusal পায়, এমন case বানান। প্রতিটার জন্য কোডে আলাদা পথ লাগে।
  • শব্দ নয়, tool call যাচাই করুন। Tool-এর নাম আর input value যাচাই করুন। Call-এর আগের হুবহু text যাচাই করবেন না।
  • দরকারি value বাদ দিন। Tool-এর দরকারি একটা value সরিয়ে দিন। Agent-কে সেটা জিজ্ঞেস করতে হবে, অনুমান নয়।
  • "Context থেকে উত্তর" যাচাই করুন। উত্তরটা আগে থেকেই context-এ রাখুন। Agent-এর উচিত সরাসরি উত্তর দেওয়া, আবার tool call না করা।
  • tool_choice setting যাচাই করুন। none দিলে agent কোনো tool call করবে না। যে model জোর করা tool মানে না, সেখানে app-কে 400 error সামলাতে হবে।
  • উত্তরকে tool result-এর সঙ্গে মেলান। চূড়ান্ত উত্তর tool-এর ফেরত দেওয়া result-এর সঙ্গে মিলতে হবে। যেমন, "চালু আছে" শুধু 200 response-এর পরে।

Key words

TermMeaning
Tool callA tool_use block in which the model asks your code to run a tool with given inputs.
tool_resultThe block your code sends back with the output of a tool.
stop_reasonThe field that says why the model stopped writing, for example end_turn or tool_use.
tool_choiceThe setting that allows, forces, or blocks tool use: auto, any, tool, none.
Forced tool usetool_choice set to any or tool. The model must call a tool.
ThinkingReasoning that the model does before or between its outputs, returned in thinking blocks.
Adaptive thinkingThinking in which the model decides when and how much to think.
Interleaved thinkingThinking between tool calls, about each tool result.
TemperatureA setting for the randomness of the output.
Non-determinismThe same input can give a different output, even at temperature 0.

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]
    Tool use with Claude

    Anthropic (Claude Platform docs) · accessed 2026-10-28দেখা হয়েছে: 2026-10-28

  2. [2]
    Define tools

    Anthropic (Claude Platform docs) · accessed 2026-10-28দেখা হয়েছে: 2026-10-28

  3. [3]
    Stop reasons and fallback

    Anthropic (Claude Platform docs) · accessed 2026-10-28দেখা হয়েছে: 2026-10-28

  4. [4]
    Thinking

    Anthropic (Claude Platform docs) · accessed 2026-10-28দেখা হয়েছে: 2026-10-28

  5. [5]
    Glossary

    Anthropic (Claude Platform docs) · accessed 2026-10-28দেখা হয়েছে: 2026-10-28

  6. [6]
    How the agent loop works

    Anthropic (Claude Code docs, Agent SDK) · accessed 2026-10-28দেখা হয়েছে: 2026-10-28