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, Task, PraisonAIAgents# Create generator and evaluator agentsgenerator = Agent( name="Generator", role="Solution generator", goal="Generate initial solutions and incorporate feedback", instructions=( "1. Look at the context from previous tasks.\n" "2. If you see that you have already produced 2 points, then add another 2 new points " " so that the total becomes 10.\n" "3. Otherwise, just produce the first 2 points.\n" "4. Return only the final list of points, with no extra explanation." ))evaluator = Agent( name="Evaluator", role="Solution evaluator", goal="Evaluate solutions and provide improvement feedback", instructions=( "1. Count how many lines in the response start with a number and a period (like '1. ' or '2. ').\n" "2. If there are 10 or more, respond with 'done'.\n" "3. Otherwise, respond with 'more'.\n" "4. Return only the single word: 'done' or 'more'." ))# Create tasks for the feedback loopgenerate_task = Task( name="generate", description="Write 2 points about AI incuding if anything exiting from previous points", expected_output="2 points", agent=generator, is_start=True, task_type="decision", next_tasks=["evaluate"])evaluate_task = Task( name="evaluate", description="Check if there are 10 points about AI", expected_output="more or done", agent=evaluator, next_tasks=["generate"], context=[generate_task], task_type="decision", condition={ "more": ["generate"], # Continue to generate "done": [""] # Exit when optimization complete })# Create workflow managerworkflow = PraisonAIAgents( agents=[generator, evaluator], tasks=[generate_task, evaluate_task], process="workflow", verbose=True)# Run optimization workflowresults = workflow.start()# Print resultsprint("\nEvaluator-Optimizer Results:")for task_id, result in results["task_results"].items(): if result: print(f"Task {task_id}: {result.raw}")
4
Start Agents
Type this in your terminal to run your agents:
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.