Agent Architecture: What You Are Testing
An agent is a decision tree with a model at each junction. Draw the tree first, and the tests write themselves.
8 min read8 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 3 sources3টি সোর্স · updated Nov 2026আপডেট: Nov 2026
The agent and its dangerous toolagent আর তার বিপজ্জনক tool
See five tools split into read-only and world-changing, then add an approval gate in front of send_email.পাঁচটা tool-কে শুধু-পড়ার আর পৃথিবী-বদলানোর ভাগে দেখুন, তারপর send_email-এর সামনে approval gate বসান।
You’ll learnআপনি শিখবেন
- What the agent carries as stateagent স্টেট হিসেবে কী বয়ে বেড়ায়✓
- Which tools only read and which change the worldকোন tool শুধু পড়ে আর কোনটা পৃথিবী বদলায়
- Why tool descriptions are test surfacetool-এর বর্ণনা কেন test surface
- How many tests a decision node needsএকটা সিদ্ধান্তের node-এ কতগুলো টেস্ট লাগে
- Why send_email needs approval and a not-called testsend_email-এর কেন approval আর না-কল টেস্ট দরকার
In plain words
An agent is not a model. It is a control loop around a model: the model is given a goal and a list of tools, it decides what to do, the system does it, and the model decides again. LangGraph calls this a graph, with nodes for the steps and edges for the transitions Source 1সোর্স 1.
The difference from a chain is that the path is decided at runtime. A chain has one path. An agent has a tree, and the model picks the branch each time.
Four things define the architecture, and each one is a separate thing to test:
- The tools. What the agent can do, and what each tool needs. The tool descriptions are part of the prompt, so their wording changes the agent's behaviour.
- The state. What the agent knows between steps: the goal, the messages, the facts it has collected.
- The decision points. The nodes where the model chooses, and what the choices are.
- The stopping condition. When the agent decides it is finished, and the limits that stop it if it never does.
The reason to draw this before testing is that it tells you where the bugs can live. A tool with the wrong arguments is a different bug from a model that picked the wrong tool, and the trace tells you which one happened Source 2সোর্স 2.
সহজ English
An agent is not just a model. It is a control loop built around a model. The model gets a goal and a list of tools. It decides what to do. The system does it. Then the model decides again.
LangGraph calls this a graph. The nodes are the steps. The edges are the moves from one step to the next Source 1সোর্স 1.
A chain is different. A chain has one path. An agent has a tree, and the model picks the branch each time. So the path is decided while it runs.
Four things define the architecture. Each one is a separate thing to test:
- The tools. What the agent can do, and what each tool needs. The tool descriptions are part of the prompt. Changing their wording changes how the agent behaves.
- The state. What the agent knows between steps. This is the goal, the messages, and the facts it has collected.
- The decision points. The nodes where the model makes a choice, and what the choices are.
- The stopping condition. When the agent decides it is done. Also the limits that stop it if it never decides.
Draw this before you test. It shows you where the bugs can live. A tool called with the wrong arguments is a different bug from a model that picked the wrong tool. The trace tells you which one happened Source 2সোর্স 2.
বাংলা ব্যাখ্যা
agent model নয়। এটা model-এর চারপাশে একটা control loop: model-কে একটা লক্ষ্য আর tool-এর তালিকা দেওয়া হয়, সে ঠিক করে কী করবে, সিস্টেম সেটা করে, আর model আবার ঠিক করে। LangGraph একে বলে graph — ধাপের জন্য node, সংযোগের জন্য edge Source 1সোর্স 1।
chain থেকে পার্থক্য হলো পথ runtime-এ ঠিক হয়। chain-এর একটাই পথ। agent-এ একটা tree, আর model প্রতিবার branch বাছে।
চারটা বিষয় architecture-কে ঠিক করে, আর প্রতিটাই আলাদা কিছু টেস্ট করার:
- Toolগুলো। agent কী করতে পারে, আর প্রতিটা tool-এর কী দরকার। tool-এর বর্ণনা prompt-এর অংশ, তাই তার ভাষা agent-এর আচরণ বদলে দেয়।
- State। ধাপগুলোর মাঝে agent কী জানে: লক্ষ্য, বার্তা, সংগ্রহ করা তথ্য।
- সিদ্ধান্তের জায়গা। যেসব node-এ model বাছে, আর সেই বাছাইগুলো কী।
- শেষ হওয়ার শর্ত। agent কখন ঠিক করে শেষ, আর সেটা না করলে কোন সীমা থামায়।
টেস্টের আগে এটা আঁকার কারণ এতে বোঝা যায় বাগ কোথায় থাকতে পারে। ভুল argument-এর tool আর ভুল tool বাছা model — দুটো আলাদা বাগ, আর trace বলে কোনটা ঘটেছে Source 2সোর্স 2।
How it works
The reference agent has five tools, and the test point for each is different:
search_web(query) returns text
query_database(sql) returns rows
calculate(expression) returns a number
send_email(to, body) changes the world
cancel_order(order_id) changes the worldThe dangerous tool. send_email is the dangerous one, and it is the reason agents need permissions. A tool that changes the world needs a test that asserts it was not called when it should not have been. It also needs a human approval step in production.
Tool descriptions. The tool descriptions are part of the prompt, and this surprises people. Rewriting "Searches the web" as "Searches the web for current information about a product or event" changes which queries the agent runs. The tool descriptions are therefore a test surface of their own Source 3সোর্স 3.
The state has three parts, and the tests differ:
the goal what the user asked for. Set once, rarely changes.
the messages the conversation, including every tool result.
the facts what the agent has extracted. The scratchpad.Decision points. The decision points are where the model acts. A node that decides between two tools needs a test for each branch, plus a test for the case where neither fits. A node that decides whether the task is complete needs a test for a task that is not complete yet. That is the case that produces the endless loop.
Stopping condition. The stopping condition needs two tests: one where the agent should stop, and one where it must not. The second is the loop test, and it is the one that finds the infinite loop.
The trace. The trace is what makes the architecture visible. A run trace records every run (model call, tool call) for one operation, with its inputs and outputs Source 2সোর্স 2. Read in order, it shows which path the agent took. This is how you tell an agent that took a wrong path from an agent that took the right path and then failed.
সহজ English
The reference agent has five tools. Each one needs a different test:
search_web(query) returns text
query_database(sql) returns rows
calculate(expression) returns a number
send_email(to, body) changes the world
cancel_order(order_id) changes the worldsend_email is the dangerous one. It is why agents need permissions. A tool that changes the world needs a test that checks it was not called when it should not be. In production, it also needs a human to approve it.
The tool descriptions are part of the prompt. This surprises people. Say you rewrite "Searches the web" as "Searches the web for current information about a product or event". That changes which queries the agent runs. So the tool descriptions are a test surface of their own Source 3সোর্স 3.
The state has three parts. Each needs different tests:
the goal what the user asked for. Set once, rarely changes.
the messages the conversation, including every tool result.
the facts what the agent has extracted. The scratchpad.The decision points are where the model acts. Say a node picks between two tools. Test each choice. Also test the case where neither tool fits. Say a node decides whether the task is done. Test a task that is not done yet. That case is what causes the endless loop.
The stopping condition needs two tests. In one, the agent should stop. In the other, it must not stop. The second is the loop test. It is the one that finds the infinite loop.
The trace makes the architecture visible. A run trace records every run (model call, tool call) for one operation, with its inputs and outputs Source 2সোর্স 2. Read in order, it shows which path the agent took. With it, you can tell two cases apart. One agent took a wrong path. Another took the right path and then failed.
বাংলা ব্যাখ্যা
reference agent-এর পাঁচটা tool, আর প্রতিটার টেস্ট পয়েন্ট আলাদা:
search_web(query) returns text
query_database(sql) returns rows
calculate(expression) returns a number
send_email(to, body) changes the world
cancel_order(order_id) changes the worldsend_email সবচেয়ে বিপজ্জনক, আর agent-এর permission দরকার হওয়ার কারণই এটা। যে tool পৃথিবী বদলে দেয়, তার একটা টেস্ট দরকার যে assert করে উচিত না হলে সেটা বলা হয়নি, আর production-এ একটা human approval ধাপ দরকার।
Tool-এর বর্ণনা prompt-এর অংশ, আর এটা মানুষকে অবাক করে। "Searches the web" কে "Searches the web for current information about a product or event" লিখলে বদলায় কোন query চলে। তাই tool-এর বর্ণনাও নিজে একটা test surface Source 3সোর্স 3।
State-এর তিনটা অংশ, আর টেস্ট আলাদা:
the goal what the user asked for. Set once, rarely changes.
the messages the conversation, including every tool result.
the facts what the agent has extracted. The scratchpad.সিদ্ধান্তের জায়গা যেখানে model কাজ করে। দুটো tool-এর মধ্যে বাছার একটা node-এর প্রতিটা branch-এর টেস্ট দরকার, আর এমন কেসের টেস্টও দরকার যেখানে কোনোটাই মিলে না। কাজ শেষ হয়েছে কি না তা ঠিক করার একটা node-এর টেস্ট দরকার সেই কেসের জন্য যেটা এখনো শেষ হয়নি — এটাই অনন্তকাল loop তৈরি করে।
শেষ হওয়ার শর্তে দুটো টেস্ট দরকার: যেখানে agent-এর থামা উচিত, আর যেখানে থামা উচিত নয়। দ্বিতীয়টাই loop টেস্ট, আর এটাই অনন্তকাল loop খুঁজে বের করে।
আর trace-ই architecture-কে দৃশ্যমান করে। একটা run trace একটা operation-এর প্রতিটা run (model call, tool call) তার input ও output সহ রেকর্ড করে Source 2সোর্স 2। ক্রমে পড়লে দেখা যায় agent কোন পথ নিয়েছে। এটা দিয়েই বোঝা যায় ভুল পথে যাওয়া agent আর সঠিক পথে গিয়ে ব্যর্থ হওয়া agent-এর পার্থক্য।
In practice
Write the architecture down as data, so the test and the agent read the same list of tools:
# app/agent/tools.py
from pydantic import BaseModel
class Tool(BaseModel):
name: str
description: str
parameters: dict
def with_description(tools, name, description):
return [
t.model_copy(update={"description": description}) if t.name == name else t
for t in tools
]
# An excerpt: two of the five tools in the reference agent.
TOOLS = [
Tool(
name="search_web",
description="Searches the web for current information about a product or event.",
parameters={"query": {"type": "string"}},
),
Tool(
name="send_email",
description="Sends an email to the customer. Changes state. Requires approval.",
parameters={"to": {"type": "string"}, "body": {"type": "string"}},
),
]Then the architecture test, which is the one that stops the agent from doing something irreversible:
def test_the_agent_does_not_email_without_approval(agent, mailbox):
agent.run("Tell the customer their refund was rejected.")
assert mailbox.sent == [], "the agent sent an email without approval"
assert agent.state["pending_approval"] is not NoneAnd the tool-description test, which is the one teams find surprising:
def test_a_vague_tool_description_still_picks_the_right_tool(agent):
agent.run("What happened in the news today?")
assert agent.tool_calls[0].name == "search_web"
agent_with_vague_description = agent.with_tools(
with_description(TOOLS, "search_web", "Searches.")
)
agent_with_vague_description.run("What happened in the news today?")
assert agent_with_vague_description.tool_calls[0].name == "search_web"That test asserts both branches pick the same tool, which tells you the vague description is not yet a problem. The moment it picks something else, the description has become load-bearing and it needs a test of its own.
Finally, the decision-tree test, which asserts that the agent asked the question before it answered it:
def test_the_agent_asks_before_it_acts_on_a_missing_fact(agent, trace):
agent.run("Cancel my order")
assert "cancel_order" not in [call.name for call in trace.tool_calls]
assert "clarify" in [node.name for node in trace.nodes]The second assertion is the point: the clarification node has to run, or the agent cancels an order it did not know the id of. The agent must not call cancel_order for this prompt until the user has given the order id.
সহজ English
First, write the architecture down as data. Then the test and the agent read the same list of tools:
# app/agent/tools.py
from pydantic import BaseModel
class Tool(BaseModel):
name: str
description: str
parameters: dict
def with_description(tools, name, description):
return [
t.model_copy(update={"description": description}) if t.name == name else t
for t in tools
]
# An excerpt: two of the five tools in the reference agent.
TOOLS = [
Tool(
name="search_web",
description="Searches the web for current information about a product or event.",
parameters={"query": {"type": "string"}},
),
Tool(
name="send_email",
description="Sends an email to the customer. Changes state. Requires approval.",
parameters={"to": {"type": "string"}, "body": {"type": "string"}},
),
]Next is the approval test. It stops the agent from doing something that cannot be undone:
def test_the_agent_does_not_email_without_approval(agent, mailbox):
agent.run("Tell the customer their refund was rejected.")
assert mailbox.sent == [], "the agent sent an email without approval"
assert agent.state["pending_approval"] is not NoneNext is the tool-description test. Teams find this one surprising:
def test_a_vague_tool_description_still_picks_the_right_tool(agent):
agent.run("What happened in the news today?")
assert agent.tool_calls[0].name == "search_web"
agent_with_vague_description = agent.with_tools(
with_description(TOOLS, "search_web", "Searches.")
)
agent_with_vague_description.run("What happened in the news today?")
assert agent_with_vague_description.tool_calls[0].name == "search_web"This test checks that both versions pick the same tool. So the vague description is not a problem yet. Once the agent picks a different tool, the description has become load-bearing. Then it needs a test of its own.
Last is the decision-tree test. It checks that the agent asked a question before it acted:
def test_the_agent_asks_before_it_acts_on_a_missing_fact(agent, trace):
agent.run("Cancel my order")
assert "cancel_order" not in [call.name for call in trace.tool_calls]
assert "clarify" in [node.name for node in trace.nodes]The second assertion is the key one. The clarification node has to run. If it does not, the agent cancels an order without knowing the id. The agent must not call cancel_order for this prompt until the user has given the order id.
বাংলা ব্যাখ্যা
architecture-টা data হিসেবে লিখুন, যাতে টেস্ট আর agent একই tool-এর তালিকা পড়ে:
# app/agent/tools.py
from pydantic import BaseModel
class Tool(BaseModel):
name: str
description: str
parameters: dict
def with_description(tools, name, description):
return [
t.model_copy(update={"description": description}) if t.name == name else t
for t in tools
]
# An excerpt: two of the five tools in the reference agent.
TOOLS = [
Tool(
name="search_web",
description="Searches the web for current information about a product or event.",
parameters={"query": {"type": "string"}},
),
Tool(
name="send_email",
description="Sends an email to the customer. Changes state. Requires approval.",
parameters={"to": {"type": "string"}, "body": {"type": "string"}},
),
]তারপর architecture টেস্ট, যেটা agent-কে অপরিবর্তনীয় কাজ করতে দেয় না:
def test_the_agent_does_not_email_without_approval(agent, mailbox):
agent.run("Tell the customer their refund was rejected.")
assert mailbox.sent == [], "the agent sent an email without approval"
assert agent.state["pending_approval"] is not Noneআর tool-description টেস্ট, যেটা দলগুলো অবাক করে:
def test_a_vague_tool_description_still_picks_the_right_tool(agent):
agent.run("What happened in the news today?")
assert agent.tool_calls[0].name == "search_web"
agent_with_vague_description = agent.with_tools(
with_description(TOOLS, "search_web", "Searches.")
)
agent_with_vague_description.run("What happened in the news today?")
assert agent_with_vague_description.tool_calls[0].name == "search_web"টেস্টটা assert করে দুটো branch-ই একই tool বাছে, যেটা বলে অস্পষ্ট description এখনো সমস্যা নয়। যেদিন সে অন্য কিছু বাছবে, তখন description আর load-bearing হয়ে গেছে, আর তার নিজস্ব টেস্ট দরকার।
শেষে decision-tree টেস্ট, যেটা assert করে agent উত্তর দেওয়ার আগে প্রশ্ন করেছে:
def test_the_agent_asks_before_it_acts_on_a_missing_fact(agent, trace):
agent.run("Cancel my order")
assert "cancel_order" not in [call.name for call in trace.tool_calls]
assert "clarify" in [node.name for node in trace.nodes]Common mistakes
Mistake 1: testing only the final answer. The trace shows the steps taken, not only the final answer Source 2সোর্স 2.
Mistake 2: no approval test for a tool that changes the world. An agent that can email without asking is one bad prompt away from emailing every customer.
Mistake 3: treating tool descriptions as documentation. They are prompt text, and rewriting one changes the behaviour Source 3সোর্স 3.
Mistake 4: no test for a task that cannot be finished. The stopping logic is only exercised by the goals that never succeed.
Mistake 5: no test for a tool returning an error. The tool result goes back into the state, and the agent has to do something with it.
Mistake 6: no cap on the number of tool calls. Without one, the agent spends the whole budget in one run.
সহজ English
Mistake 1: testing only the final answer. The trace shows the steps taken, not only the final answer Source 2সোর্স 2.
Mistake 2: no approval test for a tool that changes the world. An agent that can email without asking is one bad prompt away from emailing every customer.
Mistake 3: treating tool descriptions as documentation. They are prompt text. Rewriting one changes the behaviour Source 3সোর্স 3.
Mistake 4: no test for a task that cannot be finished. Only goals that never succeed exercise the stopping logic.
Mistake 5: no test for a tool that returns an error. The tool result goes back into the state. The agent has to do something with it.
Mistake 6: no cap on the number of tool calls. Without a cap, the agent can spend the whole budget in one run.
বাংলা ব্যাখ্যা
Mistake 1: শুধু শেষ উত্তর টেস্ট করা। trace দেখায় কোন ধাপগুলো নেওয়া হয়েছে, শুধু শেষ উত্তর নয় Source 2সোর্স 2।
Mistake 2: পৃথিবী বদলে দেওয়া tool-এর approval টেস্ট নেই। যে agent না বলেই email পাঠাতে পারে, সে একটা খারাপ prompt থেকে সব customer-কে email করতে পারে।
Mistake 3: tool-এর বর্ণনাকে ডকুমেন্টেশন ভাবা। এগুলো prompt text, আর একটা বদলালে আচরণ বদলায় Source 3সোর্স 3।
Mistake 4: যে কাজ শেষ করা যায় না তার টেস্ট নেই। শেষ হওয়ার logic কেবল সেই লক্ষ্যেই পরীক্ষিত হয় যেগুলো কখনো সফল হয় না।
Mistake 5: tool error ফেরত দেওয়ার টেস্ট নেই। tool-এর ফলাফল state-এ ঢোকে, আর agent-কে তার কিছু করতে হয়।
Mistake 6: tool call-এর সংখ্যার ক্যাপ নেই। ক্যাপ না থাকলে agent এক run-এ পুরো বাজেট খরচ করে।
What a tester can check
Tutorial advice
This advice is the tutorial's own. It does not come from the sources.
- Keep the tool list in one place and load it into both the agent and the test. Two lists is a silent mismatch.
- For every tool that changes something, write the test that proves it was not called. That test is more valuable than the one that proves it was.
- Treat a tool description as a prompt change: it needs a before-and-after measurement like any other prompt edit.
- Give the agent a goal it cannot complete in every test run. That is the case that exercises the stopping logic.
- Assert on the trace's node sequence, not on the tool names. A wrong order with the right tools is still wrong.
- Cap the tool calls in the test fixture. A test that runs 50 turns proves nothing and takes a minute.
সহজ English
Tutorial advice
This advice is the tutorial's own. It does not come from the sources.
- Keep the tool list in one place and load it into both the agent and the test. Two lists is a silent mismatch.
- For every tool that changes something, write the test that proves it was not called. That test is more valuable than the one that proves it was.
- Treat a tool description as a prompt change: it needs a before-and-after measurement like any other prompt edit.
- Give the agent a goal it cannot complete in every test run. That is the case that exercises the stopping logic.
- Assert on the trace's node sequence, not on the tool names. A wrong order with the right tools is still wrong.
- Cap the tool calls in the test fixture. A test that runs 50 turns proves nothing and takes a minute.
বাংলা ব্যাখ্যা
Tutorial advice
এই পরামর্শ টিউটোরিয়ালের নিজস্ব। এটি সোর্স থেকে আসেনি।
- tool-এর তালিকা এক জায়গায় রাখুন আর agent আর টেস্ট দুটোতেই তা লোড করুন। দুটো তালিকা মানে নীরবে মিসম্যাচ।
- যে tool কিছু বদলায়, তার জন্য সেটা বলা হয়নি — এই টেস্টটাই লিখুন। সেটা বলা হয়েছে — এই টেস্টের চেয়ে বেশি মূল্যবান সেটাই।
- tool-এর বর্ণনাকে prompt পরিবর্তনের মতোই দেখুন: এর জন্যও আগে-পরে মাপ দরকার।
- প্রতিটা test run-এ agent-কে এমন লক্ষ্য দিন যেটা সে শেষ করতে পারে না। শেষ হওয়ার logic ওই কেসেই পরীক্ষিত হয়।
- tool-এর নামের বদলে trace-এর node-এর ক্রমের ওপর assert করুন। সঠিক tool ভুল ক্রমে ব্যবহার করাও ভুল।
- test fixture-এ tool call-এর সংখ্যা ক্যাপ করুন। ৫০ turn চলা টেস্ট কিছুই প্রমাণ করে না আর এক মিনিট সময় নেয়।
Key words
| Word | What it means |
|---|---|
| Agent | A control loop around a model that decides what to do at each step |
| Tool description | The text that tells the model what a tool does; it is part of the prompt |
| Decision point | A node where the model chooses the next action |
| State | What the agent carries between steps: the goal, the messages, the collected facts |
| Approval step | A human gate before a tool that changes something irreversible |
| Stopping condition | The rule that ends the agent loop, and the limit that caps it |
| Trace | The record of every run (model call, tool call) in one operation, with inputs and outputs |
| Irreversible tool | A tool whose effect cannot be undone, like sending an email |