Menu
CoddyTech

재고 에이전트

Coddy AI Engineering 여정의 도구와 에이전트 섹션에 포함된 레슨. 22개 중 21번째.

challenge icon

챌린지

어려움

상점의 재고를 확인하고 보충하는 에이전트를 작성하세요. 시작 코드는 STOCK을 보유하고 있으며 요청을 읽습니다.

  1. 두 개의 도구를 정의하세요. check_stock: 설명 Check how many units of a product are in stock, Which product로 설명되는 필수 문자열 속성 product 1개. order_more: 설명 Order more of a product from the supplier, 동일한 product 속성 및 How many units to order로 설명되는 필수 정수 속성 quantity.
  2. 두 함수를 작성하세요. 두 함수 모두 STOCK에 없는 제품에 대해 ValueError("Unknown product: <product>")를 발생시킵니다. check_stock은 <product>: <count> in stock을 반환합니다. order_more는 수량이 1부터 50까지의 정수가 아닌 경우 ValueError("Quantity must be between 1 and 50")를 발생시키고, 그렇지 않으면 STOCK에 추가하고 Ordered <quantity> of <product>, stock is now <count>를 반환합니다.
  3. 에이전트 루프를 실행하세요 (model="claude-opus-5-5", max_tokens=500, 최대 5회). 각 호출에 대해 Tool: 줄(이름, 공백, input)을 출력하세요. ValueError는 "is_error": True와 함께 해당 메시지로 다시 전달됩니다.
  4. 마지막에 Agent: 와 응답 텍스트를 출력한 다음, Stock: 과 모든 제품 및 해당 개수를 쉼표와 공백으로 구분하여 출력하세요.

예를 들어, Order 80 more of the office chair 입력에 대해 프로그램은 다음을 출력합니다:

Tool: order_more {'product': 'office chair', 'quantity': 80}
Agent: Sorry, I could not finish: Quantity must be between 1 and 50
Stock: desk lamp 7, office chair 3, standing desk 0

직접 해보기

import coddy_ai as anthropic  # 프로덕션 환경: import anthropic

client = anthropic.Anthropic()

STOCK = {"desk lamp": 7, "office chair": 3, "standing desk": 0}

request = input()

# 아래에 코드를 작성하세요

도구와 에이전트의 모든 레슨

직접 연습해 보세요: 온라인 Python 컴파일러