Placing the order
The last tool is the one that matters. Place order takes everything in memory, confirms a total, and clears the state for the next customer. This is also where you would call a real kitchen system in production.
@function_tool()
async def place_order() -> str:
"""Finalises the order and clears the cart."""
if not order_items:
return "You do not have any items in your order yet."
total = sum(item["price"] for item in order_items)
items_list = ", ".join([item["name"] for item in order_items])
order_items.clear()
return f"Perfect. I have placed your order for {items_list}. Your total is ${total:.2f}. Thank you!"The tool clears state after placing the order so the next customer starts fresh. In production this in-memory list becomes a database row with a session or user id.
class RestaurantAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions=build_instructions(),
stt=deepgram.STTv2(model="flux-general-en", eager_eot_threshold=0.3),
llm=get_livekit_llm(),
tts=deepgram.TTS(model="aura-asteria-en"),
vad=silero.VAD.load(),
tools=[
add_item_to_order,
view_current_order,
get_menu_items,
place_order,
],
)Every tool you wrote gets registered on the agent. The LLM sees their docstrings and signatures and decides when to call them based on what the customer says.
Quiz: Quiz
Loading practice…
Checkpoint: Tool calling checkpoint
Loading practice…