diff --git a/agents/management/commands/populate_agents.py b/agents/management/commands/populate_agents.py new file mode 100644 index 0000000..c25b220 --- /dev/null +++ b/agents/management/commands/populate_agents.py @@ -0,0 +1,106 @@ +from django.core.management.base import BaseCommand +from django.core.management import call_command +import os + + +class Command(BaseCommand): + help = 'Populate all agents in the database - calls all individual agent creation commands' + + def add_arguments(self, parser): + parser.add_argument( + '--force', + action='store_true', + help='Force recreation of agents even if they exist', + ) + parser.add_argument( + '--skip-existing', + action='store_true', + help='Skip agents that already exist (default behavior)', + ) + + def handle(self, *args, **options): + self.stdout.write("šŸ¤– Starting agent population process...") + + # List of all agent creation commands + agent_commands = [ + 'create_social_ads_agent', + 'create_job_posting_agent', + 'create_pdf_summarizer_agent', + 'create_five_whys_agent', + 'create_cybersec_career_agent', + ] + + success_count = 0 + error_count = 0 + + for command_name in agent_commands: + try: + self.stdout.write(f"\nšŸ“¦ Running {command_name}...") + + # Pass through options to individual commands + command_options = {} + if options.get('force'): + command_options['force'] = True + + # Call the individual agent creation command + call_command(command_name, **command_options) + + success_count += 1 + self.stdout.write(f"āœ… {command_name} completed successfully") + + except Exception as e: + error_count += 1 + self.stdout.write( + self.style.ERROR(f"āŒ {command_name} failed: {str(e)}") + ) + + # Continue with other commands even if one fails + continue + + self.stdout.write(f"\nšŸŽÆ Agent population summary:") + self.stdout.write(f"āœ… Successful: {success_count}") + self.stdout.write(f"āŒ Failed: {error_count}") + self.stdout.write(f"šŸ“Š Total commands: {len(agent_commands)}") + + if error_count == 0: + self.stdout.write(self.style.SUCCESS("\nšŸŽ‰ All agents populated successfully!")) + else: + self.stdout.write(self.style.WARNING(f"\nāš ļø {error_count} commands failed. Check logs above.")) + + # Show final agent count + try: + from agents.models import Agent, AgentCategory + + total_categories = AgentCategory.objects.count() + total_agents = Agent.objects.count() + active_agents = Agent.objects.filter(is_active=True).count() + + self.stdout.write(f"\nšŸ“ˆ Database Summary:") + self.stdout.write(f"šŸ·ļø Categories: {total_categories}") + self.stdout.write(f"šŸ¤– Total Agents: {total_agents}") + self.stdout.write(f"⚔ Active Agents: {active_agents}") + + if active_agents > 0: + self.stdout.write(f"\nšŸ”— Agents by category:") + categories = AgentCategory.objects.all() + for category in categories: + agent_count = Agent.objects.filter(category=category, is_active=True).count() + if agent_count > 0: + self.stdout.write(f" {category.icon} {category.name}: {agent_count} agents") + + except Exception as e: + self.stdout.write(f"āš ļø Could not generate database summary: {str(e)}") + + # Environment-specific notes + deployment_env = os.environ.get('DEPLOYMENT_ENVIRONMENT', 'development') + self.stdout.write(f"\nšŸŒ Environment: {deployment_env}") + + if deployment_env == 'production': + self.stdout.write("šŸ’” Production notes:") + self.stdout.write(" - Webhook URLs should point to production N8N instance") + self.stdout.write(" - Verify agent pricing and configurations") + self.stdout.write(" - Test agent execution after deployment") + else: + self.stdout.write("šŸ’” Development notes:") + self.stdout.write(" - Webhook URLs point to localhost:5678") + self.stdout.write(" - Use ngrok for testing webhooks externally") \ No newline at end of file