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

Error Handling과 Context Budget

~36 min · errors, context, budgets

Level 0Observer
0 XP0/40 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Production loop는 평범하게 실패해

tool은 timeout나고, API는 partial data를 주고, 모델은 맞는 tool에 틀린 argument를 넣고, loop는 step budget을 다 쓰고, context는 꽉 차서 제일 중요한 decision이 시야 밖으로 밀려난다. 이거 특별한 사고 아니야. 그냥 화요일이야.

진짜 single-agent loop는 failure를 exception dump가 아니라 structured observation으로 다룬다. 모델에게는 recovery할 만큼의 정보가 필요하고, operator에게는 debug할 만큼의 정보가 필요해.

Context budget은 safety budget이야

context window가 꽉 찰 때까지 밀어붙이지 마. margin이 사라지면 tool result, recovery, compaction, human handoff를 넣을 공간도 사라진다. 좋은 agent는 벽에 박기 전에 멈춘다.

낙관보다 recoverability

모든 tool result는 성공 여부, retry 가능성, 바뀐 state, 다음 safe action을 말해야 해. error는 type, message, retryability, compact trace id를 가져야 한다.

Code

Recoverable tool envelope·python
def execute_tool_safely(name, args, trace_id, timeout=30):
    try:
        result = execute_tool(name, args, timeout=timeout)
        return {
            "ok": True,
            "tool": name,
            "trace_id": trace_id,
            "changed_state": result.get("changed_state", False),
            "data": result,
        }
    except TimeoutError:
        return {
            "ok": False,
            "tool": name,
            "trace_id": trace_id,
            "error_type": "timeout",
            "retryable": True,
            "message": f"{name} timed out after {timeout}s",
            "next_safe_action": "retry_with_smaller_input",
        }
Context margin gate·python
def should_compact_or_stop(token_count, max_context, active_tool_budget=8000):
    hard_margin = max_context * 0.15
    required_margin = max(hard_margin, active_tool_budget)
    remaining = max_context - token_count
    if remaining < required_margin:
        return {
            "decision": "compact_before_next_tool",
            "remaining_tokens": remaining,
            "required_margin": required_margin,
        }
    return {"decision": "continue", "remaining_tokens": remaining}

External links

Exercise

web search timeout, schema validation error, permission denial 각각에 대한 failure envelope를 써봐. retryability와 next safe action을 표시해.
Hint
모든 error가 'try again'이면 executor가 생각을 안 하는 거야.

Progress

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

댓글 0

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

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