duckduckgo_search is a tool that allows agents to search the web.
It is required for the multiple agents example shown below.
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 app.py with the basic setup:
Copy
from praisonaiagents.agents.agents import Agent, Task, PraisonAIAgents# Create blog writer agentblog_agent = Agent( role="Blog Writer", goal="Write a blog post about AI", backstory="Expert at writing blog posts", llm="gpt-4o-mini")# Create blog writing taskblog_task = Task( description="Write a blog post about AI trends", expected_output="Well-written blog post about AI trends", agent=blog_agent)# Create and start the agents with memory enabledagents = PraisonAIAgents( agents=[blog_agent], tasks=[blog_task], memory=True) # Start executionresult = agents.start()print(result)
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: sequentialmemory: trueroles: researcher: backstory: Expert at analyzing and storing information in memory. goal: Research and document key information about topics role: Research Analyst llm: gpt-4o-mini tools: - duckduckgo tasks: research_task: description: Research and document key information about topics. expected_output: Detailed research findings. writer: backstory: Expert at writing blog posts. goal: Write a blog post about the research role: Blog Writer llm: gpt-4o-mini tasks: blog_task: description: Write a blog post about the research. expected_output: Well-written blog post based on research.
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.
from praisonaiagents import Agent, Task, PraisonAIAgentsfrom praisonaiagents.tools import duckduckgo# Create first agent for researchresearcher = Agent( role="Research Analyst", goal="Research and analyze market trends", backstory="Expert in market research and data analysis", tools=[duckduckgo], verbose=True)# Create second agent for report writingwriter = Agent( role="Report Writer", goal="Create comprehensive market reports", backstory="Expert in technical writing and report creation", verbose=True)# Create research taskresearch_task = Task( description="Research current market trends", expected_output="Detailed market analysis", agent=researcher)# Create writing taskreport_task = Task( description="Create a market report based on research", expected_output="Comprehensive market report", agent=writer)# Create and start the agents with memoryagents = PraisonAIAgents( agents=[researcher, writer], tasks=[research_task, report_task], memory=True, process="sequential")# Start executionresult = agents.start()
Copy
framework: praisonaiprocess: sequentialmemory: trueroles: researcher: backstory: Expert in market research and data analysis. goal: Research and analyze market trends role: Research Analyst tools: - duckduckgo tasks: research_task: description: Research current market trends. expected_output: Detailed market analysis. writer: backstory: Expert in technical writing and report creation. goal: Create comprehensive market reports role: Report Writer tasks: report_task: description: Create a market report based on research. expected_output: Comprehensive market report.
PraisonAI includes built-in quality control for memory storage:
Copy
# Example of storing with quality metricsagents.memory.store_long_term( text="Important information to remember", metadata={ "task_id": "task_123", "agent": "research_agent" }, completeness=0.9, # How complete is the information relevance=0.85, # How relevant to the task clarity=0.95, # How clear and well-structured accuracy=0.9, # How accurate is the information weights={ # Custom weights for quality score "completeness": 0.3, "relevance": 0.3, "clarity": 0.2, "accuracy": 0.2 })# Search with quality filterresults = agents.memory.search_long_term( query="search query", min_quality=0.8, # Only return high-quality matches limit=5 # Maximum number of results)