Lesson 9 · tools as functions
Giving your agent tools
- 1. Story
- 2. Guess
- 3. Your turn
- 4. Catch Sitara’s mistake
KaiSo Sitara can plan. But who actually checks the fridge?
SitaraYour tools do. Each tool is a small function you wrote and trust.
Mochi(has already checked the fridge, personally)
Tools are normal functions. A dictionary connects each tool name to its function, so the agent can run the one Sitara picked.
- 1. Each tool is a function you wrote
- 2. tools maps a tool name to its function
- 3. tools[plan["tool"]] picks the function, and tool(plan["args"]) runs it
cafe.py
Try: Change the request to "How much milk is left?" and run it.
Read · about 1 minute
The basics, in plain words
Tools are normal functions. A dictionary connects each tool name to its function, so the agent can run the one Sitara picked.
from sitara import ask_sitara
stock = {"milk": 4, "scone": 10}
def check_stock(args):
return stock.get(args["item"], 0)
def take_order(args):
item = args["item"]
qty = args["qty"]
stock[item] = stock.get(item, 0) - qty
return f"Order taken: {qty} {item}"
tools = {"check_stock": check_stock, "take_order": take_order}
plan = ask_sitara("Order 2 scone")
tool = tools[plan["tool"]]
print(tool(plan["args"]))
print(stock)- Each tool is a function you wrote
- tools maps a tool name to its function
- tools[plan["tool"]] picks the function, and tool(plan["args"]) runs it
- tool
- A normal Python function the agent is allowed to use.
- tools = {name: function}
- A dictionary that connects each tool name to its function.
Common slip: Giving an agent more tools than it needs. Fewer tools means fewer surprises.
Read all twelve Python basics with Sitara →