Anthropic Claude — 도구를 사용하는 에이전트 한 턴
실제로 실행 가능한 미니 프로젝트입니다. 받아서 Docker로 실행해 보세요.
2026년 6월 28일
Anthropic Claude — 도구를 사용하는 에이전트 한 턴공식 Anthropic SDK로 만든 아주 작은 에이전트
루프입니다. Claude에 도구 하나(get_weather)를 주면 Claude가 그것을 호출하고,
스크립트는 결과를 tool_result로 다시 보냅니다 — Claude가 최종 답을 쓸 때까지
반복합니다. 이 루프가 에이전트의 핵심 패턴입니다.
설정
cd samples/anthropic-claude_1
cp .env.sample .env
# .env 편집: ANTHROPIC_API_KEY 설정 (필요하면 MODEL도)
키는 console.anthropic.com에서 발급받으세요.
MODEL의 기본값은 claude-opus-4-8이며,
모델 목록을 참고하세요.
.env는 gitignore 처리되어 있고, .env.sample만 커밋됩니다.
Docker로 실행
cd samples/anthropic-claude_1
docker build -t aas-anthropic-claude .
docker run --rm --env-file .env aas-anthropic-claude "What should I wear in Seoul today?"
Docker로 실행 (DooD를 쓰는 devcontainer에서)
호스트 Docker 데몬과 통신하는 dev container(Docker-outside-of-Docker)에서는 위의
포그라운드 docker run이 종종 아무것도 출력하지 않고 exit 0으로 끝납니다. 하지만
실행 자체는 성공한 것입니다. 스크립트는 끝까지 실행되고 출력도 Docker가 모두
캡처하는데, 실시간 attach 스트림만 그 출력을 VM 경계에서 흘려버립니다. 같은
컨테이너에 docker logs를 실행하면 전체 출력이 그대로 보이고, 컨테이너는 exit 0으로
끝나며 OOM도 아닙니다. detached로 실행하고 로그를 따라가세요:
cd samples/anthropic-claude_1
docker build -t aas-anthropic-claude .
docker logs -f "$(docker run -d --env-file .env aas-anthropic-claude \
"What should I wear in Seoul today?")"
로컬에서 실행
cd samples/anthropic-claude_1
pip install -r requirements.txt
python app.py "What should I wear in Seoul today?"
python-dotenv가 .env를 자동으로 불러옵니다.
실행 결과
모델과 실행마다 결과가 달라집니다 — LLM은 비결정적이라 표현(그리고 에이전트의 구체적 단계)이 매번 다릅니다. 아래는
claude-opus-4-8로 실행한 한 예입니다.
I'll check the current weather in Seoul to help you decide what to wear.
[tool call] get_weather({'city': 'Seoul'})
It's a beautiful day in Seoul today—**22°C and sunny**! Here's what I'd recommend:
- A light long-sleeve shirt or a t-shirt
- Comfortable pants, jeans, or a skirt/dress
- A light jacket or cardigan if you tend to get chilly, especially in the evening
- Sunglasses, maybe a hat, and a bit of sunscreen since it's sunny
...
22°C is mild and pleasant—no need for heavy layers. Enjoy your day!