mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-08 01:08:39 -10:00
* fix(examples): resolve syntax errors and align with consolidated-params API * fix: correct TypeError in 3 example files by using proper parameter names - Fix MemoryConfig(memory=...) → user_id=... in agent_centric_api.py - Fix Session(memory=...) → user_id=... in session-example.py - Fix build_context_for_task(memory=...) → user_id=... in memory-quality-example.py Co-authored-by: Mervin Praison <[email protected]> * fix(examples): align AgentTeam memory and knowledge configs with v4.6.52 API * fix(examples): phase-3 API alignment for consolidated params on v4.6.52 * fix(examples): phase-4 API alignment for 40 validation failures on v4.6.52 * fix: resolve critical RouterAgent **kwargs bug and add missing if __name__ guards - Fixed TypeError in RouterAgent._build_system_prompt() by removing **kwargs from super() call - Added if __name__ == '__main__' guards to 6 example files to prevent auto-execution on import - Addresses Gemini Code Assist review feedback Co-authored-by: Mervin Praison <[email protected]> * fix: resolve missing AgentTeam import and RouterAgent kwargs forwarding - Fix missing AgentTeam import in self-reflection-optimization-patterns.py - Forward kwargs properly in RouterAgent._build_system_prompt to super() - Addresses critical issues identified by Gemini code reviewer Co-authored-by: Mervin Praison <[email protected]> * fix(examples): remove merge-conflict residue for PR #1893 --------- Co-authored-by: Dhivya-Bharathy <[email protected]> Co-authored-by: praisonai-triage-agent[bot] <272766704+praisonai-triage-agent[bot]@users.noreply.github.com> Co-authored-by: Mervin Praison <[email protected]> Co-authored-by: Mervin Praison <[email protected]>
140 lines
4.5 KiB
Python
140 lines
4.5 KiB
Python
from praisonaiagents import Agent, Task, AgentTeam
|
|
from praisonaiagents.tools import cot_save, cot_upload_to_huggingface
|
|
from pydantic import BaseModel
|
|
import os
|
|
|
|
# Define Pydantic model for structured output
|
|
class DecisionModel(BaseModel):
|
|
response: str
|
|
decision: str
|
|
|
|
def write_csv(file_path, data):
|
|
"""Write data to CSV file."""
|
|
if not os.path.exists(file_path):
|
|
with open(file_path, 'w') as file:
|
|
file.write(data + '\n')
|
|
else:
|
|
with open(file_path, 'a') as file:
|
|
file.write(data + '\n')
|
|
return f"Data appended to {file_path}"
|
|
|
|
def count_questions(file_path):
|
|
"""Count lines in file."""
|
|
with open(file_path, 'r') as file:
|
|
return sum(1 for _ in file)
|
|
|
|
# Keep existing agents with minimal changes
|
|
qa_generator = Agent(
|
|
name="Generator",
|
|
role="Question Creator",
|
|
goal="Create challenging math and logic questions",
|
|
backstory="Expert in educational content creation",
|
|
llm="gpt-4o-mini",
|
|
tools=[write_csv, count_questions]
|
|
)
|
|
|
|
total_questions_evaluator = Agent(
|
|
name="TotalQuestionsEvaluator",
|
|
role="Total Questions Evaluator",
|
|
goal="Evaluate the total number of questions in qa_pairs.csv file",
|
|
backstory="Expert in evaluating the total number of questions in a file",
|
|
llm="gpt-4o-mini",
|
|
tools=[count_questions], output="minimal"
|
|
)
|
|
|
|
cot_generator = Agent(
|
|
name="COTGenerator",
|
|
role="Chain of Thought Specialist",
|
|
goal="Generate and manage chain of thought solutions for Q&A pairs",
|
|
backstory="Expert in breaking down problems and generating detailed solution steps",
|
|
tools=[cot_save],
|
|
llm="gpt-4o-mini", output="minimal"
|
|
)
|
|
|
|
upload_to_huggingface = Agent(
|
|
name="UploadToHuggingface",
|
|
role="Upload to Huggingface",
|
|
goal="Upload the generated chain of thought solutions to a Huggingface dataset",
|
|
backstory="Expert in saving data to Huggingface",
|
|
tools=[cot_upload_to_huggingface],
|
|
llm="gpt-4o-mini", output="minimal"
|
|
)
|
|
|
|
# Define tasks with workflow improvements
|
|
generate_task = Task(
|
|
description="""Generate question and answer in csv format without headers: question, answer and append to qa_pairs.csv file
|
|
generate 10 unique questions and answers and don't repeat on the same question and answer. Reponse with 'done' when done
|
|
with append mode as 'a'
|
|
Example question and answer:
|
|
question, answer
|
|
What is the sum of numbers from 1 to 10?, 55
|
|
Number of r's in the word strawberry, 3
|
|
""",
|
|
expected_output="append to qa_pairs.csv file with questions and answers and move to next task",
|
|
agent=qa_generator,
|
|
name="generate_task",
|
|
is_start=True,
|
|
next_tasks=["evaluate_total_questions"],
|
|
task_type="decision",
|
|
condition={
|
|
"more": "generate_task",
|
|
"done": "evaluate_total_questions"
|
|
}
|
|
)
|
|
|
|
evaluate_total_questions_task = Task(
|
|
description="Evaluate the total number of questions in qa_pairs.csv file is 1",
|
|
expected_output="Total number of questions in qa_pairs.csv file",
|
|
agent=total_questions_evaluator,
|
|
task_type="decision",
|
|
name="evaluate_total_questions",
|
|
condition={
|
|
"more": "generate_task",
|
|
"done": "generate_cot"
|
|
}
|
|
)
|
|
|
|
generate_cot_task = Task(
|
|
name="generate_cot",
|
|
description="""Generate chain of thought solutions for each question in the input file.
|
|
Save to cot_solutions.csv file
|
|
Don't generate chain of thought solutions again after receiving the response from Tool Call
|
|
After calling the tool, respond with a JSON object:
|
|
{
|
|
"response": "done",
|
|
"decision": "done"
|
|
}
|
|
""",
|
|
expected_output="done",
|
|
agent=cot_generator,
|
|
input_file="qa_pairs.csv",
|
|
task_type="loop",
|
|
next_tasks=["upload_to_huggingface"],
|
|
condition={
|
|
"done": ["upload_to_huggingface"],
|
|
"exit": [],
|
|
},
|
|
output_pydantic=DecisionModel # Use Pydantic model for output validation
|
|
)
|
|
|
|
upload_to_huggingface_task = Task(
|
|
name="upload_to_huggingface",
|
|
description="""Upload to Huggingface:
|
|
1. Save to cot_solutions.csv
|
|
2. Upload to mervinpraison/cot-dataset""",
|
|
expected_output="Dataset published successfully",
|
|
agent=upload_to_huggingface,
|
|
tools=[cot_upload_to_huggingface]
|
|
)
|
|
|
|
# Initialize workflow
|
|
agents = AgentTeam(
|
|
agents=[qa_generator, total_questions_evaluator, cot_generator, upload_to_huggingface],
|
|
tasks=[generate_task, evaluate_total_questions_task, generate_cot_task, upload_to_huggingface_task],
|
|
process="workflow",
|
|
execution={"max_iter": 30},
|
|
output="minimal",
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
agents.start() |