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
Requirements
Python 3.10 or higher
OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.
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)