お会計をどうぞ!エージェントにデータへのアクセス権を付与する
AgentsCaféでは、すべてのドリンク注文が orders.csv というファイルに保存されています。このファイルには table_id(テーブル番号)、drink_name(ドリンク名)、size(サイズ)の列が含まれています。
お客様から会計を求められるたびに手動でファイルを確認するのは大変です。そこで、特定のテーブルの現在の注文をすべて検索するツールを作りましょう。
注意:tool と pandas はあらかじめインポートされています。
この演習はコースの一部です
Hugging Face smolagents で学ぶ AI エージェント
演習の手順
- エージェントがどのテーブルの注文を取得するかを認識できるよう、関数のパラメータに
table_idを使用してください。 - すべてのドリンク注文が含まれる
orders.csvファイルを読み込んでください。 - そのテーブルのドリンク注文リストを返してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create a tool that receives the table_id as input
@tool
def lookup_orders(____: str) -> list[str]:
"""
Retrieves the current drink orders for a café table.
Args:
table_id (str): The table's identifier (e.g., "T5").
Returns:
list[str]: A list of drink orders, each formatted like "Latte (Large)".
"""
# Read the orders.csv file
df = pd.read_csv('____')
orders = df[df['table_id'] == table_id].apply(lambda row: f"{row['drink_name']} ({row['size']})", axis=1).tolist()
# Return the table orders
return ____