Set your OpenAI API key as an environment variable in your terminal:
Copy
export OPENAI_API_KEY=your_api_key_here
3
Create a file
Create a new file app.py with the basic setup:
Copy
from praisonaiagents import Agent, Task, Agents, Toolsfrom pydantic import BaseModel# Define your data structureclass AnalysisReport(BaseModel): title: str findings: str summary: str# Create agentanalyst = Agent( role="Data Analyst", goal="Analyze data and provide structured insights", backstory="Expert in data analysis and insights generation", tools=[Tools.internet_search],)# Create task with structured outputtask = Task( description="Analyze recent AI developments", expected_output="Structured analysis report", agent=analyst, output_pydantic=AnalysisReport)# Create and start the agentsagents = Agents( agents=[analyst], tasks=[task], process="sequential", verbose=2)# Start executionresult = agents.start()print(result.pydantic.title)print(result.pydantic.findings)print(result.pydantic.summary)
4
Start Agents
Type this in your terminal to run your agents:
Copy
python app.py
1
Install Package
Install the PraisonAI package:
Copy
pip install praisonai
2
Set API Key
Set your OpenAI API key as an environment variable in your terminal:
Copy
export OPENAI_API_KEY=your_api_key_here
3
Create a file
Create a new file agents.yaml with the basic setup:
Copy
framework: praisonaiprocess: sequentialtopic: analyze AI developments with structured outputagents: # Canonical: use 'agents' instead of 'roles' analyst: instructions: # Canonical: use 'instructions' instead of 'backstory' Expert in data analysis and insights generation. goal: Analyze data and provide structured insights role: Data Analyst tools: - internet_search tasks: analysis_task: description: Analyze recent AI developments. expected_output: Structured analysis report. output_structure: type: pydantic model: title: str findings: str summary: str
4
Start Agents
Type this in your terminal to run your agents:
Copy
praisonai agents.yaml
Requirements
Python 3.10 or higher
OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.
Set your OpenAI API key as an environment variable in your terminal:
Copy
export OPENAI_API_KEY=your_api_key_here
3
Create a file
Create a new file app.py with the basic setup:
Copy
from praisonaiagents import Agent, Task, Agents, Toolsfrom pydantic import BaseModel# Define output structuresclass ResearchReport(BaseModel): topic: str findings: str sources: list[str]class Analysis(BaseModel): key_points: list[str] implications: str recommendations: str# Create first agent for researchresearcher = Agent( role="Research Analyst", goal="Gather and structure research data", backstory="Expert in research and data collection", tools=[Tools.internet_search],)# Create second agent for analysisanalyst = Agent( role="Data Analyst", goal="Analyze research and provide structured insights", backstory="Expert in data analysis and insights generation",)# Create first taskresearch_task = Task( description="Research quantum computing developments", expected_output="Structured research findings", agent=researcher, output_pydantic=ResearchReport)# Create second taskanalysis_task = Task( description="Analyze research implications", expected_output="Structured analysis report", agent=analyst, output_pydantic=Analysis)# Create and start the agentsagents = Agents( agents=[researcher, analyst], tasks=[research_task, analysis_task], process="sequential")# Start executionresult = agents.start()
4
Start Agents
Type this in your terminal to run your agents:
Copy
python app.py
1
Install Package
Install the PraisonAI package:
Copy
pip install praisonai
2
Set API Key
Set your OpenAI API key as an environment variable in your terminal:
Copy
export OPENAI_API_KEY=your_api_key_here
3
Create a file
Create a new file agents.yaml with the basic setup:
Copy
framework: praisonaiprocess: sequentialtopic: research and analyze quantum computingagents: # Canonical: use 'agents' instead of 'roles' researcher: instructions: # Canonical: use 'instructions' instead of 'backstory' Expert in research and data collection. goal: Gather and structure research data role: Research Analyst tools: - internet_search tasks: research_task: description: Research quantum computing developments. expected_output: Structured research findings. output_structure: type: pydantic model: topic: str findings: str sources: list[str] analyst: instructions: # Canonical: use 'instructions' instead of 'backstory' Expert in data analysis and insights generation. goal: Analyze research and provide structured insights role: Data Analyst tasks: analysis_task: description: Analyze research implications. expected_output: Structured analysis report. output_structure: type: pydantic model: key_points: list[str] implications: str recommendations: str
# Create an agent with structured output configurationagent = Agent( role="Data Analyst", goal="Provide structured analysis", backstory="Expert in data analysis", tools=[Tools.internet_search], # Enable detailed logging llm="gpt-4o" # Language model to use)# Task with Pydantic outputtask = Task( description="Analyze data", expected_output="Structured report", agent=agent, output_pydantic=AnalysisReport # Use Pydantic model # or output_json=AnalysisReport # Use JSON output)