Menu
CoddyTech

요약: 경비 에이전트

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

challenge icon

챌린지

어려움

확인 및 사람의 승인을 거친 후에만 지출을 기록하는 지출 에이전트를 작성하세요. 시작 코드는 하나의 요청을 읽으며, TOTALS는 카테고리별로 지금까지 지출된 금액을 보유합니다.

  1. 두 개의 도구를 정의하세요. 둘 다 "enum": ["travel", "meals", "office"] 속성을 가진 문자열 category를 받습니다.
    • Log a new expense, in euros, under a category.라는 설명의 log_expense는 숫자 amount도 받습니다. 두 속성 모두 필수입니다.
    • Get the total spent so far in one expense category.라는 설명의 get_total.
  2. model="claude-opus-5-5" 및 max_tokens=300으로 최대 5회의 도구 호출 라운드 동안 에이전트 루프를 실행하세요.
  3. get_total은 <category>: <total> euros spent.를 반환합니다.
  4. log_expense는 먼저 금액을 확인합니다. 금액이 0 이하이거나 200 초과인 경우, 오류 결과로 Amounts must be between 0 and 200 euros.를 반환하고 아무것도 묻지 않습니다.
  5. 그렇지 않으면 Approve <amount> euros for <category>? (yes/no)를 출력하고 한 줄을 읽습니다. yes 이외의 모든 입력은 오류 결과로 The user declined to log this expense.를 반환합니다.
  6. 승인되면 금액을 카테고리의 총액에 더하고 Logged <amount> euros for <category>. New total: <total> euros.를 반환합니다.
  7. Answer: 와 최종 텍스트를 출력하세요.

모든 금액과 총액은 소수점 둘째 자리까지 작성하세요. 오류 결과는 "is_error": True를 포함합니다. 예를 들어 입력 Log 25 euros for a taxi under travel 및 yes에 대해 프로그램은 다음을 출력합니다:

Approve 25.00 euros for travel? (yes/no)
Answer: Here is what I found: Logged 25.00 euros for travel. New total: 145.00 euros.

직접 해보기

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

client = anthropic.Anthropic()

TOTALS = {"travel": 120.0, "meals": 45.5, "office": 30.0}

request = input()

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

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

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