LLM PauseChain
Exception mechanism in the llm-library that enables tools to cleanly pause execution chains mid-process, particularly useful for implementing human-in-the-loop approval workflows. Introduced in version 0.32a3 as part of advanced tool-calling enhancements.
Core Mechanism
Exception-Based Control:
- Tools raise
llm.PauseChainexception to halt execution - Exception propagates to caller with preserved context
- No model call made with placeholder results when paused
- Clean interruption without corrupting workflow state
State Preservation:
.tool_callattached to exception with current tool context.tool_resultscontains completed sibling results- Full context available for resumption decisions
- Workflow state remains consistent during pause
Integration with Tool Calling
Tool Implementation:
Tools can access the current tool call context through the llm_tool_call parameter:
def approval_required_tool(data, llm_tool_call):
# Access tool call ID and context
tool_id = llm_tool_call.tool_call_id
# Raise exception to pause for approval
if requires_approval(data):
raise llm.PauseChain("User approval required")
Concurrent Execution Handling:
- Async sibling tool calls run to completion before pause propagation
- Robust failure semantics for parallel tool execution
- Proper handling of mixed success/pause scenarios
Use Cases
Human Approval Workflows:
- Pausing before executing sensitive operations
- Requesting user confirmation for data modifications
- Validating AI-generated decisions before proceeding
- Implementing multi-step approval processes
datasette-agent Integration:
Primary driver for PauseChain development was enabling ask_user() functionality:
- Pause data analysis workflows for user input
- Request clarification on ambiguous queries
- Confirm potentially destructive operations
- Enable interactive data exploration sessions
Technical Implementation
Exception Propagation:
- Tool raises
PauseChainexception during execution - Exception bubbles up through tool call infrastructure
- Current state preserved with tool call context
- Caller receives exception with resumption information
- Workflow can be resumed with user input/approval
Unique Tool Call IDs:
- Every tool call guaranteed unique identifier
- Providers without native IDs get synthesized
tc_-prefixed ULIDs - Enables precise tracking of paused operations
- Supports complex workflow resumption scenarios
Workflow Patterns
Interactive Approval:
1. Tool execution begins
2. Tool determines approval needed
3. PauseChain exception raised with context
4. User presented with approval request
5. User provides approval/denial/modification
6. Workflow resumes with user input
Multi-Step Processes:
- Complex workflows can pause at multiple points
- Each pause preserves complete execution context
- Resumption maintains state consistency
- Support for branching based on user decisions
Development Impact
The PauseChain mechanism was developed entirely through claude-fable 5's autonomous programming during simon-willison's first-day evaluation. This demonstrates:
- AI-driven identification of missing infrastructure needs
- Autonomous implementation of sophisticated control flow mechanisms
- Integration of human oversight into automated workflows
- Evolution from hacks to supported library features
See also
- human-in-the-loop
- llm-library
- tool-calling
- pause-resume-workflows
- datasette-agent
- claude-fable-5