bluefly/ai_agent_crewai

Integrates CrewAI as an AI agent system with multi-agent orchestration and analytics

dev-main 2025-07-09 18:28 UTC

This package is auto-updated.

Last update: 2025-07-09 18:31:06 UTC


README

Integrates CrewAI as an AI agent system with multi-agent orchestration and analytics for Drupal.

Overview

The CrewAI Agent module provides a comprehensive integration of CrewAI's multi-agent framework into Drupal, enabling the creation and management of AI agent crews that can work together on complex tasks through role-based coordination.

Features

  • Multi-Agent Orchestration: Create crews of specialized AI agents with distinct roles and goals
  • Role-Based Agent System: Define agents with specific capabilities and responsibilities
  • Task Delegation: Automatic distribution of tasks among crew members
  • Python Bridge Integration: Seamless integration with CrewAI's Python library
  • Workflow Builder: Visual interface for composing and managing agent crews
  • ECA Integration: Event-Condition-Action workflow support for automated agent triggers
  • Performance Monitoring: Track agent performance and task completion metrics
  • Key Management: Secure API key storage and management

Requirements

  • Drupal 10.3 or higher / Drupal 11
  • PHP 8.1 or higher
  • Python 3.8+ (for CrewAI bridge)
  • Node.js 16+ (for async communication server)
  • AI module (drupal/ai) ^1.2
  • Key module (drupal/key) ^1.20

Installation

  1. Install via Composer:

    composer require bluefly/ai_agent_crewai
    
  2. Enable the module:

    drush en ai_agent_crewai
    
  3. Set up the Python environment:

    cd web/modules/custom/ai_agent_crewai
    ./setup.sh
    
  4. Start the Node.js bridge server:

    node nodejs/server.js
    

Configuration

  1. Navigate to Configuration > AI > CrewAI Settings (/admin/config/ai/crewai)
  2. Configure your API keys (OpenAI, Anthropic, etc.)
  3. Set up agent templates and default crews
  4. Configure task execution parameters

Usage

Creating a Crew Programmatically

$orchestrator = \Drupal::service('ai_agent_crewai.orchestrator');

// Define agents
$agents = [
  [
    'role' => 'researcher',
    'goal' => 'Find accurate and relevant information',
    'backstory' => 'Expert at analyzing data and finding insights'
  ],
  [
    'role' => 'writer',
    'goal' => 'Create engaging and informative content',
    'backstory' => 'Skilled content creator with attention to detail'
  ],
  [
    'role' => 'editor',
    'goal' => 'Ensure quality and accuracy',
    'backstory' => 'Meticulous editor with high standards'
  ]
];

// Define tasks
$tasks = [
  'Research Drupal 11 features and improvements',
  'Write a comprehensive blog post about the findings',
  'Edit and polish the content for publication'
];

// Create and execute crew
$crew = $orchestrator->createCrew([
  'agents' => $agents,
  'tasks' => $tasks
]);

$result = $orchestrator->executeCrew($crew);

Using the Workflow Builder

  1. Navigate to Structure > CrewAI Workflows (/admin/structure/crewai/workflows)
  2. Click "Add Workflow" to create a new agent crew
  3. Define agents with roles, goals, and backstories
  4. Create tasks and assign them to agents
  5. Save and execute the workflow

Drush Commands

# Execute a predefined crew
drush crewai:execute-crew content_creation

# List available crews
drush crewai:list-crews

# Monitor crew execution
drush crewai:monitor [crew-id]

ECA Integration

The module provides several ECA plugins for workflow automation:

Actions

  • Orchestrate Crew: Execute a CrewAI crew
  • Intelligent Crew Execution: Smart task routing with agent selection
  • AI Content Enhancement: Enhance content using agent crews
  • Dynamic Agent Discovery: Discover and utilize available agents

Events

  • Agent Performance Threshold: Triggered when agent performance metrics cross thresholds

Conditions

  • Agent Capability Match: Check if agents match required capabilities

API Endpoints

The module exposes REST endpoints for crew management:

  • GET /api/crewai/crews - List all crews
  • POST /api/crewai/crews - Create a new crew
  • GET /api/crewai/crews/{id} - Get crew details
  • POST /api/crewai/crews/{id}/execute - Execute a crew
  • GET /api/crewai/crews/{id}/status - Get execution status

Development

Running Tests

# PHP Unit tests
./vendor/bin/phpunit web/modules/custom/ai_agent_crewai

# Python tests
cd web/modules/custom/ai_agent_crewai
python -m pytest tests/

Debugging

Enable debug mode in settings:

$settings['ai_agent_crewai.debug'] = TRUE;

Check logs at:

  • Drupal: /admin/reports/dblog
  • Python bridge: python/logs/crewai_bridge.log
  • Node.js server: nodejs/logs/server.log

Troubleshooting

Common Issues

  1. Python Bridge Connection Failed

    • Ensure Python environment is activated
    • Check python/requirements.txt dependencies
    • Verify Python path in module settings
  2. Node.js Server Not Responding

    • Check if port 3000 is available
    • Review Node.js server logs
    • Ensure all npm dependencies are installed
  3. Agent Execution Timeouts

    • Increase timeout in crew settings
    • Check API rate limits
    • Monitor agent performance metrics

Support

License

This project is licensed under the GPL-2.0-or-later license.