Skip to content

Commit

Permalink
Refactor multimodal agent execution and enhance documentation structure
Browse files Browse the repository at this point in the history
- Simplified the execution of the multimodal agent by removing unnecessary result printing, allowing for a cleaner start method call.
- Updated `mint.json` to include new tabs for "Documentation" and "Use Cases," improving navigation and accessibility of relevant information.
- Added a new "Usecases" group in the navigation section of `mint.json`, detailing various use cases for better user guidance.

This commit streamlines the multimodal agent's functionality and enhances the documentation for improved user experience.
  • Loading branch information
MervinPraison committed Jan 14, 2025
1 parent 2a14508 commit 1f532e0
Show file tree
Hide file tree
Showing 26 changed files with 4,233 additions and 6 deletions.
108 changes: 108 additions & 0 deletions agents/code_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from praisonaiagents import Agent, Task, PraisonAIAgents
import time
from typing import List, Dict

def analyze_code_changes():
"""Simulates code analysis"""
issues = [
{"type": "style", "severity": "low", "file": "main.py"},
{"type": "security", "severity": "high", "file": "auth.py"},
{"type": "performance", "severity": "medium", "file": "data.py"}
]
return issues[int(time.time()) % 3]

def suggest_fixes(issue: Dict):
"""Simulates fix suggestions"""
fixes = {
"style": "Apply PEP 8 formatting",
"security": "Implement input validation",
"performance": "Use list comprehension"
}
return fixes.get(issue["type"], "Review manually")

def apply_automated_fix(fix: str):
"""Simulates applying automated fixes"""
success = int(time.time()) % 2 == 0
return "fixed" if success else "manual_review"

# Create specialized agents
analyzer = Agent(
name="Code Analyzer",
role="Code analysis",
goal="Analyze code changes and identify issues",
instructions="Review code changes and report issues",
tools=[analyze_code_changes]
)

fix_suggester = Agent(
name="Fix Suggester",
role="Solution provider",
goal="Suggest fixes for identified issues",
instructions="Provide appropriate fix suggestions",
tools=[suggest_fixes]
)

fix_applier = Agent(
name="Fix Applier",
role="Fix implementation",
goal="Apply suggested fixes automatically when possible",
instructions="Implement suggested fixes and report results",
tools=[apply_automated_fix]
)

# Create workflow tasks
analysis_task = Task(
name="analyze_code",
description="Analyze code changes for issues",
expected_output="Identified code issues",
agent=analyzer,
is_start=True,
next_tasks=["suggest_fixes"]
)

suggestion_task = Task(
name="suggest_fixes",
description="Suggest fixes for identified issues",
expected_output="Fix suggestions",
agent=fix_suggester,
next_tasks=["apply_fixes"]
)

fix_task = Task(
name="apply_fixes",
description="Apply suggested fixes",
expected_output="Fix application status",
agent=fix_applier,
task_type="decision",
condition={
"fixed": "",
"manual_review": ["suggest_fixes"] # Loop back for manual review
}
)

# Create workflow
workflow = PraisonAIAgents(
agents=[analyzer, fix_suggester, fix_applier],
tasks=[analysis_task, suggestion_task, fix_task],
process="workflow",
verbose=True
)

def main():
print("\nStarting Code Review Workflow...")
print("=" * 50)

# Run workflow
results = workflow.start()

# Print results
print("\nCode Review Results:")
print("=" * 50)
for task_id, result in results["task_results"].items():
if result:
print(f"\nTask: {task_id}")
print(f"Result: {result.raw}")
print("-" * 50)

if __name__ == "__main__":
main()
Empty file added agents/llamaindex_example.py
Empty file.
7 changes: 1 addition & 6 deletions agents/multimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,4 @@
)

# Run all tasks
result = agents.start()

# Print results
for task_id, task_result in result["task_results"].items():
print(f"\nTask {task_id} Result:")
print(task_result.raw)
agents.start()
41 changes: 41 additions & 0 deletions agents/pdf_agents_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from praisonaiagents import Agent, Task, PraisonAIAgents

