Spaces:
Sleeping
Download docs/implementation/HITL_COMPLETE_IMPLEMENTATION_GUIDE.md from CoreModelsResearch/DAO: direct link, hf CLI and curl.
- Browser
- Download file 7.11 kB
-
https://huggingface.co/spaces/CoreModelsResearch/DAO/resolve/main/docs/implementation/HITL_COMPLETE_IMPLEMENTATION_GUIDE.md
- Command line
-
hf download hf://spaces/CoreModelsResearch/DAO/docs/implementation/HITL_COMPLETE_IMPLEMENTATION_GUIDE.md
-
curl -L -o HITL_COMPLETE_IMPLEMENTATION_GUIDE.md https://huggingface.co/spaces/CoreModelsResearch/DAO/resolve/main/docs/implementation/HITL_COMPLETE_IMPLEMENTATION_GUIDE.md
HITL Integration & Deduplication - Complete Implementation Summary
Overview
Successfully implemented HITL (Human-In-The-Loop) checkpoint recording in trace.json with proper deduplication and status display in the observatory UI.
Two-Part Implementation
Part 1: HITL Step Recording (graph.py)
File: src/data_agent_baseline/langgraph_agent/graph.py
New Function: _record_hitl_step()
- Records human decisions as formal steps in state.steps
- Captures full checkpoint lifecycle with all context
- Makes HITL decisions part of the permanent trace
Integration Points: 4 decision paths
- Approve decision
- Cancel decision
- Revise decision (with human steering)
- Timeout auto-approve
Result: HITL steps now appear in trace.json for audit trail
Part 2: Deduplication & Status Display (guided_trace_flow_page.py)
File: src/data_agent_baseline/observatory/guided_trace_flow_page.py
Modified Function: _build_guided_replay_rows()
Changes:
- Filter Duplicates: Skip planner_review steps from trace.json
- Consolidate: Use checkpoint_state for single entry
- Extract Decision: Get intervention.decision from checkpoint_state
- Enhance Display:
- Action field: "approve • approve" (decision shown)
- Story label: "human-review · approved" (status shown)
- Remove Event Merging: No longer merge individual HITL events
Result: Single consolidated HITL entry with clear status in Live/Replay
Data Flow
HITL Checkpoint Lifecycle
│
├─ Create Checkpoint (Step N)
│ └─ _record_hitl_step() called
│ └─ Step recorded: "planner_review" action
│ └─ Saved to trace.json["steps"]
│
├─ Human Decision (approve/revise/cancel/timeout)
│ └─ Intervention record created
│ └─ Saved to checkpoints/ and interventions/ dirs
│
├─ Observatory Display (Live/Replay)
│ └─ Load trace.json steps
│ ├─ Filter: Skip "planner_review" steps (duplicates)
│ ├─ Load: checkpoint_state from artifacts
│ └─ Display: Single entry with status
│ └─ "Step N.5 · human-review · approved"
│
└─ Archive (trace.json)
├─ Contains full HITL step for audit
├─ Original plan captured
├─ Revised plan (if applicable)
└─ Human instruction (if applicable)
Before vs After
Before (Issue)
Step 7 [planner] - Generate execution plan
Step 7.5 [awaiting-human-input] - Planning checkpoint reached
Step 8.0 [Human review checkpoint] - Human-in-the-loop checkpoint review ← DUPLICATE
Step 9 [critic_plan] - Validate execution plan
After (Fixed)
Step 7 [planner] - Generate execution plan
Step 7.5 [human-review · approved] - Checkpoint approved by human ← SINGLE ENTRY
Step 9 [critic_plan] - Validate execution plan
Display Examples
Example 1: Approved Decision
Story Label: "human-review · approved"
Action: "approve • approve"
Status: "completed"
Evidence: "Checkpoint approved. Resuming execution."
Example 2: Revised Decision
Story Label: "human-review · revised"
Action: "revise • revise"
Status: "completed"
Evidence: "Revision submitted and replanning completed..."
Example 3: Cancelled Decision
Story Label: "human-review · cancelled"
Action: "cancel • cancel"
Status: "completed"
Evidence: "Task cancelled by human at planner checkpoint."
Example 4: Auto-Approved by Timeout
Story Label: "human-review · auto-approved"
Action: "auto_approved_timeout • timeout_auto_approve"
Status: "completed"
Evidence: "No human response received. Plan auto-approved by timeout policy."
Technical Details
Step Structure (trace.json)
{
"step_index": 7.5,
"action": "planner_review",
"phase": "planner_review",
"thought": "Human-in-the-loop checkpoint review (checkpoint_id=cp_...)",
"action_input": {
"checkpoint_id": "cp_...",
"decision": "approve"
},
"observation": {
"ok": true,
"content": {
"checkpoint_id": "cp_...",
"decision": "approve",
"message": "Checkpoint approved. Resuming execution.",
"original_plan": { /* ... */ },
"revised_plan": { /* ... */ },
"human_instruction": "...",
"timeout_seconds": 60,
"default_action_on_timeout": "continue"
}
},
"ok": true
}
Replica Rows (Observatory Display)
{
"node_id": "checkpoint:cp_...",
"step_index": 7.5,
"story_label": "human-review · approved",
"action": "approve • approve",
"phase": "planner_review",
"status": "completed",
"observation_summary": "Checkpoint approved. Resuming execution.",
"key_values": "checkpoint_id=cp_...",
"action_input": { /* original_plan */ },
}
Backward Compatibility
✅ Fully compatible:
- Non-HITL runs unaffected
- Existing trace structure preserved
- No changes to run_events.jsonl format
- Existing visualization tools work
- HITL events still emitted as before
Files Modified
graph.py (Lines +64 to implement _record_hitl_step + 4 call sites)
- New helper function for recording HITL steps
- Called at approve, cancel, revise, and timeout paths
guided_trace_flow_page.py (Lines ~437-498 updated)
- Filter duplicate HITL steps from trace.json
- Consolidate via checkpoint_state
- Display decision in action and status in story_label
- Remove event-based HITL row merging
Testing Recommendations
Verify trace.json contains HITL steps
jq '.steps[] | select(.action == "planner_review")' trace.jsonVerify Live/Replay shows single entry
# Observable in streamlit observatory app # Should see "Step N.5 · human-review · approved" (one entry)Verify decision status is displayed
- Check story_label contains decision: "human-review · approved"
- Check action field shows decision: "approve • approve"
Test different decision types
- Approve, Revise, Cancel, Timeout-Auto-Approve
- Each should display with appropriate status
Benefits
Complete Audit Trail
- HITL decisions captured in permanent trace
- Full context preserved (original plan, revision, instruction)
Clear UI/UX
- Single consolidated checkpoint entry
- Status visible in story label
- Decision visible in action field
- No confusing duplicates
Easy Review
- Human reviewers see one clear entry
- Decision immediately visible
- Full context available on inspection
Better Analysis
- Trace contains all HITL interactions
- Easy to query decision patterns
- Supports compliance/audit requirements
Future Enhancements
- Add comparison view between original and revised plans
- Timeline visualization of checkpoint interactions
- Export HITL decisions for audit reports
- Analytics on human intervention patterns
- Integration with approval workflow systems