Passa al contenuto

Workflow Stages

Define custom workflow stages with execution modes, approval gates, and automated transitions.

Overview

Workflow stages are defined in ai.project.stage and control how projects progress through the content creation process. Each stage specifies what actions occur and how to proceed to the next stage.

Execution Modes

The execution_mode field determines how a stage processes:

Mode Description Use Case
ai Execute AI template to generate content Content generation stages
manual Wait for human action or approval Review and approval stages
system Run Python method automatically Task creation, publishing
cli_loop Iterative CLI agent execution Complex development tasks

Approval Gates

Stages can require human approval before proceeding:

Python
# Stage with approval requirement
stage = env['ai.project.stage'].create({
    'name': 'Design Review',
    'template_id': template.id,
    'sequence': 40,
    'execution_mode': 'manual',
    'requires_approval': True,
    'approval_type': 'design',  # 'design', 'content', 'final'
    'allow_feedback': True,     # Enable feedback for regeneration
})

When a project reaches an approval stage:

  1. Project state changes to approval_pending
  2. User is notified via activity or email
  3. User can approve, request changes, or reject
  4. If approved, project continues to next stage
  5. If changes requested, stage re-executes with feedback

Stage Transitions

Control how stages transition with these settings:

Python
stage.write({
    # Automatic transition on completion
    'auto_advance': True,

    # Conditions for transition (Python expression)
    'transition_condition': "project.task_ids.filtered(lambda t: t.ai_state == 'done')",

    # Delay before transition (for rate limiting)
    'transition_delay': 5,  # seconds

    # Next stage (if not using sequence)
    'next_stage_id': next_stage.id,
})

Creating Custom Stages

Complete example of defining a custom workflow with stages:

Python
# Create template
template = env['ai.project.template'].create({
    'name': 'Custom Workflow',
    'code': 'custom_workflow',
    'description': 'My custom content workflow',
})

# Stage 1: Discovery (manual input)
env['ai.project.stage'].create({
    'name': 'Discovery',
    'template_id': template.id,
    'sequence': 10,
    'execution_mode': 'manual',
    'auto_advance': True,
})

# Stage 2: AI Generation
env['ai.project.stage'].create({
    'name': 'Generate Content',
    'template_id': template.id,
    'sequence': 20,
    'execution_mode': 'ai',
    'ai_template_id': content_template.id,
    'auto_advance': True,
})

# Stage 3: Review (approval gate)
env['ai.project.stage'].create({
    'name': 'Content Review',
    'template_id': template.id,
    'sequence': 30,
    'execution_mode': 'manual',
    'requires_approval': True,
    'allow_feedback': True,
})

# Stage 4: Complete
env['ai.project.stage'].create({
    'name': 'Complete',
    'template_id': template.id,
    'sequence': 100,
    'is_final': True,
})