Orchestrate agents in sequential, parallel, routed, and looped pipelines with a single AgentFlow call
from praisonaiagents import Agent, AgentFlowresearcher = Agent(name="Researcher", instructions="Research the given topic thoroughly.")writer = Agent(name="Writer", instructions="Write a concise summary of the research.")workflow = AgentFlow(steps=[researcher, writer])result = workflow.start("Latest breakthroughs in AI agents")print(result["output"])
AgentFlow runs agents as sequential steps, passing each output into the next as context.
from praisonaiagents import Agent, AgentFlowanalyst = Agent(name="Analyst", instructions="Analyze the topic and extract key insights.")strategist = Agent(name="Strategist", instructions="Develop actionable strategies from the analysis.")presenter = Agent(name="Presenter", instructions="Summarize strategies into a clear presentation.")workflow = AgentFlow(steps=[analyst, strategist, presenter])result = workflow.start("Market trends in AI industry 2024")print(result["output"])
2
Parallel research
from praisonaiagents import Agent, AgentFlow, parallelmarket = Agent(name="Market", instructions="Research market trends.")competitor = Agent(name="Competitor", instructions="Research competitor landscape.")customer = Agent(name="Customer", instructions="Research customer needs.")aggregator = Agent(name="Aggregator", instructions="Synthesize all research into a unified report.")workflow = AgentFlow(steps=[ parallel([market, competitor, customer], max_workers=3), aggregator,])result = workflow.start("AI industry 2024")print(result["output"])
3
Conditional routing
from praisonaiagents import Agent, AgentFlow, WorkflowContext, StepResult, routetech = Agent(name="TechExpert", instructions="Answer technical questions in depth.")creative = Agent(name="Creative", instructions="Write engaging creative content.")general = Agent(name="General", instructions="Provide a helpful general-purpose answer.")def classify(ctx: WorkflowContext) -> StepResult: text = ctx.input.lower() if any(k in text for k in ("code", "python", "api", "debug")): return StepResult(output="technical") if any(k in text for k in ("story", "poem", "creative")): return StepResult(output="creative") return StepResult(output="default")workflow = AgentFlow(steps=[ classify, route({"technical": [tech], "creative": [creative], "default": [general]}),])result = workflow.start("Write a Python function to sort a list")print(result["output"])
from praisonaiagents import Agent, AgentFlowresearcher = Agent(name="Researcher", instructions="Research the topic.")writer = Agent(name="Writer", instructions="Write a summary.")workflow = AgentFlow( steps=[researcher, writer], planning=True, # or a dict: {"llm": "gpt-4o", "reasoning": True})result = workflow.start("Research and write about AI trends")
Pass planning=True to enable it, or a dict to tune the planner:
Prefer the bool or dict form above. Use WorkflowPlanningConfig when you want typed, IDE-friendly configuration.
from praisonaiagents import Agent, AgentFlow, WorkflowPlanningConfigresearcher = Agent(name="Researcher", instructions="Research the topic.")writer = Agent(name="Writer", instructions="Write a summary.")workflow = AgentFlow( steps=[researcher, writer], planning=WorkflowPlanningConfig(enabled=True, llm="gpt-4o", reasoning=True),)result = workflow.start("Research and write about AI trends")
Markdown files with YAML frontmatter define multi-step workflows for WorkflowManager:
---name: Research Pipelinedefault_llm: gpt-4o-miniplanning: truevariables: topic: AI trends---## Step 1: ResearchResearch the topic thoroughly.```agentrole: Researchergoal: Find comprehensive informationinstructions: Expert researcher with broad domain knowledge``````actionSearch for information about {{topic}}```output_variable: research_data## Step 2: Analyze```agentrole: Analystgoal: Analyze data patterns``````actionAnalyze: {{research_data}}```
if_() is deprecated. Use when() instead for conditional steps. if_() will be removed in a future release.