This guide demonstrates how to test the approval activity feature with two test agents that showcase different workflow patterns.
- Purpose: Demonstrates human approval workflow for database operations
- Tools:
get_db_schema(no approval needed)execute_sql_query(requires human approval)execute_python(requires human approval)
- Activity Type: Human approval (agent-owned)
- Timeout: 1 hour for approvals
- Purpose: Demonstrates remote execution workflow for local automation
- Tools:
local_agent(remote execution via activity)
- Activity Type: Remote execution (tool-owned)
- Timeout: 5 minutes for remote operations
# Activate virtual environment
source cpython-3.12.3-macos-aarch64-none/bin/activate
# Configure AWS credentials
assume CGI-PoC
# Deploy test agents and dependencies
python test_approval_agents.py deployThis will deploy:
- Shared infrastructure (LLM services, registries)
- Required tool stacks (DB Interface, E2B, Local Automation)
- Both test agents with their approval activities
In a separate terminal, start the activity workers:
# For human approval testing
python activity_worker.py approval
# For remote execution testing
python activity_worker.py remote
# For both (runs in separate threads)
python activity_worker.py both# Test SQL approval workflow
python test_approval_agents.py test-sql
# Test remote execution workflow
python test_approval_agents.py test-remote
# Run both tests
python test_approval_agents.py test-
Start the SQL approval agent test:
python test_approval_agents.py test-sql
-
Expected Flow:
User Request → LLM → get_db_schema (executes immediately) → execute_sql_query (waits for approval) -
Approval Worker Response: The worker will display:
🔔 HUMAN APPROVAL REQUIRED Tool: execute_sql_query Agent: test-sql-approval-agent Tool Input: {"sql_query": "SELECT COUNT(*) FROM table_name"} 🤔 Approve this request? (y/n/details): -
Test Scenarios:
- Approve: Enter
y, provide reviewer info, see SQL execution - Reject: Enter
n, provide rejection reason, see feedback to LLM - Details: Enter
detailsto see full request context
- Approve: Enter
-
Start the remote execution agent test:
python test_approval_agents.py test-remote
-
Expected Flow:
User Request → LLM → local_agent (sent to remote activity) → Remote Worker executes → Returns result -
Remote Worker Response: The worker will display:
🚀 REMOTE EXECUTION REQUEST Tool: local_agent Execution Input: {"script": {"action": "open_text_editor"}} 🎯 Execution result (s=success, f=failure, c=custom): -
Test Scenarios:
- Success: Enter
s, provide output, see successful completion - Failure: Enter
f, provide error message, see error handling - Custom: Enter
c, provide JSON response for complex scenarios
- Success: Enter
The approval workflows generate these Step Functions states:
{% raw %}
{
"Request Approval execute_sql_query": {
"Type": "Task",
"Resource": "arn:aws:states:::activity:test-sql-approval-agent-approval-activity-prod",
"TimeoutSeconds": 3600,
"Next": "Check Approval execute_sql_query"
},
"Check Approval execute_sql_query": {
"Type": "Choice",
"Choices": [{"Condition": "{% $states.result.approved = true %}", "Next": "Execute execute_sql_query"}],
"Default": "Handle Rejection execute_sql_query"
}
}{% endraw %}
{
"Execute Remote local_agent": {
"Type": "Task",
"Resource": "arn:aws:states:::activity:local-automation-remote-activity-prod",
"TimeoutSeconds": 300,
"Catch": [{"ErrorEquals": ["States.Timeout"], "Next": "Remote Timeout local_agent"}]
}
}{
"tool_name": "execute_sql_query",
"tool_use_id": "tool_123456789",
"tool_input": {"sql_query": "SELECT * FROM users LIMIT 10"},
"agent_name": "test-sql-approval-agent",
"timestamp": "2025-01-15T10:30:00.000Z",
"context": {
"execution_name": "test-sql-approval-12345",
"state_machine": "test-sql-approval-agent-prod"
}
}{
"approved": true,
"reviewer": "john.doe@company.com",
"timestamp": "2025-01-15T10:32:00.000Z",
"review_notes": "Query looks safe for testing"
}{
"approved": false,
"rejection_reason": "Missing WHERE clause - could return too much data",
"reviewer": "security@company.com",
"timestamp": "2025-01-15T10:33:00.000Z",
"review_notes": "Add LIMIT or WHERE clause for safety"
}python test_approval_agents.py status-
Step Functions Console:
- View execution graphs and state transitions
- Monitor approval workflow states
- Check timeout and error handling
-
CloudWatch Logs:
- Agent execution logs:
/aws/stepfunctions/test-*-agent-prod - Lambda function logs for tool execution
- Agent execution logs:
-
Activities Console:
- Monitor activity task polling
- Check worker heartbeats
- View task completion rates
- Activities Not Found: Ensure tool stacks are deployed before agents
- Timeout Errors: Check that activity workers are running
- Permission Errors: Verify IAM roles have activity permissions
- Activity ARN Mismatches: Check exports are correctly imported
Test different approval patterns by modifying the worker responses:
# In activity_worker.py, modify the approval response
response = {
"approved": True,
"reviewer": "custom-tester@company.com",
"timestamp": datetime.now().isoformat(),
"review_notes": "Custom approval for specific test scenario",
"approval_conditions": ["add_limit_clause", "log_query"]
}Test complex remote execution scenarios:
# Simulate partial success
response = {
"type": "tool_result",
"tool_use_id": task_data.get('tool_use_id'),
"name": "local_agent",
"content": {
"status": "partial_success",
"output": "Task completed with warnings",
"warnings": ["Screenshot capture failed", "Window focus timeout"],
"execution_time_ms": 3500
}
}- Activity Workers: Deploy as containerized services or Lambda functions
- Approval UI: Build web interface for human reviewers
- Activity Monitoring: Set up CloudWatch alarms for activity timeouts
- Security: Implement proper authentication for approval workflows
For production, consider:
- Multiple worker instances for high availability
- Load balancing across worker pools
- Automatic scaling based on activity task volume
- Worker health monitoring and alerting
This testing framework provides a solid foundation for validating approval workflows before production deployment.