1. Learn
  2. /
  3. Courses
  4. /
  5. AI Agents with Hugging Face smolagents

Connected

Exercise

Just Add @tool: Writing a Custom Tool

You've just started working at a AgentsCafé, where customers at each table can place multiple drink orders.

Baristas currently hand-write order codes like T5_Latte_20250812_0915, but typos and inconsistent formatting often lead to mix-ups and wrong deliveries.

To fix this, you'll build a simple tool called generate_order_id that takes a table ID, drink name, and appends a timestamp, ensuring every order code is clear and consistent.

Note: The datetime library has been already imported.

Instructions

100 XP
  • Import the tool decorator from the smolagents library.
  • Use the @tool decorator to register your generate_order_id function as a tool.
  • Return the formatted order ID string that combines the table ID, drink name, and current timestamp.