시작하기무료로 시작하기

계산서 확인: 에이전트에 데이터 접근 권한 주기

AgentsCafé에서는 모든 음료 주문이 orders.csv 파일에 저장되며, 여기에는 table_id, drink_name, size 열이 포함되어 있습니다.

고객이 계산서를 요청할 때마다 파일을 일일이 찾아보는 대신, 특정 테이블의 현재 주문을 조회하는 도구를 만들어 보겠습니다.

참고: toolpandas는 이미 임포트되어 있습니다.

이 연습은 강의의 일부입니다

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 ____
코드 편집 및 실행