C.W.K.
Stream
Lesson 03 of 05 · published

Tool Choice 와 Agentic Loop

~22 min · tool-choice, auto, any, loop

Level 0호기심 많은 독자
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Tool 리스트가 깔리면 다음 결정은 tool choice: 이번 turn 에 모델한테 얼마나 자유 줄 거야? 모든 major provider 가 같은 세 모드를 다른 이름으로 노출해.

  • auto (default): 모델이 tool 부를지 텍스트로 답할지 직접 골라. 보통의 conversational agent 용.
  • any / required: 모델이 무조건 어떤 tool 은 불러야 함 — plain text 답 금지. 다음 step 이 tool 결과를 요구하는 architecture 일 때 (e.g. 항상 routing 결정 내리는 router).
  • specific tool: 특정 tool 강제. 구조화된 workflow 의 첫 turn 용 ("항상 plan_steps 부터 부르기").

Tool choice 는 agentic loop 의 압력 밸브야. 가장 흔한 bug — 아무것도 안 하면서 철학 떠는 agent — 는 첫 turn 을 any 나 specific tool 로 바꾸면 고쳐져. 다른 흔한 bug — 같은 tool 영원히 부르는 agent — 는 첫 turn 후 auto 로 두면 모델이 멈추고 답할 수 있어.

Agentic loop 는 그 결정들 위에 구조를 얹어. 견고한 loop 는 기계적 안전 3 조각: max_turns 캡 (버그난 description 이 영구 loop 안 만들게), error feedback 경로 (tool 이 throw 하면 에러를 tool result 로 모델한테 돌려줘서 조정 가능하게), cost guard 프로덕션용 (총 토큰이나 wall time 이 임계 넘으면 멈추고 물어봄). 이건 premature optimization 아니야 — recover 하는 agent 와 조용히 crash 하는 agent 의 차이야.

Code

Tool choice — 3 provider, 같은 idea·python
# Anthropic
client.messages.create(..., tool_choice={"type": "any"})
client.messages.create(..., tool_choice={"type": "tool", "name": "plan_steps"})

# OpenAI Responses
client.responses.create(..., tool_choice="required")
client.responses.create(..., tool_choice={"type": "function", "name": "plan_steps"})

# Gemini
GenerationConfig(tool_config=ToolConfig(function_calling_config=FunctionCallingConfig(mode="ANY")))
Error feedback 가 있는 loop·python
def call_tool_safely(name, args, executors):
    try:
        return {"ok": True, "result": executors[name](**args)}
    except Exception as e:
        return {"ok": False, "error": f"{type(e).__name__}: {e}"}

# Loop 안에서 에러 결과를 tool_result 로 — 'content' 에 실패 메시지 담아서 —
# 돌려줘. 모델은 retry 할지 tool 바꿀지 user 한테 사과할지 알아서 결정해.

External links

Exercise

Tool 두 개로 agent 짜: 항상 성공하는 'lookup' 과 항상 raise 하는 'broken'. Broken 을 고르는 prompt 로 돌려. 에러를 tool_result 로 돌려보내면 모델이 'lookup' 을 대신 골라 recover 하는지 — loop 가 crash 하지 않고 — 확인. 그 recovery 경로가 네 loop 가 실패에 정직한지 보는 test 야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.