Machine-assisted translation of the Hebrew original, awaiting the lecturer's review.
Lab 1 — The first agent
The goal: a loop that stops, and tells an answer apart from a stop.
Running
python code/lab01/agent.py
What should come out
The first output is ההפרש הוא 5 ("the difference is 5") with the status answered. Then the same file runs with a budget of zero and expects stopped.
Try it yourself
Try an unknown operation, div, and see that the error enters the history and that the answer is not a made-up number.
The code
The full starter file. The answer strings are in Hebrew, as in the repository: "הכלי נכשל" means "the tool failed", and "ההפרש הוא" means "the difference is".
def decide(history):
results = [item for item in history if item.get("kind") == "tool_result"]
if not results:
return {"kind": "tool", "name": "calculator", "args": {"op": "sub", "a": 95, "b": 90}}
if "error" in results[-1]:
return {"kind": "finish", "status": "stopped", "answer": "הכלי נכשל"}
return {"kind": "finish", "status": "answered", "answer": f"ההפרש הוא {results[-1]['value']}"}
Next
Found a mistake on this page? Email the lecturer