# Create PDF Analysis Agent
pdf_agent = Agent(
name="PDFAnalyst",
role="PDF Document Specialist",
goal="Analyze PDF documents to extract meaningful information",
backstory="""You are an expert in PDF document analysis and text extraction.
You excel at understanding document structure, extracting content, and analyzing textual information.""",
llm="gpt-4o-mini",
self_reflect=False
)

# 1. Task with PDF URL
task1 = Task(
name="analyze_pdf_url",
description="Extract and analyze content from this PDF document.",
expected_output="Detailed analysis of the PDF content and structure",
agent=pdf_agent,
input=["https://example.com/document.pdf"]
)

# 2. Task with Local PDF File
task2 = Task(
name="analyze_local_pdf",
description="What information can you extract from this PDF? Analyze its content.",
expected_output="Detailed analysis of the PDF content and structure",
agent=pdf_agent,
input=["document.pdf"]
)

# Create PraisonAIAgents instance
agents = PraisonAIAgents(
agents=[pdf_agent],
tasks=[task1, task2],
process="sequential",
verbose=1
)

# Run all tasks
agents.start()
132 changes: 132 additions & 0 deletions cookbooks/usecases/adaptive-learning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
from praisonaiagents import Agent, Task, PraisonAIAgents
import time
from typing import Dict

def assess_student_level():
"""Simulates student assessment"""
levels = ["beginner", "intermediate", "advanced"]
current_time = int(time.time())
return levels[current_time % 3]

def generate_content(level: str):
"""Simulates content generation"""
content_types = {
"beginner": "basic concepts and examples",
"intermediate": "practice problems and applications",
"advanced": "complex scenarios and projects"
}
return content_types.get(level, "basic concepts")

def evaluate_performance():
"""Simulates performance evaluation"""
scores = ["low", "medium", "high"]
current_time = int(time.time())
return scores[current_time % 3]

def adapt_difficulty(performance: str):
"""Simulates difficulty adaptation"""
adaptations = {
"low": "decrease",
"medium": "maintain",
"high": "increase"
}
return adaptations.get(performance, "maintain")

# Create specialized agents
assessor = Agent(
name="Student Assessor",
role="Level Assessment",
goal="Assess student's current level",
instructions="Evaluate student's knowledge and skills",
tools=[assess_student_level]
)

generator = Agent(
name="Content Generator",
role="Content Creation",
goal="Generate appropriate learning content",
instructions="Create content based on student's level",
tools=[generate_content]
)

evaluator = Agent(
name="Performance Evaluator",
role="Performance Assessment",
goal="Evaluate student's performance",
instructions="Assess learning outcomes",
tools=[evaluate_performance]
)

adapter = Agent(
name="Difficulty Adapter",
role="Content Adaptation",
goal="Adapt content difficulty",
instructions="Adjust difficulty based on performance",
tools=[adapt_difficulty]
)

# Create workflow tasks
assessment_task = Task(
name="assess_level",
description="Assess student's current level",
expected_output="Student's proficiency level",
agent=assessor,
is_start=True,
next_tasks=["generate_content"]
)

generation_task = Task(
name="generate_content",
description="Generate appropriate content",
expected_output="Learning content",
agent=generator,
next_tasks=["evaluate_performance"]
)

evaluation_task = Task(
name="evaluate_performance",
description="Evaluate student's performance",
expected_output="Performance assessment",
agent=evaluator,
next_tasks=["adapt_difficulty"]
)

adaptation_task = Task(
name="adapt_difficulty",
description="Adapt content difficulty",
expected_output="Difficulty adjustment",
agent=adapter,
task_type="decision",
condition={
"decrease": ["generate_content"],
"maintain": "",
"increase": ["generate_content"]
}
)

# Create workflow
workflow = PraisonAIAgents(
agents=[assessor, generator, evaluator, adapter],
tasks=[assessment_task, generation_task, evaluation_task, adaptation_task],
process="workflow",
verbose=True
)

def main():
print("\nStarting Adaptive Learning Workflow...")
print("=" * 50)

# Run workflow
results = workflow.start()

# Print results
print("\nAdaptive Learning Results:")
print("=" * 50)
for task_id, result in results["task_results"].items():
if result:
print(f"\nTask: {task_id}")
print(f"Result: {result.raw}")
print("-" * 50)

if __name__ == "__main__":
main()
Loading

0 comments on commit 1f532e0

Please sign in to comment.