Learn how to create AI agents with sequential prompt chaining for complex workflows.
A workflow where the output of one LLM call becomes the input for the next. This sequential design allows for structured reasoning and step-by-step task completion.
Set your OpenAI API key as an environment variable in your terminal:
export OPENAI_API_KEY=your_api_key_here
3
Create a file
Create a new file app.py with the basic setup:
from praisonaiagents import Agent, AgentFlow# Create agents for each step in the chainresearcher = Agent( name="Researcher", role="Research Analyst", goal="Research and gather information", instructions="Research the given topic thoroughly. Provide factual information.")analyst = Agent( name="Analyst", role="Data Analyst", goal="Analyze research findings", instructions="Analyze the research provided. Extract key insights and patterns.")writer = Agent( name="Writer", role="Content Writer", goal="Write clear content", instructions="Based on the analysis, write a clear and engaging summary.")editor = Agent( name="Editor", role="Content Editor", goal="Polish and refine content", instructions="Edit and polish the content. Ensure clarity and quality.")from praisonaiagents import AgentFlowHooksConfig# Create sequential workflow (prompt chaining)# Each agent's output becomes the next agent's inputworkflow = AgentFlow( steps=[researcher, analyst, writer, editor], hooks=WorkflowHooksConfig( on_step_complete=lambda name, r: print(f"✅ {name} completed") ))# Run the workflowresult = workflow.start("What are the benefits of renewable energy?")print(f"\nFinal Result: {result['output'][:500]}...")
4
Start Workflow
Type this in your terminal to run your workflow:
python app.py
Requirements
Python 3.10 or higher
OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.