1

Install PraisonAI

Install the core package:

Terminal
pip install praisonaiagents
2

Configure Environment

Terminal
export OPENAI_API_KEY=your_openai_key

Generate your OpenAI API key from OpenAI You can also use other LLM providers like Anthropic, Google, etc. Please refer to the Models for more information.

3

Create Agent

Create app.py:

Code Example

4

Run the Program

Execute your script:

Terminal
python app.py

You should see:

  • Agent initialization
  • Agents progress
  • Final results
  • Generated report

Advanced Usage

Creating Custom Tool

from praisonaiagents import Agent, Task, PraisonAIAgents
from duckduckgo_search import DDGS
from typing import List, Dict

# 1. Tool
def internet_search_tool(query: str) -> List[Dict]:
    """
    Perform Internet Search
    """
    results = []
    ddgs = DDGS()
    for result in ddgs.text(keywords=query, max_results=5):
        results.append({
            "title": result.get("title", ""),
            "url": result.get("href", ""),
            "snippet": result.get("body", "")
        })
    return results

# 2. Agent
data_agent = Agent(
    name="DataCollector",
    role="Search Specialist",
    goal="Perform internet searches to collect relevant information.",
    backstory="Expert in finding and organising internet data.",
    tools=[internet_search_tool],
    self_reflect=False
)

# 3. Tasks
collect_task = Task(
    description="Perform an internet search using the query: 'AI job trends in 2024'. Return results as a list of title, URL, and snippet.",
    expected_output="List of search results with titles, URLs, and snippets.",
    agent=data_agent,
    name="collect_data",
)

# 4. Start Agents
agents = PraisonAIAgents(
    agents=[data_agent],
    tasks=[collect_task],
    process="sequential"
)

agents.start()

Next Steps

Was this page helpful?