Human-in-the-Loop: Complete Guide
What Youâll Learn
Section titled âWhat Youâll LearnâThis tutorial series teaches you how to build interactive AI agents that can pause execution, ask questions, and get user approval before taking actions. Youâll learn three different approaches, from the simplest (Claude Code) to the most flexible (model-agnostic).
graph TB A[Choose Your Path] --> B{Requirements?} B -->|Quick & Simple| C[Claude Code<br/>Built-in Tool] B -->|OpenAI Only| D[OpenAI<br/>Function Calling + SDK] B -->|Multi-Model| E[Model Agnostic<br/>LangChain + OpenRouter]
C --> F[1. Overview] D --> F E --> F
F --> G[2. Claude Code] G --> H[3. OpenAI] H --> I[4. Model Agnostic]Tutorial Series
Section titled âTutorial SeriesâStart here to understand the fundamentals.
Learn:
- What human-in-the-loop is and why it matters
- Common use cases (clarification, approval, configuration)
- Architecture patterns and constraints
- Comparison of different approaches
- When to use HITL vs autonomous agents
Read this if: Youâre new to human-in-the-loop or want to understand the big picture.
The simplest approach - zero setup required.
Learn:
- How Claude Codeâs built-in
AskUserQuestionworks - Creating interactive skills with automatic UI rendering
- Design patterns (sequential, multi-select, progressive disclosure)
- Best practices for questions and options
- Limitations and when to use other approaches
Read this if: Youâre building Claude Code skills or want the fastest way to add HITL.
Pros:
- â Zero code - just write instructions
- â Automatic UI rendering in terminal
- â No state management needed
Cons:
- â Claude Code CLI only
- â Canât customize UI
- â Not portable to other platforms
Two powerful approaches for OpenAI users.
Learn:
- Function Calling: Manual implementation with full control
- Agents SDK: Built-in approval workflows with
needsApproval - Structured Outputs for guaranteed schema compliance
- Handling parallel tool calls
- Error handling and validation
Read this if: Youâre using OpenAI and want built-in approval features or need to understand function calling.
Pros:
- â Provider-supported patterns
- â Agents SDK has built-in approvals
- â Structured Outputs guarantee compliance
- â Good documentation and examples
Cons:
- â OpenAI models only
- â Still need to implement UI layer
- â SDK adds dependency
Maximum flexibility - works with any LLM provider.
Learn:
- LangChain + OpenRouter architecture
- Custom tool definition and execution loops
- Pluggable UI handlers (CLI, web, mobile)
- State management across pauses
- Constraints and trade-offs
- Production-ready patterns
Read this if: You need to support multiple LLM providers or build web/mobile apps.
Pros:
- â Works with any model (Claude, GPT, Gemini, Llama, etc.)
- â Full control over UI (terminal, web, mobile)
- â Custom validation and logic
- â Production-ready architecture
Cons:
- â More code (~200+ lines)
- â Manual state management
- â Higher complexity
Quick Comparison
Section titled âQuick ComparisonâBy Complexity
Section titled âBy Complexityâgraph LR A[Simplest] --> B[Claude Code<br/>0 LOC] B --> C[OpenAI SDK<br/>50 LOC] C --> D[Model Agnostic<br/>200+ LOC] D --> E[Most Control]By Use Case
Section titled âBy Use Caseâ| Use Case | Best Approach |
|---|---|
| Claude Code skill development | Claude Code built-in |
| Quick prototyping | Claude Code built-in |
| OpenAI-only production app | OpenAI Agents SDK |
| Custom approval logic | OpenAI Function Calling |
| Web/mobile application | Model Agnostic |
| Multi-provider support | Model Agnostic |
| Maximum flexibility | Model Agnostic |
Feature Matrix
Section titled âFeature Matrixâ| Feature | Claude Code | OpenAI SDK | Model Agnostic |
|---|---|---|---|
| Setup Time | Instant | Minutes | Hours |
| Lines of Code | 0 | ~50 | ~200+ |
| UI Rendering | Automatic | Manual | Fully Custom |
| Model Support | Claude only | OpenAI only | Any model |
| UI Options | Terminal only | Any (DIY) | Any (DIY) |
| State Management | Automatic | SDK helps | Manual |
| Approval Flow | Manual | Built-in | Manual |
| Production Ready | Demos | Yes | Yes |
| Customization | Low | Medium | High |
| Portability | None | Low | High |
Decision Tree
Section titled âDecision Treeâflowchart TD A[I need human-in-the-loop] --> B{What are you building?}
B -->|Claude Code skill| C[Use Claude Code<br/>AskUserQuestion] B -->|OpenAI-only app| D{Need approvals?} B -->|Multi-model app| E[Use Model Agnostic<br/>LangChain + OpenRouter] B -->|Web/mobile app| E
D -->|Yes| F[Use OpenAI<br/>Agents SDK] D -->|No| G[Use OpenAI<br/>Function Calling]
C --> H[Tutorial 2:<br/>Claude Code] F --> I[Tutorial 3:<br/>OpenAI SDK] G --> I E --> J[Tutorial 4:<br/>Model Agnostic]Architecture Comparison
Section titled âArchitecture ComparisonâClaude Code: Integrated
Section titled âClaude Code: Integratedâgraph TB U[User] --> CC[Claude Code CLI] CC --> C[Claude] C --> AUQ[AskUserQuestion<br/>Tool Call] AUQ --> CC CC --> UI[Auto UI Render] UI --> UCharacteristics:
- Single, integrated system
- No separation between agent and UI
- Automatic everything
- Least flexible, easiest to use
OpenAI: Semi-Integrated
Section titled âOpenAI: Semi-Integratedâgraph TB U[User] --> App[Your App] App --> OA[OpenAI API] OA --> GPT[GPT-4] GPT --> FC[Function Call] FC --> App App --> YUI[Your UI Layer] YUI --> UCharacteristics:
- Semi-integrated (SDK helps)
- Some separation (UI is yours)
- Manual UI implementation
- Medium flexibility, medium effort
Model-Agnostic: Fully Separated
Section titled âModel-Agnostic: Fully Separatedâgraph TB U[User] --> UI[UI Layer<br/>Pluggable] UI --> App[Application Layer] App --> LC[LangChain] LC --> OR[OpenRouter] OR --> M1[Claude] OR --> M2[GPT-4] OR --> M3[Gemini] OR --> M4[Llama]Characteristics:
- Fully separated layers
- Complete independence
- Maximum flexibility
- Most work, most control
Common Patterns
Section titled âCommon PatternsâPattern 1: Sequential Questions
Section titled âPattern 1: Sequential QuestionsâAsk questions one after another based on previous answers.
Example: Project setup wizard
- âWhat type of project?â â Web App
- âWhich framework?â â React
- âWhich styling?â â Tailwind CSS
Best implemented in:
- â All three approaches
- Easiest in Claude Code
- Most flexible in Model Agnostic
Pattern 2: Approval Gates
Section titled âPattern 2: Approval GatesâRequire confirmation before sensitive operations.
Example: Database operations
- âDelete 10,000 records?â
- âDeploy to production?â
- âSend email to all users?â
Best implemented in:
- â
OpenAI Agents SDK (built-in
needsApproval) - â ď¸ Manual in Claude Code
- â ď¸ Manual in Model Agnostic
Pattern 3: Conditional Branching
Section titled âPattern 3: Conditional BranchingâDifferent follow-up questions based on initial answer.
Example: Setup complexity
- Beginner â Use defaults, skip questions
- Intermediate â Ask key questions
- Advanced â Ask all configuration details
Best implemented in:
- â All three approaches
- Most elegant in Model Agnostic (full control)
Pattern 4: Multi-Select Features
Section titled âPattern 4: Multi-Select FeaturesâAllow users to select multiple non-exclusive options.
Example: Feature selection
- Select all that apply:
- â Authentication
- â Database
- â Email
- â Testing
Best implemented in:
- â
Claude Code (
multiSelect: true) - â OpenAI (custom logic)
- â Model Agnostic (custom logic)
Key Constraints Across All Approaches
Section titled âKey Constraints Across All Approachesâ1. Tool Calling Reliability
Section titled â1. Tool Calling ReliabilityâNot all models are equally good at tool calling:
| Model | Reliability | Notes |
|---|---|---|
| Claude (Anthropic) | 95%+ | Best-in-class |
| GPT-4 (OpenAI) | 95%+ | Very reliable |
| Gemini (Google) | 85%+ | Generally good |
| Llama 3 | 60-80% | Depends on fine-tuning |
| Mistral | 50-70% | Limited support |
Implication: Stick to Claude or GPT-4 for production systems.
2. UI Separation
Section titled â2. UI SeparationâOnly Claude Code has built-in UI. For everything else, you must:
- Implement your own UI layer
- Handle rendering logic
- Manage user input collection
- Validate responses
3. State Management
Section titled â3. State ManagementâPausing execution requires preserving conversation state:
- Message history must be maintained
- Tool calls must be tracked
- Answers must be properly formatted
- Context must flow back to the LLM
4. User Experience
Section titled â4. User ExperienceâConsider cognitive load:
- 2-4 options per question (max)
- 1-4 questions per interaction
- Clear descriptions for each option
- Progressive disclosure for complexity
Real-World Examples
Section titled âReal-World ExamplesâExample 1: Feature Development Assistant
Section titled âExample 1: Feature Development AssistantâScenario: Help developers implement new features by asking clarifying questions.
Best Approach: Model-Agnostic
- Needs to work with multiple LLMs
- Web UI for better collaboration
- Complex validation logic
- Integration with GitHub, Jira
Implementation:
- Tutorial 4: Model-Agnostic
- Web UI (Streamlit or React)
- LangChain for flexibility
- OpenRouter for model access
Example 2: Claude Code Skill
Section titled âExample 2: Claude Code SkillâScenario: Interactive database setup skill for Claude Code users.
Best Approach: Claude Code Built-in
- Target audience uses Claude Code
- Terminal UI is sufficient
- Want zero-setup experience
- Quick development
Implementation:
- Tutorial 2: Claude Code
- Use built-in
AskUserQuestion - Write skill in Markdown
- ~0 lines of code
Example 3: Deployment Assistant
Section titled âExample 3: Deployment AssistantâScenario: ChatGPT-based deployment tool with safety checks.
Best Approach: OpenAI Agents SDK
- OpenAI-only is acceptable
- Need built-in approvals
- Production deployments (high risk)
- Standardized flow
Implementation:
- Tutorial 3: OpenAI Agents SDK
- Use
needsApproval: true - Conditional approvals for prod
- ~50 lines of code
Getting Started
Section titled âGetting StartedâPath 1: Complete Beginner
Section titled âPath 1: Complete Beginnerâ- Start: Overview - Understand concepts
- Try: Claude Code - Simplest implementation
- Explore: Run the examples and modify them
- Advance: Try OpenAI or Model-Agnostic when needed
Path 2: OpenAI Developer
Section titled âPath 2: OpenAI Developerâ- Start: Overview - Understand landscape
- Deep Dive: OpenAI - Learn both approaches
- Implement: Choose Function Calling or Agents SDK
- Consider: Model-Agnostic for multi-provider support
Path 3: Production Engineer
Section titled âPath 3: Production Engineerâ- Start: Overview - Understand options
- Compare: Read all three implementation tutorials
- Decide: Based on requirements (single vs multi-provider)
- Implement: Model-Agnostic for maximum flexibility
Further Resources
Section titled âFurther ResourcesâOfficial Documentation
Section titled âOfficial Documentationâ- Claude Code Documentation
- OpenAI Function Calling
- OpenAI Agents SDK
- LangChain Documentation
- OpenRouter API
Related Patterns
Section titled âRelated Patternsâ- ReAct Pattern - Simple reasoning and acting loop
- Plan-Execute-Verify - Production-grade agent pattern
Community Resources
Section titled âCommunity Resourcesâ- Anthropic Cookbook
- OpenAI Cookbook
- LangChain Human-in-the-Loop Guide
- Prompt Engineering Guide - Function Calling
Need Help?
Section titled âNeed Help?â- Conceptual questions? â Start with Overview
- Claude Code specific? â See Claude Implementation
- OpenAI specific? â Check OpenAI Implementation
- Architecture questions? â Review Model-Agnostic Implementation
Ready to start? â Begin with the Overview to understand the fundamentals!