from praisonaiagents import Agent, Task, Agents, Session
from praisonaiagents import duckduckgo
from pydantic import BaseModel
# Structured output schema
class SearchResult(BaseModel):
query: str
summary: str
sources: list[str]
key_findings: list[str]
# Create session for resumability
session = Session(session_id="search-session-001", user_id="user-1")
# Agent with memory and tools
agent = Agent(
name="WebSearcher",
instructions="Search the web and return structured results.",
tools=[duckduckgo],
memory=True
)
# Task with structured output
task = Task(
description="Search for the latest AI developments in 2024",
expected_output="Structured search results",
agent=agent,
output_pydantic=SearchResult
)
# Run with SQLite persistence
agents = Agents(
agents=[agent],
tasks=[task],
memory=True
)
result = agents.start()
print(result)
# Resume later
session2 = Session(session_id="search-session-001", user_id="user-1")
history = session2.search_memory("AI developments")