Setup
Copy
# Create environment
python3 -m venv venv && source venv/bin/activate
# Install packages
pip install praisonaiagents praisonai
# Set API key
export OPENAI_API_KEY="your-key"
Create Sample Data
Copy
# Create student profiles
cat > students.json << 'EOF'
[
{"id": "STU001", "name": "Alice", "level": "beginner", "topics_completed": ["intro"], "score_avg": 65},
{"id": "STU002", "name": "Bob", "level": "intermediate", "topics_completed": ["intro", "basics", "functions"], "score_avg": 82},
{"id": "STU003", "name": "Carol", "level": "advanced", "topics_completed": ["intro", "basics", "functions", "oop", "async"], "score_avg": 91}
]
EOF
# Create curriculum
cat > curriculum.json << 'EOF'
{
"beginner": ["variables", "data_types", "control_flow"],
"intermediate": ["functions", "oop", "error_handling"],
"advanced": ["async", "decorators", "metaclasses"]
}
EOF
Run: Python Code
Copy
from praisonaiagents import Agent, Agents, Task, tool
from pydantic import BaseModel
from typing import List
import json
# Structured output
class LearningPlan(BaseModel):
student_id: str
current_level: str
recommended_topics: List[str]
difficulty_adjustment: str # increase, maintain, decrease
next_assessment_date: str
# Database persistence is configured via memory={} parameter
# Tools
@tool
def get_student_profile(student_id: str) -> str:
"""Get student profile and progress."""
with open("students.json") as f:
students = json.load(f)
for s in students:
if s["id"] == student_id:
return json.dumps(s)
return json.dumps({"error": "Student not found"})
@tool
def get_curriculum(level: str) -> str:
"""Get curriculum topics for a level."""
with open("curriculum.json") as f:
curriculum = json.load(f)
return json.dumps({"level": level, "topics": curriculum.get(level, [])})
@tool
def generate_quiz(topic: str, difficulty: str) -> str:
"""Generate a quiz for a topic."""
quizzes = {
"variables": {"q": "What is a variable?", "options": ["A", "B", "C"], "answer": "A"},
"functions": {"q": "What is a function?", "options": ["A", "B", "C"], "answer": "B"},
"oop": {"q": "What is OOP?", "options": ["A", "B", "C"], "answer": "C"}
}
quiz = quizzes.get(topic, {"q": f"Quiz on {topic}", "options": ["A", "B"], "answer": "A"})
quiz["difficulty"] = difficulty
return json.dumps(quiz)
# Agents
assessor = Agent(
name="SkillAssessor",
instructions="Assess student's current level and progress. Use get_student_profile tool.",
tools=[get_student_profile],
memory={
"db": "sqlite:///learning.db",
"session_id": "adaptive-learning"
}
)
planner = Agent(
name="ContentPlanner",
instructions="Plan learning content based on level. Use get_curriculum tool.",
tools=[get_curriculum]
)
generator = Agent(
name="ContentGenerator",
instructions="Generate quizzes and exercises. Use generate_quiz tool.",
tools=[generate_quiz]
)
# Tasks
assess_task = Task(
description="Assess student: {student_id}",
agent=assessor,
expected_output="Student profile with current level"
)
plan_task = Task(
description="Create learning plan based on assessment",
agent=planner,
expected_output="Recommended topics and difficulty"
)
generate_task = Task(
description="Generate content for recommended topics",
agent=generator,
expected_output="Learning content with quizzes",
output_pydantic=LearningPlan
)
# Run
agents = Agents(agents=[assessor, planner, generator], tasks=[assess_task, plan_task, generate_task])
result = agents.start(student_id="STU001")
print(result)
Run: CLI
Copy
# Assess single student
praisonai "Create learning plan for beginner Python student" --verbose
# With persistence
praisonai "Generate adaptive quiz for intermediate level" --memory --user-id tutor1
# Interactive tutoring
praisonai chat --memory --user-id learning_system
Run: agents.yaml
Createagents.yaml:
Copy
framework: praisonai
topic: "adaptive learning system"
roles:
assessor:
role: Skill Assessor
goal: Evaluate student knowledge level
backstory: Expert at educational assessment
tasks:
assess:
description: |
Assess student:
- Current knowledge level
- Completed topics
- Average score
- Learning gaps
expected_output: Skill assessment report
planner:
role: Curriculum Planner
goal: Create personalized learning paths
backstory: Expert at curriculum design
tasks:
plan:
description: |
Create learning plan:
- Next topics to learn
- Difficulty level
- Estimated time
- Prerequisites
expected_output: Personalized learning plan
generator:
role: Content Generator
goal: Create engaging learning content
backstory: Expert at educational content
tasks:
generate:
description: |
Generate content:
- Explanations
- Examples
- Quizzes
- Practice exercises
expected_output: Learning materials
Copy
praisonai agents.yaml --verbose
Monitor & Verify
Copy
# View learning history
praisonai --history 10 --user-id tutor1
# Check metrics
praisonai --metrics
# Export progress
praisonai --save student_progress
Serve API
Copy
from praisonaiagents import Agent, tool
import json
@tool
def quick_assessment(score: int, topics_completed: int) -> str:
"""Quick skill level assessment."""
if score >= 90 and topics_completed >= 5:
level = "advanced"
next_topics = ["decorators", "metaclasses"]
elif score >= 70 and topics_completed >= 3:
level = "intermediate"
next_topics = ["oop", "error_handling"]
else:
level = "beginner"
next_topics = ["variables", "control_flow"]
return json.dumps({"level": level, "next_topics": next_topics})
agent = Agent(
name="LearningAPI",
instructions="Assess student level and recommend topics.",
tools=[quick_assessment]
)
agent.launch(path="/assess", port=8000)
Copy
curl -X POST http://localhost:8000/assess \
-H "Content-Type: application/json" \
-d '{"message": "Assess student with score 75 and 4 topics completed"}'
Cleanup
Copy
rm -f learning.db students.json curriculum.json
deactivate
Features Demonstrated
| Feature | Implementation |
|---|---|
| Multi-agent | Assessor → Planner → Generator |
| Structured Output | Pydantic LearningPlan |
| Student Profiles | JSON-based progress tracking |
| DB Persistence | SQLite via db() |
| CLI | praisonai chat for tutoring |
| YAML Config | 3-agent learning pipeline |
| API Endpoint | agent.launch() |
| Adaptive Difficulty | Score-based level adjustment |

