Lesson 4 of 5 · 2 min
Tools: the model asks, your code acts
A model never runs anything itself. It replies with the name of a tool and its inputs. Your code checks the request, runs it and sends the result back. The model chooses from the descriptions, so write them as if for a new colleague.
def add(a: float, b: float): return a + b
TOOLS = {"add": add}
request = {"tool": "add", "args": {"a": 19, "b": 23}} # what a model might send
if request["tool"] not in TOOLS:
result = "error: unknown tool"
else:
result = TOOLS[request["tool"]](**request["args"])
print("send back to the model:", result)
