This directory contains Hygen templates for rapidly scaffolding new components in the SwarmAgent ecosystem. Each template is designed to generate production-ready code with full integration into the existing architecture.
Generate new SwarmAgent implementations with FSM integration and OpenTelemetry support.
# Generate a new monitoring agent
hygen swarm-agent new
# Example prompts:
# Name: Monitoring
# States: IDLE,WATCHING,ALERTING,REPORTING
# Triggers: start,detect,alert,reportGenerated files:
src/dslmodel/agents/examples/monitoring_agent.py- Agent implementationsrc/dslmodel/agents/tests/test_monitoring_agent.py- Test suite
Create complete workflow orchestrations with multiple agents.
# Generate a deployment workflow
hygen swarm-workflow new
# Example prompts:
# Name: deployment
# Agents: validator,deployer,monitor
# Steps: 5
# Include rollback: yesGenerated files:
src/dslmodel/workflows/deployment_workflow.py- Workflow implementation
Add custom telemetry with exporters and processors.
# Generate metrics telemetry
hygen otel-integration new
# Example prompts:
# Name: Metrics
# Signal type: metrics
# Custom exporter: yesGenerated files:
src/dslmodel/otel/metrics_telemetry.py- OTEL integration
Create new CLI commands with Rich formatting.
# Generate analyze command
hygen cli-command new
# Example prompts:
# Name: analyze
# Parent command: swarm
# Has subcommands: noGenerated files:
src/dslmodel/commands/swarm_analyze_command.py- Command implementation
Build reusable FSM mixins with advanced features.
# Generate approval workflow mixin
hygen fsm-mixin new
# Example prompts:
# Name: Approval
# States: PENDING,REVIEWING,APPROVED,REJECTED
# Include timeout: yes
# Include retry: yesGenerated files:
src/dslmodel/mixins/approval_fsm_mixin.py- FSM mixin
# Install hygen globally
npm install -g hygen
# Or use npx (no installation needed)
npx hygen <template> <action># Interactive mode - prompts for all options
hygen swarm-agent new
# With predefined values
hygen swarm-agent new --name Analytics --states IDLE,PROCESSING,REPORTING# Generate multiple components for a feature
hygen swarm-agent new --name Auth
hygen swarm-workflow new --name authentication --agents auth,validator,logger
hygen cli-command new --name auth --parent-command swarm- ✅ Type hints and Pydantic models
- ✅ Comprehensive docstrings
- ✅ Error handling patterns
- ✅ Logging integration
- ✅ Example usage in
__main__ - ✅ Test scaffolding (where applicable)
- State machine with transitions
- OpenTelemetry span processing
- Trigger mapping and decorators
- NextCommand generation
- Status reporting
- Multi-step orchestration
- Span emission for coordination
- Progress tracking with Rich
- Dry-run support
- Optional rollback capability
- Custom exporters and processors
- Semantic conventions
- Context managers for spans
- Metrics and event tracking
- JSONL export format
- Typer command structure
- Rich formatted output
- Multiple output formats (table, json, yaml)
- Async command support
- Subcommand groups
- State transition callbacks
- Timeout handling
- Retry logic with backoff
- State persistence
- History tracking
Templates are EJS files located in _templates/<template-name>/new/:
- index.js - Defines prompts and data processing
- *.ejs.t - Template files with EJS syntax
# Create new template structure
hygen generator new --name my-feature
# Edit the generated files in _templates/my-feature/new/All templates have access to:
- User inputs from prompts
- Derived values (className, fileName, etc.)
- Helper functions (JSON.stringify, etc.)
# 1. Create the agent
hygen swarm-agent new \
--name Scheduler \
--states IDLE,SCHEDULING,EXECUTING,COMPLETE \
--triggers schedule,execute,complete
# 2. Create the workflow
hygen swarm-workflow new \
--name scheduling \
--agents scheduler,executor,monitor \
--steps 4
# 3. Add CLI command
hygen cli-command new \
--name schedule \
--parent-command swarm \
--arguments task-name,cron-expression
# 4. Add telemetry
hygen otel-integration new \
--name Scheduling \
--signal-type traces \
--has-exporter yes# Run the generated agent
python src/dslmodel/agents/examples/scheduler_agent.py
# Run tests
pytest src/dslmodel/agents/tests/test_scheduler_agent.py
# Test the workflow
python src/dslmodel/workflows/scheduling_workflow.py --dry-run
# Test CLI command
python -m dslmodel.cli swarm schedule "backup" "0 2 * * *"-
Naming Conventions
- Use PascalCase for agent/mixin names
- Use lowercase for command names
- Use descriptive state names (ACTIVE not A)
-
State Design
- Always include ERROR state
- Keep states focused and minimal
- Use clear transition triggers
-
Integration
- Test generated code immediately
- Update imports in
__init__.pyfiles - Add to CLI command registry if needed
-
Documentation
- Update component lists after generation
- Add usage examples to generated code
- Document any custom modifications
-
Import Errors
- Ensure generated files are in correct directories
- Update
__init__.pyfiles to export new components - Check for circular imports
-
Template Errors
- Validate EJS syntax in template files
- Check for undefined variables in templates
- Review index.js for data processing issues
-
Integration Issues
- Verify parent commands exist for CLI
- Ensure state names are valid Python identifiers
- Check file permissions for generated files
- Review generated code for TODO comments
- Check template source files for examples
- Run generated example code in
__main__
These templates are designed to evolve with the project:
- Add new prompts as patterns emerge
- Extract common code into shared templates
- Update templates when base classes change
- Add validation for common mistakes
Remember: Templates are starting points. Always review and customize generated code for your specific needs!