LangGraphLangChainFault ToleranceProduction

LangGraph Adds Fault Tolerance: Retries, Timeouts, and Error Handlers

Overview

LangGraph has introduced comprehensive fault tolerance mechanisms, including retries, timeouts, and error handlers. These features enable agents to handle failures gracefully, recover from transient errors, and maintain reliability in production environments.

New Features

1. Retry Mechanisms

LangGraph now supports configurable retry policies:

  • Automatic Retries: Define maximum retry attempts for failing nodes
  • Exponential Backoff: Gradually increase delay between retries
  • Retry Conditions: Specify which errors should trigger retries
  • Retry Callbacks: Execute custom logic before/after each retry
from langgraph.graph import StateGraph

builder = StateGraph(State)
builder.add_node(
    "api_call",
    api_call_node,
    retry={
        "max_attempts": 3,
        "backoff_factor": 2,
        "retry_on": [TimeoutError, ConnectionError],
    }
)

2. Timeout Controls

Prevent nodes from running indefinitely:

  • Node-Level Timeouts: Set maximum execution time per node
  • Global Timeouts: Limit total workflow execution time
  • Graceful Degradation: Specify fallback behavior on timeout
builder.add_node(
    "long_running_task",
    long_running_node,
    timeout=300  # 5 minutes
)

3. Error Handlers

Custom error handling and recovery:

  • Global Error Handler: Catch all unhandled errors
  • Node-Specific Handlers: Handle errors at the node level
  • Recovery Actions: Define alternative paths for different error types
  • Error Logging: Capture error context for debugging
def error_handler(error: Exception, state: State):
    if isinstance(error, ValidationError):
        return "validation_failed"
    elif isinstance(error, RateLimitError):
        return "rate_limited"
    return "unknown_error"

builder.add_node("error_handler", error_handler)

Impact on Agent Reliability

These features address common production challenges:

ChallengeBeforeAfter
Transient API failuresWorkflow crashesAutomatic retry with backoff
Long-running tasksNo timeout controlConfigurable timeouts
Unexpected errorsUnhandled exceptionsGraceful error handling
Debugging failuresLimited contextRich error logging

Integration with Existing Patterns

The fault tolerance features integrate seamlessly with:

  • Human-in-the-Loop: Error checkpoints can trigger human review
  • Persistence: Failed workflows can be resumed after recovery
  • Streaming: Error events are streamed for real-time monitoring
  • Subgraphs: Error handling can be scoped to specific subgraphs

Best Practices

  1. Define Clear Retry Policies: Only retry on transient errors
  2. Set Reasonable Timeouts: Balance between completion and resource usage
  3. Log Error Context: Capture sufficient information for debugging
  4. Test Failure Scenarios: Validate error handling with chaos testing
  5. Monitor Error Rates: Track failure patterns for continuous improvement

Resources