Harnesses, bounded loops and recovery
Harness হলো agent-এর কাজের চারপাশের নিয়ন্ত্রণ। কতবার চেষ্টা করবে, কোন tool পাবে, কখন থামবে।
Guess first
Pick an answer. You will see if you were right at the end of the lesson.
What stops a model that never says done?
Real-world analogy
What is it?
A harness executes the model-tool loop and preserves state. Good limits cover steps, wall time, tool permissions and output size. An error can lead to a controlled correction; repeated failure must stop with evidence rather than spinning forever.
Real-world relevance
One shared support-ticket product, three optional entry points. Frontend: Bound screenshot/fix/retest attempts; repeated layout failures should stop with a report. Backend: Bound tool calls and request time; permission failures must not trigger endless retries. Mobile: Bound build/test retries and require a real device check for platform-sensitive changes.
Key points
- Bound steps — Count every model turn, including failed turns.
- Bound wall time — A step limit does not stop one hung network call; add call timeouts too.
- Allowlist tools — Dispatch only known operations with validated arguments.
- Validate completion — Do not accept done unless the expected schema and verification evidence exist.
- Classify errors — Retry transient timeouts; stop on permission denial or invalid credentials.
- Persist checkpoints — Store the operation id and completed effects so recovery does not duplicate them.
- Explain stopping — Return what failed and what is needed next, without exposing secrets.
- Frontend practice — Bound screenshot/fix/retest attempts; repeated layout failures should stop with a report.
- Backend practice — Bound tool calls and request time; permission failures must not trigger endless retries.
- Mobile practice — Bound build/test retries and require a real device check for platform-sensitive changes.
Quick check
Answer from memory — scrolling up first makes it stick less.
What artifact demonstrates this lesson?
Which statement is defensible?
Code example
def run_fixture_agent(next_action, tools, max_steps=3):
history = []
for _ in range(max_steps):
action = next_action(history)
if action["type"] == "done":
return action["result"]
name = action["tool"]
if name not in tools:
raise ValueError("tool not allowed")
history.append(tools[name](action["args"]))
raise RuntimeError("step limit reached")Line-by-line walkthrough
- 1. This minimal Python fixture loop demonstrates dispatch and a step bound only. Before live use add schema validation, independent result checks, per-call timeout, authorisation and cost limits. It is not a production sandbox.
Spot the bug
while True: ask_model_and_run_tools()Need a hint?
Show answer
Explain like I'm 5
Fun fact
Hands-on challenge
More resources
- Free Context Course (Hugging Face)
- Download the free offline lab (Python, tests and instructions) (Teamz Lab)
Lock it in