Set your OpenAI API key as an environment variable in your terminal:
Copy
export OPENAI_API_KEY=your_api_key_here
3
Create a file
Create a new file app.py with the basic setup:
Copy
from praisonaiagents import Agent, AgentFlow, Taskfrom praisonaiagents import repeat# Create generator agentgenerator = Agent( name="Generator", role="Content Generator", goal="Generate high-quality content", instructions="Generate content based on the topic. Improve based on feedback if provided.")# Create evaluator agent evaluator = Agent( name="Evaluator", role="Content Evaluator", goal="Evaluate and provide feedback on content", instructions="Evaluate the content quality. If good, respond with 'APPROVED'. Otherwise provide specific feedback for improvement.")# Evaluation function to check if content is approveddef is_approved(ctx) -> bool: return "approved" in ctx.previous_result.lower()# Create workflow with evaluator-optimizer patternworkflow = AgentFlow( steps=[ generator, # First, generate content repeat( evaluator, # Evaluate and provide feedback until=is_approved, max_iterations=3 ) ])# Run optimization workflowresult = workflow.start("Write a compelling product description for an AI assistant")print(f"Final Result: {result['output'][:500]}...")
4
Start Workflow
Type this in your terminal to run your workflow:
Copy
python app.py
Requirements
Python 3.10 or higher
OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.
For optimal results, ensure your generator instructions and evaluation criteria are clear and well-defined to achieve the desired optimization outcomes.