Closed darielnoel closed 1 month ago
Human in the Loop (HITL) is a core feature in AgenticJS that enables manual intervention and oversight in AI-driven tasks. It provides a mechanism for human operators to review, provide input, or make decisions at critical points in the workflow, ensuring accuracy, reliability, and ethical considerations in complex or sensitive operations.
The HITL feature addresses the need for human judgment in scenarios where:
Imagine a Kanban board for a software development team:
| To Do | In Progress | Code Review | Testing | Done |
|-------|-------------|-------------|---------|------|
| Task 1 | Task 2 | Task 3 | Task 4 | Task 5 |
| | | <Needs | | |
| | | Human | | |
| | | Review> | | |
In this scenario, Task 3 in the "Code Review" column requires human intervention. This is similar to how HITL works in AI workflows, where certain tasks need human input or validation before proceeding.
Task Creation: Tasks are created and can be flagged to require human validation.
AI Processing: AI agents work on tasks, moving them through different states (like "To Do" to "In Progress").
Human Intervention Points:
Feedback or Validation:
Feedback Processing:
Completion: Once validated, tasks move to the 'DONE' state.
This process ensures that human expertise is incorporated at crucial points, improving the overall quality and reliability of the AI-driven workflow.
This HITL workflow can be easily implemented using AgenticJS. The library provides methods and status to manage the entire process programmatically:
validateTask()
, provideFeedback()
, getTasksByStatus()
feedbackHistory
array, with entries consisting of:
content
: The human input or decisionstatus
: PENDING or PROCESSEDtimestamp
: When the feedback was created or last updatedHere's an example of how to set up and manage a HITL workflow using AgenticJS:
// Creating a task that requires validation
const task = new Task({
title: "Analyze market trends",
description: "Research and summarize current market trends for our product",
assignedTo: "Alice",
externalValidationRequired: true
});
// Set up the workflow status change listener before starting
team.onWorkflowStatusChange((status) => {
if (status === 'BLOCKED') {
// Check for tasks awaiting validation
const tasksAwaitingValidation = team.getTasksByStatus('AWAITING_VALIDATION');
tasksAwaitingValidation.forEach(task => {
console.log(`Task awaiting validation: ${task.title}`);
// Example: Automatically validate the task
team.validateTask(task.id);
// Alternatively, provide feedback if the task needs revision
// This could be based on human review or automated criteria
// team.provideFeedback(task.id, "Please include more data on competitor pricing.");
});
} else if (status === 'FINISHED') {
console.log('Workflow completed successfully!');
console.log('Final result:', team.getWorkflowResult());
}
});
// Start the workflow and handle the promise
team.start()
.then(result => {
console.log('Workflow completed with result:', result);
})
.catch(error => {
console.error('Workflow encountered an error:', error);
});
The system includes the following task statuses, which apply to all tasks throughout the entire workflow, including but not limited to HITL processes:
TODO
: Task is queued for initiation, awaiting processing.DOING
: Task is actively being worked on by an agent.BLOCKED
: Progress on the task is halted due to dependencies or obstacles.REVISE
: Task requires additional review or adjustments based on feedback.AWAITING_VALIDATION
: Task is completed but requires validation or approval.VALIDATED
: Task has been validated and confirmed as correctly completed.DONE
: Task is fully completed and requires no further action.These statuses are defined in the TASK_STATUS_enum
and can be accessed throughout the system for consistency.
Below is a text-based representation of the task state flow diagram:
+---------+
| TODO |
+---------+
|
v
+---------+
+--->| DOING |
| +---------+
| |
| +----+----+----+----+
| | | |
v v v v
+-------------+ +---------+ +------------------+
| BLOCKED | | REVISE | | AWAITING_ |
+-------------+ +---------+ | VALIDATION |
| | +------------------+
| | |
| | v
| | +--------------+
| | | VALIDATED |
| | +--------------+
| | |
| | v
+--------------+----------------+
|
v
+---------+
| DONE |
+---------+
TODO to DOING:
DOING to BLOCKED:
DOING to REVISE:
DOING to AWAITING_VALIDATION:
externalValidationRequired = true
.DOING to DONE:
AWAITING_VALIDATION to VALIDATED:
AWAITING_VALIDATION to REVISE:
VALIDATED to DONE:
REVISE to DOING:
BLOCKED to DOING:
Requiring External Validation:
externalValidationRequired: true
when creating a task to ensure it goes through human validation before completion.Initiating HITL:
team.provideFeedback(taskId, feedbackContent)
at any point to move a task to REVISE state.Validating Tasks:
team.validateTask(taskId)
to approve a task, moving it from AWAITING_VALIDATION to VALIDATED, then to DONE.team.provideFeedback(taskId, feedbackContent)
to request revisions, moving the task from AWAITING_VALIDATION to REVISE.Processing Feedback:
In AgenticJS, human interventions are implemented through a feedback system. Each task maintains a feedbackHistory
array to track these interactions.
Each feedback entry in the feedbackHistory
consists of:
content
: The human input or decisionstatus
: The current state of the feedbacktimestamp
: When the feedback was created or last updatedAgenticJS uses two primary statuses for feedback:
PENDING
: Newly added feedback that hasn't been addressed yetPROCESSED
: Feedback that has been successfully addressed and incorporatedThis structure allows for clear tracking of human interventions and their resolution throughout the task lifecycle.
import React, { useState, useEffect } from 'react';
import { team } from './teamSetup'; // Assume this is where your team is initialized
function WorkflowBoard() {
const [tasks, setTasks] = useState([]);
const [workflowStatus, setWorkflowStatus] = useState('');
const store = team.useStore();
useEffect(() => {
const unsubscribeTasks = store.subscribe(
state => state.tasks,
(tasks) => setTasks(tasks)
);
const unsubscribeStatus = store.subscribe(
state => state.teamWorkflowStatus,
(status) => setWorkflowStatus(status)
);
return () => {
unsubscribeTasks();
unsubscribeStatus();
};
}, []);
const renderTaskColumn = (status, title) => (
<div className="task-column">
<h2>{title}</h2>
{tasks.filter(task => task.status === status).map(task => (
<div key={task.id} className="task-card">
<h3>{task.title}</h3>
<p>{task.description}</p>
{status === 'AWAITING_VALIDATION' && (
<button onClick={() => store.getState().validateTask(task.id)}>
Validate
</button>
)}
<button onClick={() => store.getState().provideFeedback(task.id, "Sample feedback")}>
Provide Feedback
</button>
</div>
))}
</div>
);
return (
<div className="task-board">
<h1>Task Board - Workflow Status: {workflowStatus}</h1>
<div className="columns-container">
{renderTaskColumn('TODO', 'To Do')}
{renderTaskColumn('DOING', 'In Progress')}
{renderTaskColumn('BLOCKED', 'Blocked')}
{renderTaskColumn('AWAITING_VALIDATION', 'Waiting for Feedback')}
{renderTaskColumn('DONE', 'Done')}
</div>
<button onClick={() => store.getState().startWorkflow()}>Start Workflow</button>
</div>
);
}
export default WorkflowBoard;
By implementing Human in the Loop through AgenticJS's feedback and validation system, you can create a more robust, ethical, and accurate task processing workflow. This feature ensures that critical decisions benefit from human judgment while maintaining the efficiency of automated processes for routine operations.
Implement Human in the Loop (HITL) support to allow for manual intervention in tasks that require human oversight. This feature will enable tasks within AgenticJS to be paused or flagged for human review, ensuring that certain operations benefit from human judgment before proceeding.
Problem to Solve: Certain tasks handled by AI agents can reach a complexity or sensitivity level that automated processes alone may not adequately address. By introducing HITL, we can ensure that such tasks are handled correctly, maintaining a high level of accuracy and reliability.
Advantages of HITL Support:
Goals:
Implementation Steps:
Testing:
Documentation:
Community Engagement:
This initiative aims to make AgenticJS more versatile and trustworthy by integrating human intelligence where it is most beneficial.