Workflow Resume Commands
AgentMap provides functionality to resume interrupted workflows, allowing you to handle user interventions, approvals, or recovery from errors. This is particularly useful for workflows that require human oversight or complex decision points.
Resume Command
The resume
command allows you to continue an interrupted workflow by providing a thread ID and response data.
agentmap resume <thread_id> <response> [OPTIONS]
Arguments:
thread_id
: Thread ID to resume (required)response
: Response action (approve, reject, choose, respond, edit) (required)
Options:
--data
,-d
: Additional data as JSON string--data-file
,-f
: Path to JSON file containing additional data--config
,-c
: Path to custom config file
Example Usage
# Resume a workflow with approval
agentmap resume thread_12345 approve
# Resume with additional data
agentmap resume thread_12345 respond --data '{"user_response": "Yes, proceed with the order"}'
# Resume with data from a file
agentmap resume thread_12345 choose --data-file response_data.json
# Resume with custom configuration
agentmap resume thread_12345 edit --data '{"edited_content": "Updated text"}' --config custom_config.yaml
Response Types
The resume
command supports several response types:
1. Approve/Reject
Used for simple approval workflows:
# Approve the pending action
agentmap resume thread_12345 approve
# Reject the pending action
agentmap resume thread_12345 reject --data '{"reason": "Budget exceeded"}'
2. Choose
Used when the workflow presents multiple options:
# Choose an option by ID
agentmap resume thread_12345 choose --data '{"choice": "option_2"}'
# Choose with additional context
agentmap resume thread_12345 choose --data '{"choice": "option_3", "notes": "Preferred due to cost"}'
3. Respond
Used for providing free-form responses:
# Provide a text response
agentmap resume thread_12345 respond --data '{"response": "The proposed solution looks good"}'
# Respond with structured data
agentmap resume thread_12345 respond --data '{"response": "Approved", "additional_requirements": ["Feature A", "Feature B"]}'
4. Edit
Used for editing content generated by the workflow:
# Edit generated content
agentmap resume thread_12345 edit --data '{"edited_content": "This is the revised version of the text."}'
# Edit with formatting options
agentmap resume thread_12345 edit --data '{"edited_content": "New content", "format": "markdown"}'
Using Data Files
For complex responses, it's often easier to use a JSON file:
# Create a data file
cat > response_data.json << EOF
{
"choice": "option_2",
"feedback": "This option aligns better with our requirements",
"additional_parameters": {
"priority": "high",
"deadline": "2023-05-15",
"assigned_to": "engineering_team"
}
}
EOF
# Resume with the data file
agentmap resume thread_12345 choose --data-file response_data.json
How Workflow Resumption Works
-
Interruption Point: Workflows can be designed with interruption points using the
HumanInTheLoop
agent or similar mechanisms. -
Thread ID Generation: When a workflow reaches an interruption point, it generates a unique thread ID and waits for a response.
-
State Persistence: The current state of the workflow is saved, including all variables and context.
-
Resume Command: When you run the
resume
command with the thread ID and response, the workflow loads the saved state and continues execution with the provided response data. -
Response Integration: The response data is integrated into the workflow state and available to subsequent nodes.
Example: Approval Workflow
Here's a simple example of how to create a workflow with an approval step:
ApprovalFlow,start,,Start the approval workflow,Input,validate_request,,request,request_data,Process request: {request}
ApprovalFlow,validate_request,request_approval|reject_invalid,Validate the request data,Function,,,request_data,is_valid,
ApprovalFlow,reject_invalid,,Handle invalid requests,Output,,,is_valid,rejection_message,Request rejected: Invalid format
ApprovalFlow,request_approval,,Request approval from human,HumanInTheLoop,end,,request_data,approval_result,Please review this request: {request_data}
ApprovalFlow,end,,Complete the workflow,Output,,,approval_result,final_message,Request processed with result: {approval_result}
In this workflow:
- The
request_approval
node uses theHumanInTheLoop
agent to pause execution - The workflow will provide a thread ID when it reaches this node
- You can resume the workflow using:
# Approve the request
agentmap resume thread_12345 approve
# Or reject with a reason
agentmap resume thread_12345 reject --data '{"reason": "Budget limit exceeded"}'
Best Practices for Resumable Workflows
-
Design for Interruptions: Identify natural points in your workflow where human input might be valuable.
-
Clear Thread ID Communication: Ensure thread IDs are communicated clearly to the people who need to respond.
-
Timeout Handling: Consider implementing timeout handling for workflows that don't receive responses within a certain timeframe.
-
Response Validation: Validate response data to ensure it meets the expected format and requirements.
-
Audit Trail: Keep a log of all resume actions for audit and troubleshooting purposes.
Security Considerations
-
Thread ID Protection: Treat thread IDs as sensitive information, as they provide access to resume workflows.
-
Authentication: Consider implementing additional authentication for resume operations in production environments.
-
Data Validation: Always validate response data to prevent injection attacks or other security issues.
-
Access Control: Implement appropriate access controls to determine who can resume specific workflows.
Related Documentation
- CLI Commands Reference: Complete list of all CLI commands
- Human-in-the-Loop Agents: Documentation for the HumanInTheLoop agent
- State Persistence: How workflow state is saved and restored
- Approval Workflow Example: Complete example of an approval workflow