Overview
Concrete tool for intercepting agent execution within workflows to request human approval, rejection, or input before or after the target action runs.
Description
The HITLInterceptorAgent class extends HITLBaseAgent (which extends Agent) to create a specialized agent that intercepts another agent's action. Upon construction, it creates a HITLInterceptorAction (for `PRE_EXECUTION` mode) or `HITLPostExecutionAction` (for `POST_EXECUTION` mode) that calls `hitl_manager.request_approval()` during workflow execution. The agent name is auto-generated from the target agent/action names and mode.
Usage
- HITL workflow: Create an interceptor agent targeting a specific agent/action, add it as a node in the workflow graph, and pass an active `HITLManager` to `WorkFlow`.
- Pre-execution approval: Use `mode=HITLMode.PRE_EXECUTION` to require human approval before an action runs.
- Post-execution review: Use `mode=HITLMode.POST_EXECUTION` to review results after an action completes.
Code Reference
Source Location
- Repository: EvoAgentX
- File: evoagentx/hitl/interceptor_agent.py (L13-299)
Signature
class HITLInterceptorAgent(HITLBaseAgent):
def __init__(
self,
target_agent_name: str,
target_action_name: str,
name: str = None,
interaction_type: HITLInteractionType = HITLInteractionType.APPROVE_REJECT,
mode: HITLMode = HITLMode.PRE_EXECUTION,
**kwargs
)
def get_hitl_agent_name(self) -> str
class HITLInterceptorAction(Action):
def __init__(
self,
target_agent_name: str,
target_action_name: str,
name: str = None,
interaction_type: HITLInteractionType = HITLInteractionType.APPROVE_REJECT,
mode: HITLMode = HITLMode.PRE_EXECUTION,
**kwargs
)
async def async_execute(self, llm, inputs: dict, hitl_manager: HITLManager, sys_msg: str = None, **kwargs) -> Tuple[dict, str]
Import
from evoagentx.hitl.interceptor_agent import HITLInterceptorAgent
from evoagentx.hitl.hitl import HITLInteractionType, HITLMode
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| target_agent_name |
str |
Yes |
Agent to intercept
|
| target_action_name |
str |
Yes |
Action to intercept
|
| interaction_type |
HITLInteractionType |
No |
APPROVE_REJECT (default), REVIEW_EDIT_STATE, etc.
|
| mode |
HITLMode |
No |
PRE_EXECUTION (default) or POST_EXECUTION
|
Outputs
| Name |
Type |
Description
|
| async_execute returns |
Result dict (hitl_decision, target agent/action, feedback) and prompt
|
Usage Examples
Intercept Agent in Workflow
from evoagentx.hitl.interceptor_agent import HITLInterceptorAgent
from evoagentx.hitl.approval_manager import HITLManager
from evoagentx.hitl.hitl import HITLInteractionType, HITLMode
from evoagentx.workflow.workflow_graph import WorkFlowNode, WorkFlowEdge, WorkFlowGraph
from evoagentx.workflow.workflow import WorkFlow
# 1. Create interceptor agent targeting a specific agent/action
interceptor = HITLInterceptorAgent(
target_agent_name="Summarizer",
target_action_name="Summarizer action",
interaction_type=HITLInteractionType.APPROVE_REJECT,
mode=HITLMode.PRE_EXECUTION,
)
# 2. Add to workflow graph as a node between producer and consumer
hitl_node = WorkFlowNode(
name="approval_checkpoint",
description="Human approval for summarization",
inputs=[...], # match predecessor outputs
outputs=[...], # match successor inputs
agents=[interceptor.get_hitl_agent_name()],
)
# 3. Activate HITL and execute
hitl_manager = HITLManager()
hitl_manager.activate()
agent_manager.add_agent(interceptor)
workflow = WorkFlow(graph=graph, llm=llm, agent_manager=agent_manager, hitl_manager=hitl_manager)
result = workflow.execute(inputs={...})
Related Pages
Implements Principle
Requires Environment