도구 설명 작성하기
Coddy AI Engineering 여정의 도구와 에이전트 섹션에 포함된 레슨. 22개 중 11번째.
모델은 사용자의 Python 함수를 절대 직접 보지 못합니다. 도구를 호출할지 여부와 어떤 도구를 호출할지는 오직 도구의 name과 description만 보고 결정합니다. Useful helper.와 같은 설명은 판단할 수 있는 근거를 제공하지 않으므로, 도구 없이 답변하게 됩니다.
vague = {"name": "helper", "description": "Useful helper.", "input_schema": schema}
clear = {
"name": "get_tides",
"description": "Get today's high and low tide times for a harbour. Use it for any question about tides.",
"input_schema": schema,
}When is high tide in Dover?라는 질문을 받으면 모델은 vague로 직접 응답하고(종료 이유 end_turn), clear를 호출합니다(종료 이유 tool_use).
좋은 설명은 세 가지를 명시합니다: 도구가 수행하거나 반환하는 작업, 사용해야 하는 시점, 그리고 모델이 인자에 대해 알아야 하는 내용(단위, 형식, 제한 사항)입니다. 각 인자에도 고유한 description을 작성해 주세요. 가상 테스트(stand-in)는 요청과 설명 사이의 단어를 매칭하고, 실제 모델은 의미를 파악하지만 설명에 아무런 내용이 없다면 마찬가지로 실패합니다.
챌린지
중급도서관 어시스턴트가 설명에 아무런 내용이 없어 lookup 도구를 전혀 사용하지 않습니다. 설명을 수정하세요. 이름, 스키마, 루프는 그대로 유지하세요.
Looks things up.를 한두 문장의 설명으로 교체하세요.- 이 도구가 도서관 지점의 운영 시간을 가져온다고 설명하세요.
- 누군가 지점이 언제 여는지 또는 닫는지 물어볼 때 사용하라고 지정하세요.
루프는 각 도구 호출과 답변을 출력합니다. 예를 들어, When does the Riverside branch open? 입력에 대해 프로그램은 다음과 같이 출력합니다:
Tool: lookup {'branch_name': 'Riverside'}
Answer: Here is what I found: Riverside: 9 am to 6 pm직접 해보기
import coddy_ai as anthropic # 프로덕션 환경: import anthropic
client = anthropic.Anthropic()
HOURS = {"Riverside": "9 am to 6 pm", "Hill": "10 am to 4 pm", "Oak": "8 am to 8 pm"}
# 모델이 이 도구를 언제 사용해야 하는지 알 수 있도록 설명을 재작성하세요
TOOLS = [
{
"name": "lookup",
"description": "Looks things up.",
"input_schema": {
"type": "object",
"properties": {"branch_name": {"type": "string", "description": "The branch name, such as Riverside"}},
"required": ["branch_name"],
},
}
]
def lookup(branch_name):
return f"{branch_name}: {HOURS.get(branch_name, 'no such branch')}"
request = input()
messages = [{"role": "user", "content": request}]
response = client.messages.create(model="claude-opus-5-5", max_tokens=300, tools=TOOLS, messages=messages)
while response.stop_reason == "tool_use":
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type == "tool_use":
print(f"Tool: {block.name} {block.input}")
results.append({"type": "tool_result", "tool_use_id": block.id, "content": lookup(**block.input)})
messages.append({"role": "user", "content": results})
response = client.messages.create(model="claude-opus-5-5", max_tokens=300, tools=TOOLS, messages=messages)
for block in response.content:
if block.type == "text":
print("Answer: " + block.text)
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
도구와 에이전트의 모든 레슨
직접 연습해 보세요: 온라인 Python 컴파일러