from praisonaiagents import Agent, Task, Agents, Session
from praisonaiagents import execute_code, analyze_code
from pydantic import BaseModel
# Structured output schema
class CodeResult(BaseModel):
language: str
code: str
output: str
explanation: str
# Create session for project tracking
session = Session(session_id="code-001", user_id="user-1")
# Agent with memory and tools
agent = Agent(
name="Programmer",
instructions="Write, execute, and return structured code results.",
tools=[execute_code, analyze_code],
memory=True,
reflection=True
)
# Task with structured output
task = Task(
description="Write a Python script to calculate fibonacci numbers",
expected_output="Structured code result",
agent=agent,
output_pydantic=CodeResult
)
# Run with SQLite persistence
agents = Agents(
agents=[agent],
tasks=[task],
memory=True
)
result = agents.start()
print(result)
# Resume later
session2 = Session(session_id="code-001", user_id="user-1")
history = session2.search_memory("fibonacci")