Lesson 6 of 12 advanced

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?

Open interactive version (quiz + challenge)

Real-world analogy

A driving instructor sets the route, speed limit and emergency brake around a learner driver.

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

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. 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?
What stops a model that never says done?
Show answer
Use a step budget, per-call timeout and a wall deadline; return a recoverable failure.

Explain like I'm 5

Harness হলো agent-এর কাজের চারপাশের নিয়ন্ত্রণ। কতবার চেষ্টা করবে, কোন tool পাবে, কখন থামবে।

Fun fact

A useful artifact for this lesson: Count every model turn, including failed turns.

Hands-on challenge

Choose ONE stack; you do not need to build all three. Junior foundation: Run the offline fixture loop and demonstrate the step limit. Senior extension: Design per-call deadlines, recovery checkpoints and spend enforcement for a live adapter. Evidence: save the input, expected behaviour, actual result and one failure or limitation. Junior means basic coding and Git, not zero programming experience.

More resources

Open interactive version (quiz + challenge) Download the whole course as PDF / Word

Lock it in

← Back to course: AI-Assisted Software Engineering