Modular workflows with include() and YAMLWorkflowParser

Compose reusable sub-workflows with include()

Don't copy-paste the same 4-step compliance check into five different workflows. Build one reusable AgentFlow and embed it cleanly inside parent flows using include(sub_flow).

Example

from praisonai import Agent, AgentFlow

drafter = Agent(name='Drafter', instructions='Write a one-sentence upgrade summary without mentioning email addresses.', output='silent')
pii_scrub = Agent(name='PIIScrubber', instructions='Return the text unchanged if no email appears, otherwise replace any email with [REDACTED].', output='silent')
compliance_steps = [pii_scrub]
main_flow = AgentFlow(steps=[drafter, *compliance_steps])
print('Composed:', main_flow.start('Upgrade jane@example.com to Pro plan')['output'])

Try it Yourself

Example explained

  • include(compliance_subflow) — Embeds a tested sub-workflow directly as a reusable step inside any parent AgentFlow.

Load declarative workflows with YAMLWorkflowParser

Teams that prefer version-controlled YAML definitions can parse and run workflow graphs with YAMLWorkflowParser directly from praisonai.

Example

from praisonai import YAMLWorkflowParser

yaml_def = '''
name: SupportFlow
steps:
  - name: triage
    action: Classify the ticket in one word.
'''
flow = YAMLWorkflowParser().parse_string(yaml_def)
print('Parsed YAML workflow:', flow.name, '| steps:', len(flow.steps))

Try it Yourself

Example explained

  • YAMLWorkflowParser().parse_string(…) — Parses a declarative YAML workflow definition directly into an executable AgentFlow.

Common pitfall: circular include() references

Keep sub-workflows acyclic (DAGs). Never include Workflow A inside Workflow B while B is included inside A — AgentFlow enforces MAX_NESTING_DEPTH to guard against infinite recursion.

Reference: documentation