Skip to content

Conversation

TerminallyLazy
Copy link
Contributor

🤖➡️👤 HumanLayer Human-in-the-Loop Integration

Summary

This PR adds complete HumanLayer integration to Agent Zero, enabling human-in-the-loop workflows for approvals, consultations, and multi-channel communication. The integration follows Agent Zero's
architectural patterns and provides a seamless user experience through the Settings UI.

Features Added

🔧 Core Integration

  • HumanLayer SDK Integration: Added humanlayer>=0.3.0 dependency with AsyncHumanLayer client support
  • HumanLayerClient Wrapper: Comprehensive client wrapper handling configuration, validation, and error management
  • Conditional Loading: Extension system only loads HumanLayer tools when humanlayer_enabled=True

🛠️ Tools Implementation

  • Approval Tool (humanlayer_approval.py): Request human approval for potentially risky operations
  • Consultation Tool (humanlayer_consultation.py): Ask humans questions with context for decision-making
  • Contact Management Tool (humanlayer_contact.py): Validate and manage communication channels
  • Enhanced Code Execution: Automatic approval requests for high-risk code operations

⚙️ Settings UI Integration

  • Complete Settings Panel: 11 configuration fields in External Services tab
  • User-Friendly Interface: Toggles, dropdowns, password fields, and number inputs
  • Multi-Channel Support: Slack and Email configuration with validation
  • API Endpoints: Configuration validation and testing endpoints
  • Visual Elements: Custom HumanLayer icon and proper UI integration

🏗️ Architecture Compliance

  • Agent Zero Patterns: All tools extend Tool base class and use Response objects
  • Async/Await Support: Full async compatibility throughout the integration
  • Extension System: Uses Agent Zero's lifecycle hooks for conditional functionality
  • Configuration Flow: Settings automatically flow from UI to agent's additional config
  • Graceful Fallbacks: Proper error handling when HumanLayer is disabled or misconfigured

Configuration

Users can configure HumanLayer through Settings → External Services with:

Core Settings:

  • Enable/disable integration toggle
  • API key (password field)
  • Default contact channel selection
  • Approval timeout configuration
  • Verbose logging toggle

Channel Configuration:

  • Slack: Channel ID, context description, Block Kit support
  • Email: Address, subject line, context description

Usage Examples

Once configured, HumanLayer automatically integrates into Agent Zero workflows:

# Automatic approval for risky operations
agent.execute_code("rm -rf /tmp/old_files")  # → Requests human approval

# Manual consultation requests
agent.consult_human("Should I proceed with database migration?")

# Approval workflows
agent.request_approval("Delete 1000 old log entries", context="Disk cleanup")

Testing

-Comprehensive unit test suite for all tools and integrations
-Integration tests validating end-to-end functionality
-Configuration validation and error handling tests
-Syntax and type checking validation
-API endpoint testing for validation and testing features

Files Changed

Core Integration:
- requirements.txt - Added HumanLayer dependency
- python/helpers/humanlayer_client.py - HumanLayer SDK wrapper
- python/tools/humanlayer_*.py - Three main tools (approval, consultation, contact)
- python/tools/code_execution_tool.py - Enhanced with auto-approval

Extensions:
- python/extensions/system_prompt/_30_humanlayer_prompts.py - Conditional prompt loading
- python/extensions/before_main_llm_call/_15_humanlayer_check.py - Pre-execution monitoring

Settings Integration:
- python/helpers/settings.py - Added HumanLayer settings schema and UI fields
- initialize.py - Pass HumanLayer settings to agent configuration
- python/api/humanlayer_validate.py - Configuration validation endpoint
- python/api/humanlayer_test.py - Tool testing endpoint

UI Components:
- webui/public/humanlayer.svg - HumanLayer icon
- agents/agent0/prompts/agent.system.tool.humanlayer_*.md - Tool prompt files

Testing:
- tests/test_humanlayer_*.py - Comprehensive test suite

Breaking Changes

None. This is a purely additive feature that doesn't affect existing functionality when disabled.

Migration Notes

No migration required. The integration is disabled by default and can be enabled through the Settings UI.

---
🎉 Ready for human-in-the-loop AI workflows! This integration brings human oversight and collaboration directly into Agent Zero's autonomous operations.

  - Add HumanLayer SDK dependency (>=0.3.0) to requirements.txt
  - Create HumanLayerClient wrapper for configuration and validation
  - Implement three core tools: approval, consultation, and contact management
  - Add conditional extension system for tool loading and pre-execution checks
  - Enhance code execution tool with automatic approval for high-risk operations
  - Create comprehensive settings UI integration with 11 configuration fields
  - Add API endpoints for configuration validation and testing
  - Include proper Agent Zero patterns: Tool base class, Response objects, async support
  - Add HumanLayer settings to External Services tab in Settings UI
  - Create icon and visual elements for settings integration
  - Implement graceful fallbacks and error handling throughout
  - Add comprehensive test suite covering all integration points

  The integration enables human oversight workflows for approvals, consultations,
  and multi-channel communication while maintaining full compatibility with
  Agent Zero's existing architecture and following established patterns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant